diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java index afd33da84b7..b6d4ff64b31 100644 --- a/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java +++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupResponse.java @@ -64,7 +64,6 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie private List vmIdList; public AffinityGroupResponse() { - this.vmIdList = new ArrayList(); } @Override @@ -149,6 +148,10 @@ public class AffinityGroupResponse extends BaseResponse implements ControlledVie } public void addVMId(String vmId) { + if (this.vmIdList == null) { + this.vmIdList = new ArrayList(); + } + this.vmIdList.add(vmId); } diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 77ba9fed59e..70c0159dffe 100755 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -230,7 +230,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { for (String groupName : securityGroupNameList) { Long groupId = _responseGenerator.getSecurityGroupId(groupName, getEntityOwnerId()); if (groupId == null) { - throw new InvalidParameterValueException("Unable to find group by name " + groupName + " for account " + getEntityOwnerId()); + throw new InvalidParameterValueException("Unable to find group by name " + groupName); } else { securityGroupIds.add(groupId); } @@ -344,8 +344,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { for (String groupName : affinityGroupNameList) { Long groupId = _responseGenerator.getAffinityGroupId(groupName, getEntityOwnerId()); if (groupId == null) { - throw new InvalidParameterValueException("Unable to find group by name " + groupName - + " for account " + getEntityOwnerId()); + throw new InvalidParameterValueException("Unable to find affinity group by name " + groupName); } else { affinityGroupIds.add(groupId); } diff --git a/docs/en-US/Release_Notes.xml b/docs/en-US/Release_Notes.xml index f243a26cce2..60209f660d5 100644 --- a/docs/en-US/Release_Notes.xml +++ b/docs/en-US/Release_Notes.xml @@ -4181,17 +4181,17 @@ under the License. Restart the agent: - service cloud-agent stop - killall jsvc - service cloudstack-agent start +service cloud-agent stop +killall jsvc +service cloudstack-agent start During the upgrade, log4j-cloud.xml was simply copied over, so the logs will continue to be added to /var/log/cloud/agent/agent.log. There's nothing wrong with this, but if you prefer to be consistent, you can change this by copying over the sample configuration file: - cd /etc/cloudstack/agent - mv log4j-cloud.xml.dpkg-dist log4j-cloud.xml - service cloudstack-agent restart +cd /etc/cloudstack/agent +mv log4j-cloud.xml.dpkg-dist log4j-cloud.xml +service cloudstack-agent restart @@ -4201,22 +4201,63 @@ under the License. - The package names have changed between 4.0 and 4.1, so upgrading the packages won't happen automatically with a yum update + If you are using CentOS or RHEL, follow this procedure to upgrade your packages. If not, skip to step . + Community Packages + This section assumes you're using the community supplied packages for &PRODUCT;. If you've created your own packages and yum repository, substitute your own URL for the ones used in these examples. + + + + The first order of business will be to change the yum repository for each system with &PRODUCT; packages. This means all management servers, and any hosts that have the KVM agent. (No changes should be necessary for hosts that are running VMware or Xen.) + Start by opening /etc/yum.repos.d/cloudstack.repo on any systems that have &PRODUCT; packages installed. + This file should have content similar to the following: + +[apache-cloudstack] +name=Apache CloudStack +baseurl=http://cloudstack.apt-get.eu/rhel/4.0/ +enabled=1 +gpgcheck=0 + + If you are using the community provided package repository, change the baseurl to http://cloudstack.apt-get.eu/rhel/4.1/ + If you're using your own package repository, change this line to read as appropriate for your 4.1.0 repository. + + + Now that you have the repository configured, it's time to install the cloudstack-management package by upgrading the older cloud-client package. + $ sudo yum upgrade cloud-client + + + For KVM hosts, you will need to upgrade the cloud-agent package, similarly installing the new version as cloudstack-agent. + $ sudo yum upgrade cloud-agent + During the installation of cloudstack-agent, the RPM will copy your agent.properties, log4j-cloud.xml, and environment.properties from /etc/cloud/agent to /etc/cloudstack/agent. + + + Verify that the file /etc/cloudstack/agent/environment.properties has a line that reads: + paths.script=/usr/share/cloudstack-common + If not, add the line. + + + Restart the agent: + +service cloud-agent stop +killall jsvc +service cloudstack-agent start + + + - Once you've upgraded the packages on your management servers, you'll need to restart the system VMs. Make sure port 8096 is open to do this. + Once you've upgraded the packages on your management servers, you'll need to restart the system VMs. Make sure port 8096 is open in your local host firewall to do this. There is a script that will do this for you, all you need to do is run the script and supply the IP address for your MySQL instance and your MySQL credentials: # nohup cloudstack-sysvmadm -d IP address -u cloud -p -a > sysvm.log 2>&1 & You can monitor the log for progress. The process of restarting the system VMs can take an hour or more. # tail -f sysvm.log The output to sysvm.log will look something like this: - Stopping and starting 1 secondary storage vm(s)... - Done stopping and starting secondary storage vm(s) - Stopping and starting 1 console proxy vm(s)... - Done stopping and starting console proxy vm(s). - Stopping and starting 4 running routing vm(s)... - Done restarting router(s). +Stopping and starting 1 secondary storage vm(s)... +Done stopping and starting secondary storage vm(s) +Stopping and starting 1 console proxy vm(s)... +Done stopping and starting console proxy vm(s). +Stopping and starting 4 running routing vm(s)... +Done restarting router(s). @@ -4231,15 +4272,6 @@ under the License. Upgrade from 3.0.2 to 4.1.0 This section will guide you from Citrix CloudStack 3.0.2 to Apache CloudStack 4.1.0. Sections that are hypervisor-specific will be called out with a note. - - Ensure that you query your IP address usage records and process them or make a - backup. During the upgrade you will lose the old IP address usage records. - Starting in 3.0.2, the usage record format for IP addresses is the same as the rest - of the usage types. Instead of a single record with the assignment and release dates, - separate records are generated per aggregation period with start and end dates. After - upgrading, any existing IP address usage records in the old format will no longer be - available. - The following upgrade instructions apply only if you're using VMware hosts. If @@ -4350,23 +4382,107 @@ under the License. the community provided yum/apt repositories to gain access to the &PRODUCT; binaries. - - After you have configured an appropriate yum or apt repository, you may execute the - one of the following commands as appropriate for your environment in order to upgrade - &PRODUCT;: # yum update cloud-* - # apt-get update - # apt-get upgrade cloud-* - - You will, of course, have to agree to the changes suggested by Yum or APT. - - If the upgrade output includes a message similar to the following, then some - custom content was found in your old components.xml, and you need to merge the two - files: - warning: /etc/cloud/management/components.xml created as /etc/cloud/management/components.xml.rpmnew - Instructions follow in the next step. + + If you are using Ubuntu, follow this procedure to upgrade your packages. If not, skip to step . + Community Packages + This section assumes you're using the community supplied packages for &PRODUCT;. If you've created your own packages and APT repository, substitute your own URL for the ones used in these examples. + + + The first order of business will be to change the sources list for each system with &PRODUCT; packages. This means all management servers, and any hosts that have the KVM agent. (No changes should be necessary for hosts that are running VMware or Xen.) + Start by opening /etc/apt/sources.list.d/cloudstack.list on any systems that have &PRODUCT; packages installed. + This file should have one line, which contains: + deb http://cloudstack.apt-get.eu/ubuntu precise 4.0 + We'll change it to point to the new package repository: + deb http://cloudstack.apt-get.eu/ubuntu precise 4.1 + If you're using your own package repository, change this line to read as appropriate for your 4.1.0 repository. + + + Now update your apt package list: + $ sudo apt-get update + + + Now that you have the repository configured, it's time to install the cloudstack-management package. This will pull in any other dependencies you need. + $ sudo apt-get install cloudstack-management + + + You will need to manually install the cloudstack-agent package: + $ sudo apt-get install cloudstack-agent + During the installation of cloudstack-agent, APT will copy your agent.properties, log4j-cloud.xml, and environment.properties from /etc/cloud/agent to /etc/cloudstack/agent. + When prompted whether you wish to keep your configuration, say Yes. + + + Verify that the file /etc/cloudstack/agent/environment.properties has a line that reads: + paths.script=/usr/share/cloudstack-common + If not, add the line. + + + Restart the agent: + +service cloud-agent stop +killall jsvc +service cloudstack-agent start + + + + During the upgrade, log4j-cloud.xml was simply copied over, so the logs will continue to be added to /var/log/cloud/agent/agent.log. There's nothing wrong with this, but if you prefer to be consistent, you can change this by copying over the sample configuration file: + +cd /etc/cloudstack/agent +mv log4j-cloud.xml.dpkg-dist log4j-cloud.xml +service cloudstack-agent restart + + + + Once the agent is running, you can uninstall the old cloud-* packages from your system: + sudo dpkg --purge cloud-agent + + - + + If you are using CentOS or RHEL, follow this procedure to upgrade your packages. If not, skip to step . + Community Packages + This section assumes you're using the community supplied packages for &PRODUCT;. If you've created your own packages and yum repository, substitute your own URL for the ones used in these examples. + + + + The first order of business will be to change the yum repository for each system with &PRODUCT; packages. This means all management servers, and any hosts that have the KVM agent. (No changes should be necessary for hosts that are running VMware or Xen.) + Start by opening /etc/yum.repos.d/cloudstack.repo on any systems that have &PRODUCT; packages installed. + This file should have content similar to the following: + +[apache-cloudstack] +name=Apache CloudStack +baseurl=http://cloudstack.apt-get.eu/rhel/4.0/ +enabled=1 +gpgcheck=0 + + If you are using the community provided package repository, change the baseurl to http://cloudstack.apt-get.eu/rhel/4.1/ + If you're using your own package repository, change this line to read as appropriate for your 4.1.0 repository. + + + Now that you have the repository configured, it's time to install the cloudstack-management package by upgrading the older cloud-client package. + $ sudo yum upgrade cloud-client + + + For KVM hosts, you will need to upgrade the cloud-agent package, similarly installing the new version as cloudstack-agent. + $ sudo yum upgrade cloud-agent + During the installation of cloudstack-agent, the RPM will copy your agent.properties, log4j-cloud.xml, and environment.properties from /etc/cloud/agent to /etc/cloudstack/agent. + + + Verify that the file /etc/cloudstack/agent/environment.properties has a line that reads: + paths.script=/usr/share/cloudstack-common + If not, add the line. + + + Restart the agent: + +service cloud-agent stop +killall jsvc +service cloudstack-agent start + + + + + If you have made changes to your copy of /etc/cloud/management/components.xml the changes will be preserved in the upgrade. However, you need to do the following steps to place these @@ -4796,16 +4912,107 @@ under the License. the community provided yum/apt repositories to gain access to the &PRODUCT; binaries. - - After you have configured an appropriate yum or apt repository, you may execute the - one of the following commands as appropriate for your environment in order to upgrade - &PRODUCT;: # yum update cloud-* - # apt-get update - # apt-get upgrade cloud-* - - You will, of course, have to agree to the changes suggested by Yum or APT. + + If you are using Ubuntu, follow this procedure to upgrade your packages. If not, skip to step . + Community Packages + This section assumes you're using the community supplied packages for &PRODUCT;. If you've created your own packages and APT repository, substitute your own URL for the ones used in these examples. + + + + The first order of business will be to change the sources list for each system with &PRODUCT; packages. This means all management servers, and any hosts that have the KVM agent. (No changes should be necessary for hosts that are running VMware or Xen.) + Start by opening /etc/apt/sources.list.d/cloudstack.list on any systems that have &PRODUCT; packages installed. + This file should have one line, which contains: + deb http://cloudstack.apt-get.eu/ubuntu precise 4.0 + We'll change it to point to the new package repository: + deb http://cloudstack.apt-get.eu/ubuntu precise 4.1 + If you're using your own package repository, change this line to read as appropriate for your 4.1.0 repository. + + + Now update your apt package list: + $ sudo apt-get update + + + Now that you have the repository configured, it's time to install the cloudstack-management package. This will pull in any other dependencies you need. + $ sudo apt-get install cloudstack-management + + + You will need to manually install the cloudstack-agent package: + $ sudo apt-get install cloudstack-agent + During the installation of cloudstack-agent, APT will copy your agent.properties, log4j-cloud.xml, and environment.properties from /etc/cloud/agent to /etc/cloudstack/agent. + When prompted whether you wish to keep your configuration, say Yes. + + + Verify that the file /etc/cloudstack/agent/environment.properties has a line that reads: + paths.script=/usr/share/cloudstack-common + If not, add the line. + + + Restart the agent: + +service cloud-agent stop +killall jsvc +service cloudstack-agent start + + + + During the upgrade, log4j-cloud.xml was simply copied over, so the logs will continue to be added to /var/log/cloud/agent/agent.log. There's nothing wrong with this, but if you prefer to be consistent, you can change this by copying over the sample configuration file: + +cd /etc/cloudstack/agent +mv log4j-cloud.xml.dpkg-dist log4j-cloud.xml +service cloudstack-agent restart + + + + Once the agent is running, you can uninstall the old cloud-* packages from your system: + sudo dpkg --purge cloud-agent + + - + + If you are using CentOS or RHEL, follow this procedure to upgrade your packages. If not, skip to step . + Community Packages + This section assumes you're using the community supplied packages for &PRODUCT;. If you've created your own packages and yum repository, substitute your own URL for the ones used in these examples. + + + + The first order of business will be to change the yum repository for each system with &PRODUCT; packages. This means all management servers, and any hosts that have the KVM agent. (No changes should be necessary for hosts that are running VMware or Xen.) + Start by opening /etc/yum.repos.d/cloudstack.repo on any systems that have &PRODUCT; packages installed. + This file should have content similar to the following: + +[apache-cloudstack] +name=Apache CloudStack +baseurl=http://cloudstack.apt-get.eu/rhel/4.0/ +enabled=1 +gpgcheck=0 + + If you are using the community provided package repository, change the baseurl to http://cloudstack.apt-get.eu/rhel/4.1/ + If you're using your own package repository, change this line to read as appropriate for your 4.1.0 repository. + + + Now that you have the repository configured, it's time to install the cloudstack-management package by upgrading the older cloud-client package. + $ sudo yum upgrade cloud-client + + + For KVM hosts, you will need to upgrade the cloud-agent package, similarly installing the new version as cloudstack-agent. + $ sudo yum upgrade cloud-agent + During the installation of cloudstack-agent, the RPM will copy your agent.properties, log4j-cloud.xml, and environment.properties from /etc/cloud/agent to /etc/cloudstack/agent. + + + Verify that the file /etc/cloudstack/agent/environment.properties has a line that reads: + paths.script=/usr/share/cloudstack-common + If not, add the line. + + + Restart the agent: + +service cloud-agent stop +killall jsvc +service cloudstack-agent start + + + + + If you have made changes to your existing copy of the file components.xml in your previous-version CloudStack installation, the changes will be preserved in the upgrade. However, you need to do the following steps to place these changes in a new version of diff --git a/packaging/debian/replace.properties b/packaging/debian/replace.properties index 8c852060c02..5a0bd58ab67 100644 --- a/packaging/debian/replace.properties +++ b/packaging/debian/replace.properties @@ -57,6 +57,6 @@ SYSCONFDIR=/etc SYSTEMCLASSPATH= SYSTEMJARS= USAGECLASSPATH= -USAGELOG=/var/log/cloudstack/usage +USAGELOG=/var/log/cloudstack/usage/usage.log USAGESYSCONFDIR=/etc/cloudstack/usage PACKAGE=cloudstack diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 50d8de25702..7629e5e5e59 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -379,7 +379,7 @@ public class ApiResponseHelper implements ResponseGenerator { populateDomain(resourceLimitResponse, accountTemp.getDomainId()); } resourceLimitResponse.setResourceType(Integer.valueOf(limit.getType().getOrdinal()).toString()); - if(limit.getType() == ResourceType.primary_storage || limit.getType() == ResourceType.secondary_storage) { + if((limit.getType() == ResourceType.primary_storage || limit.getType() == ResourceType.secondary_storage) && limit.getMax() >= 0) { resourceLimitResponse.setMax((long) Math.ceil(limit.getMax()/ResourceType.bytesToGiB)); } else { resourceLimitResponse.setMax(limit.getMax()); @@ -3664,8 +3664,13 @@ public class ApiResponseHelper implements ResponseGenerator { response.setName(group.getName()); response.setType(group.getType()); response.setDescription(group.getDescription()); - // response.setDomainId(account.) + Domain domain = ApiDBUtils.findDomainById(account.getDomainId()); + if (domain != null) { + response.setDomainId(domain.getUuid()); + response.setDomainName(domain.getName()); + } + response.setObjectName("affinitygroup"); return response; } diff --git a/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java index a17679313d6..8743bcb2028 100644 --- a/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java +++ b/server/src/com/cloud/api/query/dao/AffinityGroupJoinDaoImpl.java @@ -63,6 +63,7 @@ public class AffinityGroupJoinDaoImpl extends GenericDaoBase vnetToAdd : vnetsToAdd) { s_logger.debug("Adding vnet range " + vnetToAdd.first() + "-" + vnetToAdd.second() + " for the physicalNetwork id= " + id + " and zone id=" + network.getDataCenterId() + " as a part of updatePhysicalNetwork call"); @@ -2456,6 +2452,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService { } } + _physicalNetworkDao.update(id, network); + return network; } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 169db3283e3..f601f4fa2e4 100755 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -876,8 +876,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl if (publicNetwork) { routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); } else { - Long podId = dest.getPod().getId(); if (isPodBased) { + Long podId = dest.getPod().getId(); routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER); } else { routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER); diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java index b6c4a027484..f418cefd781 100644 --- a/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java +++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupVO.java @@ -107,7 +107,7 @@ public class AffinityGroupVO implements AffinityGroup { @Override public String toString() { StringBuilder buf = new StringBuilder("AffinityGroup["); - buf.append(id).append("|").append(name).append("|").append(type).append("]"); + buf.append(uuid).append("]"); return buf.toString(); } diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index a36be0ebbf4..ce651a01a77 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -512,6 +512,7 @@ CREATE VIEW `cloud`.`affinity_group_view` AS select affinity_group.id id, affinity_group.name name, + affinity_group.type type, affinity_group.description description, affinity_group.uuid uuid, account.id account_id, diff --git a/test/integration/smoke/test_public_ip_range.py b/test/integration/smoke/test_public_ip_range.py index a7aad6b795c..7c965ea1d94 100644 --- a/test/integration/smoke/test_public_ip_range.py +++ b/test/integration/smoke/test_public_ip_range.py @@ -49,7 +49,7 @@ class Services: "endip": "10.102.197.73", "zoneid": "1", "podid": "", - "vlan": "101", + "vlan": "4444", } class TesDedicatePublicIPRange(cloudstackTestCase): diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index 5fd3e1226a4..14b12e7910b 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -22,16 +22,20 @@ import hmac import hashlib import time import cloudstackException -from cloudstackAPI import * +from cloudstackAPI import * import jsonHelper from requests import ConnectionError from requests import HTTPError from requests import Timeout from requests import RequestException + class cloudConnection(object): - def __init__(self, mgtSvr, port=8096, apiKey=None, securityKey=None, asyncTimeout=3600, logging=None, - scheme='http', path='client/api'): + """ Connections to make API calls to the cloudstack management server + """ + def __init__(self, mgtSvr, port=8096, apiKey=None, securityKey=None, + asyncTimeout=3600, logging=None, scheme='http', + path='client/api'): self.apiKey = apiKey self.securityKey = securityKey self.mgtSvr = mgtSvr @@ -42,16 +46,18 @@ class cloudConnection(object): self.asyncTimeout = asyncTimeout self.auth = True if port == 8096 or \ - (self.apiKey == None and self.securityKey == None): + (self.apiKey is None and self.securityKey is None): self.auth = False if scheme not in ['http', 'https']: raise RequestException("Protocol must be HTTP") self.protocol = scheme - self.baseurl = "%s://%s:%d/%s"%(self.protocol, self.mgtSvr, self.port, self.path) + self.baseurl = "%s://%s:%d/%s"\ + % (self.protocol, self.mgtSvr, self.port, self.path) def __copy__(self): - return cloudConnection(self.mgtSvr, self.port, self.apiKey, self.securityKey, self.asyncTimeout, - self.logging, self.protocol, self.path) + return cloudConnection(self.mgtSvr, self.port, self.apiKey, + self.securityKey, self.asyncTimeout, + self.logging, self.protocol, self.path) def poll(self, jobid, response): """ @@ -68,16 +74,19 @@ class cloudConnection(object): asyncResonse = self.marvin_request(cmd, response_type=response) if asyncResonse.jobstatus == 2: - raise cloudstackException.cloudstackAPIException("asyncquery", asyncResonse.jobresult) + raise cloudstackException.cloudstackAPIException( + "asyncquery", asyncResonse.jobresult) elif asyncResonse.jobstatus == 1: return asyncResonse time.sleep(5) if self.logging is not None: - self.logging.debug("job: %s still processing, will timeout in %ds"%(jobid, timeout)) + self.logging.debug("job: %s still processing," + " will timeout in %ds" % (jobid, timeout)) timeout = timeout - 5 - raise cloudstackException.cloudstackAPIException("asyncquery", "Async job timeout %s"%jobid) + raise cloudstackException.cloudstackAPIException( + "asyncquery", "Async job timeout %s" % jobid) def sign(self, payload): """ @@ -90,19 +99,26 @@ class cloudConnection(object): params.sort(key=lambda k: str.lower(k[0])) hashStr = "&".join( ["=".join( - [str.lower(r[0]), str.lower(urllib.quote_plus(str(r[1]))).replace("+", "%20")] + [str.lower(r[0]), + str.lower( + urllib.quote_plus(str(r[1])) + ).replace("+", "%20")] ) for r in params] ) - signature = base64.encodestring(hmac.new(self.securityKey, hashStr, hashlib.sha1).digest()).strip() - self.logging.info("Computed Signature by Marvin: %s"%signature) + signature = base64.encodestring(hmac.new( + self.securityKey, hashStr, hashlib.sha1).digest()).strip() + self.logging.info("Computed Signature by Marvin: %s" % signature) return signature def request(self, command, auth=True, payload={}, data={}): """ - Makes requests on the `integration.api.port` - @param command: cloudstack API command name eg: deployVirtualMachineCommand - @param auth: Authentication (apikey,secretKey) => True, else False - @param payload: GET param data composed as a dictionary of key,value pairs + Makes requests using auth or over integration port + @param command: cloudstack API command name + eg: deployVirtualMachineCommand + @param auth: Authentication (apikey,secretKey) => True + else False for integration.api.port + @param payload: GET param data composed as a dictionary + of key,value pairs @param data: POST data as a dictionary @return: """ @@ -114,23 +130,24 @@ class cloudConnection(object): signature = self.sign(payload) payload["signature"] = signature - try: if data: - response = requests.get(self.baseurl, params=payload, data=data) + response = requests.get(self.baseurl, params=payload, + data=data) else: response = requests.get(self.baseurl, params=payload) except ConnectionError, c: - self.logging.debug("Connection refused. Reason: %s"%(self.baseurl, c)) + self.logging.debug("Connection refused. Reason: %s" % + (self.baseurl, c)) raise c except HTTPError, h: - self.logging.debug("Server returned error code: %s"%h) + self.logging.debug("Server returned error code: %s" % h) raise h except Timeout, t: - self.logging.debug("Connection timed out with %s"%t) + self.logging.debug("Connection timed out with %s" % t) raise t - except RequestException,r: - self.logging.debug("Error returned by server %s"%r) + except RequestException, r: + self.logging.debug("Error returned by server %s" % r) raise r else: return response @@ -144,7 +161,8 @@ class cloudConnection(object): requests = {} required = [] for attribute in dir(cmd): - if attribute != "__doc__" and attribute != "__init__" and attribute != "__module__": + if attribute != "__doc__" and attribute != "__init__" and \ + attribute != "__module__": if attribute == "isAsync": isAsync = getattr(cmd, attribute) elif attribute == "required": @@ -155,7 +173,8 @@ class cloudConnection(object): cmdname = cmd.__class__.__name__.replace("Cmd", "") for requiredPara in required: if requests[requiredPara] is None: - raise cloudstackException.cloudstackAPIException(cmdname, "%s is required"%requiredPara) + raise cloudstackException.cloudstackAPIException( + cmdname, "%s is required" % requiredPara) for param, value in requests.items(): if value is None: requests.pop(param) @@ -169,8 +188,8 @@ class cloudConnection(object): requests.pop(param) i = 0 for val in value: - for k,v in val.iteritems(): - requests["%s[%d].%s"%(param,i,k)] = v + for k, v in val.iteritems(): + requests["%s[%d].%s" % (param, i, k)] = v i = i + 1 return cmdname, isAsync, requests @@ -184,14 +203,17 @@ class cloudConnection(object): @return: """ cmdname, isAsync, payload = self.sanitize_command(cmd) - self.logging.info("sending command: %s %s"%(cmdname, str(payload))) + self.logging.info("sending command: %s %s" % (cmdname, str(payload))) if self.auth: - response = self.request(cmdname, auth=True, payload=payload, data=data) + response = self.request( + cmdname, auth=True, payload=payload, data=data) else: - response = self.request(cmdname, auth=False, payload=payload, data=data) + response = self.request( + cmdname, auth=False, payload=payload, data=data) - self.logging.info("Request: %s Response: %s"%(response.url, response.text)) - response = jsonHelper.getResultObj(response.json, response_type) + self.logging.info("Request: %s Response: %s" % + (response.url, response.text)) + response = jsonHelper.getResultObj(response.json(), response_type) if isAsync == "false": return response