def ex_describe_tags(self, node): """ Return a dictionary of tags for this instance. @type node: C{Node} @param node: Node instance @return dict Node tags """ params = {'Action': 'DescribeTags', 'Filter.0.Name': 'resource-id', 'Filter.0.Value.0': node.id, 'Filter.1.Name': 'resource-type', 'Filter.1.Value.0': 'instance', } result = self.connection.request(self.path, params=params.copy()).object tags = {} for element in findall(element=result, xpath='tagSet/item', namespace=NAMESPACE): key = findtext(element=element, xpath='key', namespace=NAMESPACE) value = findtext(element=element, xpath='value', namespace=NAMESPACE) tags[key] = value return tags
def _to_obj(self, element, container): owner_id = findtext(element=element, xpath='Owner/ID', namespace=NAMESPACE) owner_display_name = findtext(element=element, xpath='Owner/DisplayName', namespace=NAMESPACE) meta_data = { 'owner': { 'id': owner_id, 'display_name': owner_display_name } } obj = Object(name=findtext(element=element, xpath='Key', namespace=NAMESPACE), size=int( findtext(element=element, xpath='Size', namespace=NAMESPACE)), hash=findtext(element=element, xpath='ETag', namespace=NAMESPACE).replace('"', ''), extra=None, meta_data=meta_data, container=container, driver=self) return obj
def ex_describe_all_addresses(self, only_allocated=False): """ Return all the Elastic IP addresses for this account optionally, return only the allocated addresses @keyword only_allocated: If true, return only those addresses that are associated with an instance @type only_allocated: C{string} @return list list of elastic ips for this particular account. """ params = {'Action': 'DescribeAddresses'} result = self.connection.request(self.path, params=params.copy()).object # the list which we return elastic_ip_addresses = [] for element in findall(element=result, xpath='addressesSet/item', namespace=NAMESPACE): instance_id = findtext(element=element, xpath='instanceId', namespace=NAMESPACE) # if only allocated addresses are requested if only_allocated and not instance_id: continue ip_address = findtext(element=element, xpath='publicIp', namespace=NAMESPACE) elastic_ip_addresses.append(ip_address) return elastic_ip_addresses
def ex_create_keypair(self, name): """Creates a new keypair @note: This is a non-standard extension API, and only works for EC2. @type name: C{str} @param name: The name of the keypair to Create. This must be unique, otherwise an InvalidKeyPair.Duplicate exception is raised. """ params = { 'Action': 'CreateKeyPair', 'KeyName': name, } response = self.connection.request(self.path, params=params).object key_material = findtext(element=response, xpath='keyMaterial', namespace=NAMESPACE) key_fingerprint = findtext(element=response, xpath='keyFingerprint', namespace=NAMESPACE) return { 'keyMaterial': key_material, 'keyFingerprint': key_fingerprint, }
def _to_image(self, element): n = NodeImage(id=findtext(element=element, xpath='imageId', namespace=NAMESPACE), name=findtext(element=element, xpath='imageLocation', namespace=NAMESPACE), driver=self.connection.driver) return n
def ex_import_keypair(self, name, keyfile): """imports a new public key @note: This is a non-standard extension API, and only works for EC2. @type name: C{str} @param name: The name of the public key to import. This must be unique, otherwise an InvalidKeyPair.Duplicate exception is raised. @type keyfile: C{str} @param keyfile: The filename with path of the public key to import. """ with open(os.path.expanduser(keyfile)) as fh: content = fh.read() base64key = base64.b64encode(content) params = {'Action': 'ImportKeyPair', 'KeyName': name, 'PublicKeyMaterial': base64key } response = self.connection.request(self.path, params=params).object key_name = findtext(element=response, xpath='keyName', namespace=NAMESPACE) key_fingerprint = findtext(element=response, xpath='keyFingerprint', namespace=NAMESPACE) return { 'keyName': key_name, 'keyFingerprint': key_fingerprint, }
def _to_image(self, element): n = NodeImage(id=findtext(element=element, xpath='imageId', namespace=NAMESPACE), name=findtext(element=element, xpath='imageLocation', namespace=NAMESPACE), driver=self.connection.driver, extra={ 'state': findattr(element=element, xpath="imageState", namespace=NAMESPACE), 'ownerid': findattr(element=element, xpath="imageOwnerId", namespace=NAMESPACE), 'owneralias': findattr(element=element, xpath="imageOwnerAlias", namespace=NAMESPACE), 'ispublic': findattr(element=element, xpath="isPublic", namespace=NAMESPACE), 'architecture': findattr(element=element, xpath="architecture", namespace=NAMESPACE), 'imagetype': findattr(element=element, xpath="imageType", namespace=NAMESPACE), 'platform': findattr(element=element, xpath="platform", namespace=NAMESPACE), 'rootdevicetype': findattr(element=element, xpath="rootDeviceType", namespace=NAMESPACE), 'virtualizationtype': findattr(element=element, xpath="virtualizationType", namespace=NAMESPACE), 'hypervisor': findattr(element=element, xpath="hypervisor", namespace=NAMESPACE) }) return n
def _to_container(self, element): extra = { 'creation_date': findtext(element=element, xpath='CreationDate', namespace=self.namespace) } container = Container( name=findtext(element=element, xpath='Name', namespace=self.namespace), extra=extra, driver=self ) return container
def _to_container(self, element): extra = { 'creation_date': findtext(element=element, xpath='CreationDate', namespace=NAMESPACE) } container = Container( name=findtext(element=element, xpath='Name', namespace=NAMESPACE), extra=extra, driver=self ) return container
def _to_record(self, elem, zone): id = findtext(element=elem, xpath='id') name = findtext(element=elem, xpath='hostname') type = findtext(element=elem, xpath='host-type') type = self._string_to_record_type(type) data = findtext(element=elem, xpath='data') notes = findtext(element=elem, xpath='notes') state = findtext(element=elem, xpath='state') fqdn = findtext(element=elem, xpath='fqdn') priority = findtext(element=elem, xpath='priority') extra = { 'notes': notes, 'state': state, 'fqdn': fqdn, 'priority': priority } record = Record(id=id, name=name, type=type, data=data, zone=zone, driver=self, extra=extra) return record
def parse_error(self): if self.status == httplib.UNAUTHORIZED: raise InvalidCredsError(self.body) elif self.status == httplib.FORBIDDEN: raise InvalidCredsError(self.body) body = self.parse_body() if self.status == httplib.BAD_REQUEST: code = findtext(body, 'resultCode', SERVER_NS) message = findtext(body, 'resultDetail', SERVER_NS) raise OpsourceAPIException(code, message, driver=OpsourceNodeDriver) return self.body
def ex_start_node(self, node): """ Powers on an existing deployed server """ body = self.connection.request_with_orgId('server/%s?start' % node.id).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def _get_orgId(self): """ send the /myaccount API request to opsource cloud and parse the 'orgId' from the XML response object. We need the orgId to use most of the other API functions """ if self._orgId == None: body = self.request('myaccount').object self._orgId = findtext(body, 'orgId', DIRECTORY_NS) return self._orgId
def ex_describe_addresses(self, nodes): """ Return Elastic IP addresses for all the nodes in the provided list. @type nodes: C{list} @param nodes: List of C{Node} instances @return dict Dictionary where a key is a node ID and the value is a list with the Elastic IP addresses associated with this node. """ if not nodes: return {} params = {'Action': 'DescribeAddresses'} if len(nodes) == 1: params.update({ 'Filter.0.Name': 'instance-id', 'Filter.0.Value.0': nodes[0].id }) result = self.connection.request(self.path, params=params.copy()).object node_instance_ids = [node.id for node in nodes] nodes_elastic_ip_mappings = {} for node_id in node_instance_ids: nodes_elastic_ip_mappings.setdefault(node_id, []) for element in findall(element=result, xpath='addressesSet/item', namespace=NAMESPACE): instance_id = findtext(element=element, xpath='instanceId', namespace=NAMESPACE) ip_address = findtext(element=element, xpath='publicIp', namespace=NAMESPACE) if instance_id not in node_instance_ids: continue nodes_elastic_ip_mappings[instance_id].append(ip_address) return nodes_elastic_ip_mappings
def ex_list_availability_zones(self, only_available=True): """ Return a list of L{ExEC2AvailabilityZone} objects for the current region. Note: This is an extension method and is only available for EC2 driver. @keyword only_available: If true, return only availability zones with state 'available' @type only_available: C{string} """ params = {'Action': 'DescribeAvailabilityZones'} if only_available: params.update({'Filter.0.Name': 'state'}) params.update({'Filter.0.Value.0': 'available'}) params.update({'Filter.1.Name': 'region-name'}) params.update({'Filter.1.Value.0': self.region_name}) result = self.connection.request(self.path, params=params.copy()).object availability_zones = [] for element in findall(element=result, xpath='availabilityZoneInfo/item', namespace=NAMESPACE): name = findtext(element=element, xpath='zoneName', namespace=NAMESPACE) zone_state = findtext(element=element, xpath='zoneState', namespace=NAMESPACE) region_name = findtext(element=element, xpath='regionName', namespace=NAMESPACE) availability_zone = ExEC2AvailabilityZone(name=name, zone_state=zone_state, region_name=region_name) availability_zones.append(availability_zone) return availability_zones
def ex_power_off(self, node): """This function will abruptly power-off a server. Unlike ex_shutdown_graceful, success ensures the node will stop but some OS and application configurations may be adversely affected by the equivalent of pulling the power plug out of the machine. """ body = self.connection.request_with_orgId('server/%s?poweroff' % node.id).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def ex_list_availability_zones(self, only_available=True): """ Return a list of L{ExEC2AvailabilityZone} objects for the current region. Note: This is an extension method and is only available for EC2 driver. @keyword only_available: If true, return only availability zones with state 'available' @type only_available: C{string} """ params = {'Action': 'DescribeAvailabilityZones'} if only_available: params.update({'Filter.0.Name': 'state'}) params.update({'Filter.0.Value.0': 'available'}) params.update({'Filter.1.Name': 'region-name'}) params.update({'Filter.1.Value.0': self.region_name}) result = self.connection.request(self.path, params=params.copy()).object availability_zones = [] for element in findall(element=result, xpath='availabilityZoneInfo/item', namespace=NAMESPACE): name = findtext(element=element, xpath='zoneName', namespace=NAMESPACE) zone_state = findtext(element=element, xpath='zoneState', namespace=NAMESPACE) region_name = findtext(element=element, xpath='regionName', namespace=NAMESPACE) availability_zone = ExEC2AvailabilityZone( name=name, zone_state=zone_state, region_name=region_name ) availability_zones.append(availability_zone) return availability_zones
def ex_shutdown_graceful(self, node): """This function will attempt to "gracefully" stop a server by initiating a shutdown sequence within the guest operating system. A successful response on this function means the system has successfully passed the request into the operating system. """ body = self.connection.request_with_orgId('server/%s?shutdown' % node.id).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def _get_orgId(self): """ Send the /myaccount API request to opsource cloud and parse the 'orgId' from the XML response object. We need the orgId to use most of the other API functions """ if self._orgId == None: body = self.request('myaccount').object self._orgId = findtext(body, 'orgId', DIRECTORY_NS) return self._orgId
def ex_power_off(self, node): """ This function will abruptly power-off a server. Unlike ex_shutdown_graceful, success ensures the node will stop but some OS and application configurations may be adversely affected by the equivalent of pulling the power plug out of the machine. """ body = self.connection.request_with_orgId('server/%s?poweroff' % node.id).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def ex_shutdown_graceful(self, node): """ This function will attempt to "gracefully" stop a server by initiating a shutdown sequence within the guest operating system. A successful response on this function means the system has successfully passed the request into the operating system. """ body = self.connection.request_with_orgId('server/%s?shutdown' % (node.id)).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def _to_status(self, element): if element == None: return OpsourceStatus() s = OpsourceStatus( action=findtext(element, 'action', SERVER_NS), requestTime=findtext(element, 'requestTime', SERVER_NS), userName=findtext(element, 'userName', SERVER_NS), numberOfSteps=findtext(element, 'numberOfSteps', SERVER_NS), step_name=findtext(element, 'step/name', SERVER_NS), step_number=findtext(element, 'step_number', SERVER_NS), step_percentComplete=findtext(element, 'step/percentComplete', SERVER_NS), failureReason=findtext(element, 'failureReason', SERVER_NS)) return s
def _to_image(self, element): n = NodeImage(id=findtext(element=element, xpath='imageId', namespace=NAMESPACE), name=findtext(element=element, xpath='imageLocation', namespace=NAMESPACE), driver=self.connection.driver, extra={ 'state': findattr(element=element, xpath="imageState", namespace=NAMESPACE), 'ownerid': findattr(element=element, xpath="imageOwnerId", namespace=NAMESPACE), 'owneralias': findattr(element=element, xpath="imageOwnerAlias", namespace=NAMESPACE), 'ispublic': findattr(element=element, xpath="isPublic", namespace=NAMESPACE), 'architecture': findattr(element=element, xpath="architecture", namespace=NAMESPACE), 'imagetype': findattr(element=element, xpath="imageType", namespace=NAMESPACE), 'platform': findattr(element=element, xpath="platform", namespace=NAMESPACE), 'rootdevicetype': findattr(element=element, xpath="rootDeviceType", namespace=NAMESPACE), 'virtualizationtype': findattr(element=element, xpath="virtualizationType", namespace=NAMESPACE), 'hypervisor': findattr(element=element, xpath="hypervisor", namespace=NAMESPACE) } ) return n
def parse_error(self): if self.status == 401: raise InvalidCredsError(self.body) if self.status == 403: raise InvalidCredsError(self.body) try: body = ET.XML(self.body) except: raise MalformedResponseError("Failed to parse XML", body=self.body, driver=OpsourceNodeDriver) if self.status == 400: code = findtext(body, 'resultCode', SERVER_NS) message = findtext(body, 'resultDetail', SERVER_NS) raise OpsourceAPIException(code, message, driver=OpsourceNodeDriver) return self.body
def ex_describe_addresses(self, nodes): """ Return Elastic IP addresses for all the nodes in the provided list. @type nodes: C{list} @param nodes: List of C{Node} instances @return dict Dictionary where a key is a node ID and the value is a list with the Elastic IP addresses associated with this node. """ if not nodes: return {} params = {'Action': 'DescribeAddresses'} if len(nodes) == 1: self._add_instance_filter(params, nodes[0]) result = self.connection.request(self.path, params=params.copy()).object node_instance_ids = [node.id for node in nodes] nodes_elastic_ip_mappings = {} for node_id in node_instance_ids: nodes_elastic_ip_mappings.setdefault(node_id, []) for element in findall(element=result, xpath='addressesSet/item', namespace=NAMESPACE): instance_id = findtext(element=element, xpath='instanceId', namespace=NAMESPACE) ip_address = findtext(element=element, xpath='publicIp', namespace=NAMESPACE) if instance_id not in node_instance_ids: continue nodes_elastic_ip_mappings[instance_id].append(ip_address) return nodes_elastic_ip_mappings
def _to_obj(self, element, container): owner_id = findtext(element=element, xpath='Owner/ID', namespace=self.namespace) owner_display_name = findtext(element=element, xpath='Owner/DisplayName', namespace=self.namespace) meta_data = { 'owner': { 'id': owner_id, 'display_name':owner_display_name }} obj = Object(name=findtext(element=element, xpath='Key', namespace=self.namespace), size=int(findtext(element=element, xpath='Size', namespace=self.namespace)), hash=findtext(element=element, xpath='ETag', namespace=self.namespace).replace('"', ''), extra=None, meta_data=meta_data, container=container, driver=self ) return obj
def _to_record(self, elem, zone): id = findtext(element=elem, xpath='id') name = findtext(element=elem, xpath='hostname') type = findtext(element=elem, xpath='host-type') type = self._string_to_record_type(type) data = findtext(element=elem, xpath='data') notes = findtext(element=elem, xpath='notes') state = findtext(element=elem, xpath='state') fqdn = findtext(element=elem, xpath='fqdn') priority = findtext(element=elem, xpath='priority') extra = {'notes': notes, 'state': state, 'fqdn': fqdn, 'priority': priority} record = Record(id=id, name=name, type=type, data=data, zone=zone, driver=self, extra=extra) return record
def _to_status(self, element): if element == None: return OpsourceStatus() s = OpsourceStatus(action=findtext(element, 'action', SERVER_NS), requestTime=findtext(element, 'requestTime', SERVER_NS), userName=findtext(element, 'userName', SERVER_NS), numberOfSteps=findtext(element, 'numberOfSteps', SERVER_NS), step_name=findtext(element, 'step/name', SERVER_NS), step_number=findtext(element, 'step_number', SERVER_NS), step_percentComplete=findtext(element, 'step/percentComplete', SERVER_NS), failureReason=findtext(element, 'failureReason', SERVER_NS)) return s
def ex_modify_instance_attribute(self, node, attributes): """ Modify node attributes. A list of valid attributes can be found at http://goo.gl/gxcj8 @type node: C{Node} @param node: Node instance @type attributes: C{dict} @param attributes: Dictionary with node attributes @return bool True on success, False otherwise. """ attributes = attributes or {} attributes.update({'InstanceId': node.id}) params = {'Action': 'ModifyInstanceAttribute'} params.update(attributes) result = self.connection.request(self.path, params=params.copy()).object element = findtext(element=result, xpath='return', namespace=NAMESPACE) return element == 'true'
def _to_network(self, element): multicast = False if findtext(element, 'multicast', NETWORK_NS) == 'true': multicast = True status = self._to_status(element.find(fixxpath('status', NETWORK_NS))) location_id = findtext(element, 'location', NETWORK_NS) location = self.ex_get_location_by_id(location_id) return OpsourceNetwork(id=findtext(element, 'id', NETWORK_NS), name=findtext(element, 'name', NETWORK_NS), description=findtext(element, 'description', NETWORK_NS), location=location, privateNet=findtext(element, 'privateNet', NETWORK_NS), multicast=multicast, status=status)
def _to_zone(self, elem): id = findtext(element=elem, xpath='id') domain = findtext(element=elem, xpath='domain') type = findtext(element=elem, xpath='ns-type') type = 'master' if type.find('pri') == 0 else 'slave' ttl = findtext(element=elem, xpath='default-ttl') hostmaster = findtext(element=elem, xpath='hostmaster') custom_ns = findtext(element=elem, xpath='custom-ns') custom_nameservers = findtext(element=elem, xpath='custom-nameservers') notes = findtext(element=elem, xpath='notes') nx_ttl = findtext(element=elem, xpath='nx-ttl') slave_nameservers = findtext(element=elem, xpath='slave-nameservers') tags = findtext(element=elem, xpath='tag-list') tags = tags.split(' ') if tags else [] extra = {'hostmaster': hostmaster, 'custom-ns': custom_ns, 'custom-nameservers': custom_nameservers, 'notes': notes, 'nx-ttl': nx_ttl, 'slave-nameservers': slave_nameservers, 'tags': tags} zone = Zone(id=str(id), domain=domain, type=type, ttl=int(ttl), driver=self, extra=extra) return zone
def reboot_node(self, node): body = self.connection.request_with_orgId('server/%s?restart' % (node.id)).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def _to_zone(self, elem): id = findtext(element=elem, xpath='id') domain = findtext(element=elem, xpath='domain') type = findtext(element=elem, xpath='ns-type') type = 'master' if type.find('pri') == 0 else 'slave' ttl = findtext(element=elem, xpath='default-ttl') hostmaster = findtext(element=elem, xpath='hostmaster') custom_ns = findtext(element=elem, xpath='custom-ns') custom_nameservers = findtext(element=elem, xpath='custom-nameservers') notes = findtext(element=elem, xpath='notes') nx_ttl = findtext(element=elem, xpath='nx-ttl') slave_nameservers = findtext(element=elem, xpath='slave-nameservers') tags = findtext(element=elem, xpath='tag-list') tags = tags.split(' ') if tags else [] extra = { 'hostmaster': hostmaster, 'custom-ns': custom_ns, 'custom-nameservers': custom_nameservers, 'notes': notes, 'nx-ttl': nx_ttl, 'slave-nameservers': slave_nameservers, 'tags': tags } zone = Zone(id=str(id), domain=domain, type=type, ttl=int(ttl), driver=self, extra=extra) return zone
def _to_node(self, element, groups=None): try: state = self.NODE_STATE_MAP[ findattr(element=element, xpath="instanceState/name", namespace=NAMESPACE) ] except KeyError: state = NodeState.UNKNOWN instance_id = findtext(element=element, xpath='instanceId', namespace=NAMESPACE) tags = dict((findtext(element=item, xpath='key', namespace=NAMESPACE), findtext(element=item, xpath='value', namespace=NAMESPACE)) for item in findall(element=element, xpath='tagSet/item', namespace=NAMESPACE)) name = tags.get('Name', instance_id) n = Node( id=findtext(element=element, xpath='instanceId', namespace=NAMESPACE), name=name, state=state, public_ip=[findtext(element=element, xpath='ipAddress', namespace=NAMESPACE)], private_ip=[findtext(element=element, xpath='privateIpAddress', namespace=NAMESPACE)], driver=self.connection.driver, extra={ 'dns_name': findattr(element=element, xpath="dnsName", namespace=NAMESPACE), 'instanceId': findattr(element=element, xpath="instanceId", namespace=NAMESPACE), 'imageId': findattr(element=element, xpath="imageId", namespace=NAMESPACE), 'private_dns': findattr(element=element, xpath="privateDnsName", namespace=NAMESPACE), 'status': findattr(element=element, xpath="instanceState/name", namespace=NAMESPACE), 'keyname': findattr(element=element, xpath="keyName", namespace=NAMESPACE), 'launchindex': findattr(element=element, xpath="amiLaunchIndex", namespace=NAMESPACE), 'productcode': [p.text for p in findall(element=element, xpath="productCodesSet/item/productCode", namespace=NAMESPACE )], 'instancetype': findattr(element=element, xpath="instanceType", namespace=NAMESPACE), 'launchdatetime': findattr(element=element, xpath="launchTime", namespace=NAMESPACE), 'availability': findattr(element, xpath="placement/availabilityZone", namespace=NAMESPACE), 'kernelid': findattr(element=element, xpath="kernelId", namespace=NAMESPACE), 'ramdiskid': findattr(element=element, xpath="ramdiskId", namespace=NAMESPACE), 'clienttoken': findattr(element=element, xpath="clientToken", namespace=NAMESPACE), 'groups': groups, 'tags': tags } ) return n
def _to_base_image(self, element): # Eventually we will probably need multiple _to_image() functions # that parse <ServerImage> differently than <DeployedImage>. # DeployedImages are customer snapshot images, and ServerImages are # 'base' images provided by opsource location_id = findtext(element, 'location', SERVER_NS) location = self.ex_get_location_by_id(location_id) extra = { 'description': findtext(element, 'description', SERVER_NS), 'OS_type': findtext(element, 'operatingSystem/type', SERVER_NS), 'OS_displayName': findtext(element, 'operatingSystem/displayName', SERVER_NS), 'cpuCount': findtext(element, 'cpuCount', SERVER_NS), 'resourcePath': findtext(element, 'resourcePath', SERVER_NS), 'memory': findtext(element, 'memory', SERVER_NS), 'osStorage': findtext(element, 'osStorage', SERVER_NS), 'additionalStorage': findtext(element, 'additionalStorage', SERVER_NS), 'created': findtext(element, 'created', SERVER_NS), 'location': location, } return NodeImage(id=str(findtext(element, 'id', SERVER_NS)), name=str(findtext(element, 'name', SERVER_NS)), extra=extra, driver=self.connection.driver)
def _to_node(self, element): if findtext(element, 'isStarted', SERVER_NS) == 'true': state = NodeState.RUNNING else: state = NodeState.TERMINATED status = self._to_status(element.find(fixxpath('status', SERVER_NS))) extra = { 'description': findtext(element, 'description', SERVER_NS), 'sourceImageId': findtext(element, 'sourceImageId', SERVER_NS), 'networkId': findtext(element, 'networkId', SERVER_NS), 'machineName': findtext(element, 'machineName', SERVER_NS), 'deployedTime': findtext(element, 'deployedTime', SERVER_NS), 'cpuCount': findtext(element, 'machineSpecification/cpuCount', SERVER_NS), 'memoryMb': findtext(element, 'machineSpecification/memoryMb', SERVER_NS), 'osStorageGb': findtext(element, 'machineSpecification/osStorageGb', SERVER_NS), 'additionalLocalStorageGb': findtext(element, 'machineSpecification/additionalLocalStorageGb', SERVER_NS), 'OS_type': findtext(element, 'machineSpecification/operatingSystem/type', SERVER_NS), 'OS_displayName': findtext(element, 'machineSpecification/operatingSystem/displayName', SERVER_NS), 'status': status, } n = Node(id=findtext(element, 'id', SERVER_NS), name=findtext(element, 'name', SERVER_NS), state=state, public_ips=[], private_ips=findtext(element, 'privateIpAddress', SERVER_NS), driver=self.connection.driver, extra=extra) return n
def _to_location(self, element): l = NodeLocation(id=findtext(element, 'location', DATACENTER_NS), name=findtext(element, 'displayName', DATACENTER_NS), country=findtext(element, 'country', DATACENTER_NS), driver=self) return l
def destroy_node(self, node): """Destroys the node""" body = self.connection.request_with_orgId('server/%s?delete' % node.id).object result = findtext(body, 'result', GENERAL_NS) return result == 'SUCCESS'
def _to_node(self, element, groups=None): try: state = self.NODE_STATE_MAP[ findattr(element=element, xpath="instanceState/name", namespace=NAMESPACE) ] except KeyError: state = NodeState.UNKNOWN instance_id = findtext(element=element, xpath='instanceId', namespace=NAMESPACE) tags = dict((findtext(element=item, xpath='key', namespace=NAMESPACE), findtext(element=item, xpath='value', namespace=NAMESPACE)) for item in findall(element=element, xpath='tagSet/item', namespace=NAMESPACE)) name = tags.get('Name', instance_id) public_ip = findtext(element=element, xpath='ipAddress', namespace=NAMESPACE) public_ips = [public_ip] if public_ip else [] private_ip = findtext(element=element, xpath='privateIpAddress', namespace=NAMESPACE) private_ips = [private_ip] if private_ip else [] n = Node( id=findtext(element=element, xpath='instanceId', namespace=NAMESPACE), name=name, state=state, public_ips=public_ips, private_ips=private_ips, driver=self.connection.driver, extra={ 'dns_name': findattr(element=element, xpath="dnsName", namespace=NAMESPACE), 'instanceId': findattr(element=element, xpath="instanceId", namespace=NAMESPACE), 'imageId': findattr(element=element, xpath="imageId", namespace=NAMESPACE), 'private_dns': findattr(element=element, xpath="privateDnsName", namespace=NAMESPACE), 'status': findattr(element=element, xpath="instanceState/name", namespace=NAMESPACE), 'keyname': findattr(element=element, xpath="keyName", namespace=NAMESPACE), 'launchindex': findattr(element=element, xpath="amiLaunchIndex", namespace=NAMESPACE), 'productcode': [p.text for p in findall(element=element, xpath="productCodesSet/item/productCode", namespace=NAMESPACE )], 'instancetype': findattr(element=element, xpath="instanceType", namespace=NAMESPACE), 'launchdatetime': findattr(element=element, xpath="launchTime", namespace=NAMESPACE), 'availability': findattr(element, xpath="placement/availabilityZone", namespace=NAMESPACE), 'kernelid': findattr(element=element, xpath="kernelId", namespace=NAMESPACE), 'ramdiskid': findattr(element=element, xpath="ramdiskId", namespace=NAMESPACE), 'clienttoken': findattr(element=element, xpath="clientToken", namespace=NAMESPACE), 'groups': groups, 'tags': tags } ) return n