def _to_keypair(self, element): n = KeyPair( keyName=findattr(element=element, xpath="keyName", namespace=NAMESPACE), keyFingerprint=findattr(element=element, xpath="keyFingerprint", namespace=NAMESPACE), # keyMaterial = findattr(element=element, xpath="keyMaterial", namespace=NAMESPACE), ) return n
def _to_instanceState(self, element): n = InstanceState( description = findattr(element=element, xpath="Description", namespace=NAMESPACE), instanceId = findattr(element=element, xpath="InstanceId", namespace=NAMESPACE), reasonCode = findattr(element=element, xpath="ReasonCode", namespace=NAMESPACE), state = findattr(element=element, xpath="State", namespace=NAMESPACE), ) return n
def _to_listener(self, element): n = Listener( instancePort = findattr(element=element, xpath="InstancePort", namespace=NAMESPACE), instanceProtocol = findattr(element=element, xpath="InstanceProtocol", namespace=NAMESPACE), loadBalancerPort = findattr(element=element, xpath="LoadBalancerPort", namespace=NAMESPACE), protocol = findattr(element=element, xpath="Protocol", namespace=NAMESPACE), ) return n
def _to_tagSet(self, element): n = TagSet( resourceId=findattr(element=element, xpath="resourceId", namespace=NAMESPACE), resourceType=findattr(element=element, xpath="resourceType", namespace=NAMESPACE), key=findattr(element=element, xpath="key", namespace=NAMESPACE), value=findattr(element=element, xpath="value", namespace=NAMESPACE), ) return n
def _to_vpcInfo(self, element): n = VpcInfo( vpcId=findattr(element=element, xpath="vpcId", namespace=NAMESPACE), state=findattr(element=element, xpath="state", namespace=NAMESPACE), cidrBlock=findattr(element=element, xpath="cidrBlock", namespace=NAMESPACE), dhcpOptionsId=findattr(element=element, xpath="dhcpOptionsId", namespace=NAMESPACE), tagSet=findattr(element=element, xpath="tagSet", namespace=NAMESPACE), ) return n
def _to_address(self, element): n = Address( publicIp=findattr(element=element, xpath="publicIp", namespace=NAMESPACE), domain=findattr(element=element, xpath="domain", namespace=NAMESPACE), instanceId=findattr(element=element, xpath="instanceId", namespace=NAMESPACE), allocationId=findattr(element=element, xpath="allocationId", namespace=NAMESPACE), associationId=findattr(element=element, xpath="associationId", namespace=NAMESPACE), ) return n
def _to_attachmentSet(self, element): n = AttachmentSet( volumeId=findattr(element=element, xpath="volumeId", namespace=NAMESPACE), instanceId=findattr(element=element, xpath="instanceId", namespace=NAMESPACE), device=findattr(element=element, xpath="device", namespace=NAMESPACE), status=findattr(element=element, xpath="status", namespace=NAMESPACE), attachTime=findattr(element=element, xpath="attachTime", namespace=NAMESPACE), ) return n
def _to_healthCheck (self, element): n = HealthCheck( healthyThreshold = findattr(element=element, xpath="HealthyThreshold", namespace=NAMESPACE), interval = findattr(element=element, xpath="Interval", namespace=NAMESPACE), target = findattr(element=element, xpath="Target", namespace=NAMESPACE), timeout = findattr(element=element, xpath="Timeout", namespace=NAMESPACE), unhealthyThreshold = findattr(element=element, xpath="UnhealthyThreshold", namespace=NAMESPACE), ) return n
def _to_regionInfo(self, element): n = RegionInfo( regionName=findattr(element=element, xpath="regionName", namespace=NAMESPACE), regionEndpoint=findattr(element=element, xpath="regionEndpoint", namespace=NAMESPACE), ) return n
def _to_snapshot(self, element): n = SnapshotSet( snapshotId=findattr(element=element, xpath="snapshotId", namespace=NAMESPACE), volumeId=findattr(element=element, xpath="volumeId", namespace=NAMESPACE), status=findattr(element=element, xpath="status", namespace=NAMESPACE), startTime=findattr(element=element, xpath="startTime", namespace=NAMESPACE), progress=findattr(element=element, xpath="progress", namespace=NAMESPACE), ownerId=findattr(element=element, xpath="ownerId", namespace=NAMESPACE), volumeSize=findattr(element=element, xpath="volumeSize", namespace=NAMESPACE), description=findattr(element=element, xpath="description", namespace=NAMESPACE), tagSet=findattr(element=element, xpath="tagSet", namespace=NAMESPACE), ) return n
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={ "rootDeviceType": findattr(element=element, xpath="rootDeviceType", namespace=NAMESPACE), "platform": findattr(element=element, xpath="platform", namespace=NAMESPACE), }, ) return n
def _to_keypair(self, element): n = KeyPair( keyName=findattr(element=element, xpath="keyName", namespace=NAMESPACE), keyFingerprint=findattr(element=element, xpath="keyFingerprint", namespace=NAMESPACE), #keyMaterial = findattr(element=element, xpath="keyMaterial", namespace=NAMESPACE), ) return n
def _to_ipPermissions(self, element): ipRanges = [] for rs in findall(element=element, xpath="ipRanges/item", namespace=NAMESPACE): ipRanges.append(findattr(element=rs, xpath="cidrIp", namespace=NAMESPACE)) n = IpPermissions( ipProtocol=findattr(element=element, xpath="ipProtocol", namespace=NAMESPACE), fromPort=findattr(element=element, xpath="fromPort", namespace=NAMESPACE), toPort=findattr(element=element, xpath="toPort", namespace=NAMESPACE), groups=findattr(element=element, xpath="groups", namespace=NAMESPACE), ipRanges=ipRanges, ) return n
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 describeInstances(self, instanceid=None): params = {'Action': 'DescribeInstances'} #任意パラメータ if instanceid != None: params.update({'InstanceId.0': instanceid}) elem = self.connection.request(self.path, params=params).object nodes = [] for rs in findall(element=elem, xpath='reservationSet/item', namespace=NAMESPACE): groups = [] for g in findall( element=rs, xpath= 'instancesSet/item/networkInterfaceSet/item/groupSet/item', namespace=NAMESPACE): groups.append( findattr(element=g, xpath='groupId', namespace=NAMESPACE)) nodes += self._to_nodes(rs, 'instancesSet/item', groups) nodes_elastic_ips_mappings = self.ex_describe_addresses(nodes) for node in nodes: node.public_ip.extend(nodes_elastic_ips_mappings[node.id]) return nodes
def createLoadBalancer(self, availabilityZone, listeners, loadBalancerName, subnetIds, securityGroups, internal): params = {'Action': 'CreateLoadBalancer', 'LoadBalancerName' : loadBalancerName} for i,listener in enumerate(listeners, 1): params['Listeners.member.%d.LoadBalancerPort' % i] = listener.loadBalancerPort params['Listeners.member.%d.InstancePort' % i] = listener.instancePort params['Listeners.member.%d.Protocol' % i] = listener.protocol if listener.protocol=='HTTPS' or listener.protocol=='SSL': params['Listeners.member.%d.SSLCertificateId' % i] = listener.sslCertificateId #選択パラメータ if len(subnetIds) != 0: #サブネットが指定されている場合サブネットを指定する for i,subnetId in enumerate(subnetIds, 1): params['Subnets.member.%d' % i] = subnetId #セキュリティグループ for i,group in enumerate(securityGroups, 1): params['SecurityGroups.member.%d' % i] = group else: #サブネットが指定されていない場合はゾーンを指定する params['AvailabilityZones.member.1'] = availabilityZone #内部ロードバランサ有効 if internal: params['Scheme'] = "internal" self.logger.debug(params) elem = self.connection.request(self.path, params=params).object dnsName = findattr(element=elem, xpath="CreateLoadBalancerResult/DNSName", namespace=NAMESPACE) return dnsName
def _get_extra_dict(self, element, mapping): """ Extract attributes from the element based on rules provided in the mapping dictionary. :param element: Element to parse the values from. :type element: xml.etree.ElementTree.Element. :param mapping: Dictionary with the extra layout :type node: :class:`Node` :rtype: ``dict`` """ extra = {} for attribute, values in mapping.items(): transform_func = values['transform_func'] value = findattr(element=element, xpath=values['xpath'], namespace=self.namespace) if value: try: extra[attribute] = transform_func(value) except Exception: extra[attribute] = None else: extra[attribute] = value return extra
def _to_volumes(self, element): #ステータスチェック(保留) #try: # state = self.NODE_STATE_MAP[ # findattr(element=element, xpath="instanceState/name", # namespace=NAMESPACE) # ] #except KeyError: # state = NodeState.UNKNOWN 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)) attachment = [] for rs in findall(element=element, xpath='attachmentSet/item', namespace=NAMESPACE): attachmentset = self._to_attachmentSet(rs) attachmentset.setDeleteOnTermination( findattr(element=element, xpath="deleteOnTermination", namespace=NAMESPACE)) attachment.append(attachmentset) v = self._to_volume(element, attachment, tags) return v
def _to_volumes(self, element): # ステータスチェック(保留) # try: # state = self.NODE_STATE_MAP[ # findattr(element=element, xpath="instanceState/name", # namespace=NAMESPACE) # ] # except KeyError: # state = NodeState.UNKNOWN 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) ) attachment = [] for rs in findall(element=element, xpath="attachmentSet/item", namespace=NAMESPACE): attachmentset = self._to_attachmentSet(rs) attachmentset.setDeleteOnTermination( findattr(element=element, xpath="deleteOnTermination", namespace=NAMESPACE) ) attachment.append(attachmentset) v = self._to_volume(element, attachment, tags) return v
def createKeyPair(self, keyName): params = {"Action": "CreateKeyPair", "KeyName": keyName} elem = self.connection.request(self.path, params=params).object keypair = self._to_keypair(elem) keypair.setKeyMaterial(findattr(element=elem, xpath="keyMaterial", namespace=NAMESPACE))
def createKeyPair(self, keyName): params = {'Action': 'CreateKeyPair', 'KeyName': keyName} elem = self.connection.request(self.path, params=params).object keypair = self._to_keypair(elem) keypair.setKeyMaterial( findattr(element=elem, xpath="keyMaterial", namespace=NAMESPACE))
def _to_securityGroup(self, element): ipPermissions = [] for rs in findall(element=element, xpath='ipPermissions/item', namespace=NAMESPACE): ipPermissions.append(self._to_ipPermissions(rs)) n = SecurityGroup( ownerId=findattr(element=element, xpath="ownerId", namespace=NAMESPACE), groupId=findattr(element=element, xpath="groupId", namespace=NAMESPACE), groupName=findattr(element=element, xpath="groupName", namespace=NAMESPACE), groupDescription=findattr(element=element, xpath="groupDescription", namespace=NAMESPACE), vpcId=findattr(element=element, xpath="vpcId", namespace=NAMESPACE), ipPermissions=ipPermissions, ipPermissionsEgress=findattr(element=element, xpath="ipPermissionsEgress", namespace=NAMESPACE), tagSet=findattr(element=element, xpath="tagSet", namespace=NAMESPACE), ) return n
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={ 'rootDeviceType': findattr(element=element, xpath="rootDeviceType", namespace=NAMESPACE), 'platform': findattr(element=element, xpath="platform", namespace=NAMESPACE), }) return n
def allocateVpcAddress(self): params = {"Action": "AllocateAddress", "Domain": "vpc"} elem = self.connection.request(self.path, params=params).object publicIp = findattr(element=elem, xpath="publicIp", namespace=NAMESPACE) # ログ出力 self.logger.info(None, "IPROCESS-100133", [publicIp]) return publicIp
def getPasswordData(self, InstanceId): params = {"Action": "GetPasswordData", "InstanceId": InstanceId} elem = self.connection.request(self.path, params=params).object # True Falseを受ける passwdData = findattr(element=elem, xpath="passwordData", namespace=NAMESPACE) if isEmpty(passwdData): # パスワードデータを取得できない場合 raise IaasException("EPROCESS-000133", [InstanceId]) return passwdData
def registerInstancesWithLoadBalancer(self, instances, loadBalancerName): params = {'Action': 'RegisterInstancesWithLoadBalancer', 'LoadBalancerName':loadBalancerName} for i, instance in enumerate(instances,1): params['Instances.member.%d.InstanceId' % i] = instance elem = self.connection.request(self.path, params=params).object instanceids = [] for rs in findall(element=elem, xpath='RegisterInstancesWithLoadBalancerResult/Instances/member', namespace=NAMESPACE): instanceids.append(findattr(element=rs, xpath="InstanceId", namespace=NAMESPACE)) return instanceids
def _to_subnetInfo(self, element): n = SubnetInfo( subnetId=findattr(element=element, xpath="subnetId", namespace=NAMESPACE), state=findattr(element=element, xpath="state", namespace=NAMESPACE), vpcId=findattr(element=element, xpath="vpcId", namespace=NAMESPACE), cidrBlock=findattr(element=element, xpath="cidrBlock", namespace=NAMESPACE), availableIpAddressCount=findattr(element=element, xpath="availableIpAddressCount", namespace=NAMESPACE), availabilityZone=findattr(element=element, xpath="availabilityZone", namespace=NAMESPACE), tagSet=findattr(element=element, xpath="tagSet", namespace=NAMESPACE), ) return n
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 allocateVpcAddress(self): params = {'Action': 'AllocateAddress', 'Domain': 'vpc'} elem = self.connection.request(self.path, params=params).object publicIp = findattr(element=elem, xpath="publicIp", namespace=NAMESPACE) # ログ出力 self.logger.info(None, "IPROCESS-100133", [ publicIp, ]) return publicIp
def _to_ipPermissions(self, element): ipRanges = [] for rs in findall(element=element, xpath='ipRanges/item', namespace=NAMESPACE): ipRanges.append( findattr(element=rs, xpath="cidrIp", namespace=NAMESPACE)) n = IpPermissions( ipProtocol=findattr(element=element, xpath="ipProtocol", namespace=NAMESPACE), fromPort=findattr(element=element, xpath="fromPort", namespace=NAMESPACE), toPort=findattr(element=element, xpath="toPort", namespace=NAMESPACE), groups=findattr(element=element, xpath="groups", namespace=NAMESPACE), ipRanges=ipRanges, ) return n
def getPasswordData(self, InstanceId): params = {'Action': 'GetPasswordData', 'InstanceId': InstanceId} elem = self.connection.request(self.path, params=params).object #True Falseを受ける passwdData = findattr(element=elem, xpath="passwordData", namespace=NAMESPACE) if isEmpty(passwdData): # パスワードデータを取得できない場合 raise IaasException("EPROCESS-000133", [ InstanceId, ]) return passwdData
def ex_describe_keypairs(self, name): """Describes a keypair by name @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 describe. """ params = {'Action': 'DescribeKeyPairs', 'KeyName.1': name} response = self.connection.request(self.path, params=params).object key_name = findattr(element=response, xpath='keySet/item/keyName', namespace=NAMESPACE) return {'keyName': key_name}
def _to_volume(self, element, attachmentSet=None, tags=None): v = Volume( volumeId=findattr(element=element, xpath="volumeId", namespace=NAMESPACE), size=findattr(element=element, xpath="size", namespace=NAMESPACE), snapshotId=findattr(element=element, xpath="snapshotId", namespace=NAMESPACE), availabilityZone=findattr(element=element, xpath="availabilityZone", namespace=NAMESPACE), status=findattr(element=element, xpath="status", namespace=NAMESPACE), createTime=findattr(element=element, xpath="createTime", namespace=NAMESPACE), attachmentSet=attachmentSet, tagSet=tags, ) return v
def _to_securityGroup(self, element): ipPermissions = [] for rs in findall(element=element, xpath="ipPermissions/item", namespace=NAMESPACE): ipPermissions.append(self._to_ipPermissions(rs)) n = SecurityGroup( ownerId=findattr(element=element, xpath="ownerId", namespace=NAMESPACE), groupId=findattr(element=element, xpath="groupId", namespace=NAMESPACE), groupName=findattr(element=element, xpath="groupName", namespace=NAMESPACE), groupDescription=findattr(element=element, xpath="groupDescription", namespace=NAMESPACE), vpcId=findattr(element=element, xpath="vpcId", namespace=NAMESPACE), ipPermissions=ipPermissions, ipPermissionsEgress=findattr(element=element, xpath="ipPermissionsEgress", namespace=NAMESPACE), tagSet=findattr(element=element, xpath="tagSet", namespace=NAMESPACE), ) return n
def describeInstances(self, instanceid=None): params = {"Action": "DescribeInstances"} # 任意パラメータ if instanceid != None: params.update({"InstanceId.0": instanceid}) elem = self.connection.request(self.path, params=params).object nodes = [] for rs in findall(element=elem, xpath="reservationSet/item", namespace=NAMESPACE): groups = [] for g in findall( element=rs, xpath="instancesSet/item/networkInterfaceSet/item/groupSet/item", namespace=NAMESPACE ): groups.append(findattr(element=g, xpath="groupId", namespace=NAMESPACE)) nodes += self._to_nodes(rs, "instancesSet/item", groups) nodes_elastic_ips_mappings = self.ex_describe_addresses(nodes) for node in nodes: node.public_ip.extend(nodes_elastic_ips_mappings[node.id]) return nodes
def ex_describe_keypairs(self, name): """Describes a keypair by name @note: This is a non-standard extension API, and only works for EC2. @param name: The name of the keypair to describe. @type name: C{str} @rtype: C{dict} """ params = { 'Action': 'DescribeKeyPairs', 'KeyName.1': name } response = self.connection.request(self.path, params=params).object key_name = findattr(element=response, xpath='keySet/item/keyName', namespace=NAMESPACE) return { 'keyName': key_name }
def _to_volume(self, element, attachmentSet=None, tags=None): v = Volume(volumeId=findattr(element=element, xpath="volumeId", namespace=NAMESPACE), size=findattr(element=element, xpath="size", namespace=NAMESPACE), snapshotId=findattr(element=element, xpath="snapshotId", namespace=NAMESPACE), availabilityZone=findattr(element=element, xpath="availabilityZone", namespace=NAMESPACE), status=findattr(element=element, xpath="status", namespace=NAMESPACE), createTime=findattr(element=element, xpath="createTime", namespace=NAMESPACE), attachmentSet=attachmentSet, tagSet=tags) return v
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
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
def _to_loadBalancerDescription(self, element): availabilityZones = [] for rs in findall(element=element, xpath='AvailabilityZones', namespace=NAMESPACE): availabilityZones.append(findattr(element=rs, xpath="member", namespace=NAMESPACE)) backendServerDescriptions = [] for rs in findall(element=element, xpath='BackendServerDescriptions/member', namespace=NAMESPACE): backendServerDescription = BackendServerDescription( instancePort = findattr(element=rs, xpath="InstancePort", namespace=NAMESPACE), policyNames = findattr(element=rs, xpath="PolicyNames", namespace=NAMESPACE), ) backendServerDescriptions.append(backendServerDescription) elmlist = findall(element=element, xpath='HealthCheck', namespace=NAMESPACE) healthCheckh = self._to_healthCheck(elmlist[0]) instances = [] for rs in findall(element=element, xpath='Instances/member', namespace=NAMESPACE): instances.append(findattr(element=rs, xpath="InstanceId ", namespace=NAMESPACE)) listenerDescriptions = [] for rs in findall(element=element, xpath='ListenerDescriptions/member', namespace=NAMESPACE): elmlist = findall(element=rs, xpath='Listener', namespace=NAMESPACE) listener = self._to_listener(elmlist[0]) if listener.protocol=='HTTPS' or listener.protocol=='SSL': listener.setSSLCertificateId(findattr(element=element, xpath="SSLCertificateId", namespace=NAMESPACE)) policyNames = [] for rs3 in findall(element=rs, xpath='PolicyNames/member', namespace=NAMESPACE): policyNames.append(findattr(element=rs3, xpath="name", namespace=NAMESPACE)) n = ListenerDescription(listener, policyNames) listenerDescriptions.append(n) appCookieStickinessPolicies = [] for rs in findall(element=element, xpath='Policies/AppCookieStickinessPolicies/member', namespace=NAMESPACE): appCookieStickinessPolicy = AppCookieStickinessPolicy( cookieName = findattr(element=rs, xpath="CookieName", namespace=NAMESPACE), policyName = findattr(element=rs, xpath="PolicyName", namespace=NAMESPACE), ) appCookieStickinessPolicies.append(appCookieStickinessPolicy) lbCookieStickinessPolicies = [] for rs in findall(element=element, xpath='Policies/LbCookieStickinessPolicy/member', namespace=NAMESPACE): lbCookieStickinessPolicy = LBCookieStickinessPolicy( cookieExpirationPeriod = findattr(element=rs, xpath="CookieExpirationPeriod ", namespace=NAMESPACE), policyName = findattr(element=rs, xpath="PolicyName", namespace=NAMESPACE), ) lbCookieStickinessPolicies.append(lbCookieStickinessPolicy) otherPolicies = [] for rs in findall(element=element, xpath='Policies/OtherPolicies', namespace=NAMESPACE): otherPolicies.append(findattr(element=element, xpath="member", namespace=NAMESPACE)) policies = Policies( appCookieStickinessPolicies = appCookieStickinessPolicies, lbCookieStickinessPolicies = lbCookieStickinessPolicies, otherPolicies = otherPolicies, ) sourceSecurityGroups = [] for rs in findall(element=element, xpath='SourceSecurityGroup', namespace=NAMESPACE): sourceSecurityGroup = SourceSecurityGroup( groupName = findattr(element=rs, xpath="GroupName", namespace=NAMESPACE), ownerAlias = findattr(element=rs, xpath="OwnerAlias", namespace=NAMESPACE), ) sourceSecurityGroups.append(sourceSecurityGroup) boadBalancerDescription = LoadBalancerDescription( availabilityZones = availabilityZones, backendServerDescriptions = backendServerDescriptions, canonicalHostedZoneName = findattr(element=element, xpath="CanonicalHostedZoneName", namespace=NAMESPACE), canonicalHostedZoneNameID = findattr(element=element, xpath="CanonicalHostedZoneNameID", namespace=NAMESPACE), createdTime = findattr(element=element, xpath="CreatedTime", namespace=NAMESPACE), dnsName = findattr(element=element, xpath="DNSName", namespace=NAMESPACE), healthCheck = healthCheckh, instances = instances, listenerDescriptions = listenerDescriptions, loadBalancerName = findattr(element=element, xpath="LoadBalancerName", namespace=NAMESPACE), policies = policies, sourceSecurityGroup = sourceSecurityGroups, ) return boadBalancerDescription