<s> from __future__ import with_statement <EOL> import sys <EOL> import base64 <EOL> import warnings <EOL> from libcloud . utils . py3 import b <EOL> from libcloud . utils . py3 import urlparse <EOL> from libcloud . compute . providers import Provider <EOL> from libcloud . common . cloudstack import CloudStackDriverMixIn <EOL> from libcloud . compute . base import Node , NodeDriver , NodeImage , NodeLocation <EOL> from libcloud . compute . base import NodeSize , StorageVolume , VolumeSnapshot <EOL> from libcloud . compute . base import KeyPair <EOL> from libcloud . compute . types import NodeState , LibcloudError <EOL> from libcloud . compute . types import KeyPairDoesNotExistError , StorageVolumeState <EOL> from libcloud . utils . networking import is_private_subnet <EOL> def transform_int_or_unlimited ( value ) : <EOL> try : <EOL> return int ( value ) <EOL> except ValueError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> if str ( value ) . lower ( ) == '<STR_LIT>' : <EOL> return - <NUM_LIT:1> <EOL> raise e <EOL> """<STR_LIT>""" <EOL> RESOURCE_EXTRA_ATTRIBUTES_MAP = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT:state>' : { <EOL> '<STR_LIT>' : '<STR_LIT:state>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT:type>' : { <EOL> '<STR_LIT>' : '<STR_LIT:type>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT:password>' : { <EOL> '<STR_LIT>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : list <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT:state>' : { <EOL> '<STR_LIT>' : '<STR_LIT:state>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT:type>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT:state>' : { <EOL> '<STR_LIT>' : '<STR_LIT:state>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT:state>' : { '<STR_LIT>' : '<STR_LIT:state>' , '<STR_LIT>' : str } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : str } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : list <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : bool <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : transform_int_or_unlimited <EOL> } , <EOL> '<STR_LIT:name>' : { <EOL> '<STR_LIT>' : '<STR_LIT:name>' , <EOL> '<STR_LIT>' : str <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str <EOL> } <EOL> } <EOL> } <EOL> class CloudStackNode ( Node ) : <EOL> """<STR_LIT>""" <EOL> def ex_allocate_public_ip ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_allocate_public_ip ( self ) <EOL> def ex_release_public_ip ( self , address ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_release_public_ip ( self , address ) <EOL> def ex_create_ip_forwarding_rule ( self , address , protocol , <EOL> start_port , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_create_ip_forwarding_rule ( node = self , <EOL> address = address , <EOL> protocol = protocol , <EOL> start_port = start_port , <EOL> end_port = end_port ) <EOL> def ex_create_port_forwarding_rule ( self , address , <EOL> private_port , public_port , <EOL> protocol , <EOL> public_end_port = None , <EOL> private_end_port = None , <EOL> openfirewall = True ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_create_port_forwarding_rule ( <EOL> node = self , address = address , private_port = private_port , <EOL> public_port = public_port , protocol = protocol , <EOL> public_end_port = public_end_port , private_end_port = private_end_port , <EOL> openfirewall = openfirewall ) <EOL> def ex_delete_ip_forwarding_rule ( self , rule ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_delete_ip_forwarding_rule ( node = self , rule = rule ) <EOL> def ex_delete_port_forwarding_rule ( self , rule ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_delete_port_forwarding_rule ( node = self , rule = rule ) <EOL> def ex_start ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_start ( node = self ) <EOL> def ex_stop ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . driver . ex_stop ( node = self ) <EOL> class CloudStackAddress ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , address , driver , associated_network_id = None , <EOL> vpc_id = None , virtualmachine_id = None ) : <EOL> self . id = id <EOL> self . address = address <EOL> self . driver = driver <EOL> self . associated_network_id = associated_network_id <EOL> self . vpc_id = vpc_id <EOL> self . virtualmachine_id = virtualmachine_id <EOL> def release ( self ) : <EOL> self . driver . ex_release_public_ip ( address = self ) <EOL> def __str__ ( self ) : <EOL> return self . address <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackFirewallRule ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , address , cidr_list , protocol , <EOL> icmp_code = None , icmp_type = None , <EOL> start_port = None , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = id <EOL> self . address = address <EOL> self . cidr_list = cidr_list <EOL> self . protocol = protocol <EOL> self . icmp_code = icmp_code <EOL> self . icmp_type = icmp_type <EOL> self . start_port = start_port <EOL> self . end_port = end_port <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackEgressFirewallRule ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , network_id , cidr_list , protocol , <EOL> icmp_code = None , icmp_type = None , <EOL> start_port = None , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = id <EOL> self . network_id = network_id <EOL> self . cidr_list = cidr_list <EOL> self . protocol = protocol <EOL> self . icmp_code = icmp_code <EOL> self . icmp_type = icmp_type <EOL> self . start_port = start_port <EOL> self . end_port = end_port <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackIPForwardingRule ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , node , id , address , protocol , start_port , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> self . node = node <EOL> self . id = id <EOL> self . address = address <EOL> self . protocol = protocol <EOL> self . start_port = start_port <EOL> self . end_port = end_port <EOL> def delete ( self ) : <EOL> self . node . ex_delete_ip_forwarding_rule ( rule = self ) <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackPortForwardingRule ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , node , rule_id , address , protocol , public_port , <EOL> private_port , public_end_port = None , private_end_port = None , <EOL> network_id = None ) : <EOL> """<STR_LIT>""" <EOL> self . node = node <EOL> self . id = rule_id <EOL> self . address = address <EOL> self . protocol = protocol <EOL> self . public_port = public_port <EOL> self . public_end_port = public_end_port <EOL> self . private_port = private_port <EOL> self . private_end_port = private_end_port <EOL> def delete ( self ) : <EOL> self . node . ex_delete_port_forwarding_rule ( rule = self ) <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackNetworkACLList ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , acl_id , name , vpc_id , driver , description = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = acl_id <EOL> self . name = name <EOL> self . vpc_id = vpc_id <EOL> self . driver = driver <EOL> self . description = description <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . name , self . vpc_id , <EOL> self . driver . name , self . description ) ) <EOL> class CloudStackNetworkACL ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , protocol , acl_id , action , cidr_list , <EOL> start_port , end_port , traffic_type = None ) : <EOL> """<STR_LIT>""" <EOL> self . id = id <EOL> self . protocol = protocol <EOL> self . acl_id = acl_id <EOL> self . action = action <EOL> self . cidr_list = cidr_list <EOL> self . start_port = start_port <EOL> self . end_port = end_port <EOL> self . traffic_type = traffic_type <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackDiskOffering ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , name , size , customizable ) : <EOL> self . id = id <EOL> self . name = name <EOL> self . size = size <EOL> self . customizable = customizable <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackNetwork ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , displaytext , name , networkofferingid , id , zoneid , <EOL> driver , extra = None ) : <EOL> self . displaytext = displaytext <EOL> self . name = name <EOL> self . networkofferingid = networkofferingid <EOL> self . id = id <EOL> self . zoneid = zoneid <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . displaytext , self . name , self . networkofferingid , <EOL> self . id , self . zoneid , self . driver . name ) ) <EOL> class CloudStackNetworkOffering ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , display_text , guest_ip_type , id , <EOL> service_offering_id , for_vpc , driver , extra = None ) : <EOL> self . display_text = display_text <EOL> self . name = name <EOL> self . guest_ip_type = guest_ip_type <EOL> self . id = id <EOL> self . service_offering_id = service_offering_id <EOL> self . for_vpc = for_vpc <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . name , self . display_text , <EOL> self . guest_ip_type , self . service_offering_id , self . for_vpc , <EOL> self . driver . name ) ) <EOL> class CloudStackNic ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , network_id , net_mask , gateway , ip_address , <EOL> is_default , mac_address , driver , extra = None ) : <EOL> self . id = id <EOL> self . network_id = network_id <EOL> self . net_mask = net_mask <EOL> self . gateway = gateway <EOL> self . ip_address = ip_address <EOL> self . is_default = is_default <EOL> self . mac_address = mac_address <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . network_id , self . net_mask , <EOL> self . gateway , self . ip_address , self . is_default , <EOL> self . mac_address , self . driver . name ) ) <EOL> def __eq__ ( self , other ) : <EOL> return self . __class__ is other . __class__ and self . id == other . id <EOL> class CloudStackVPC ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , vpc_offering_id , id , cidr , driver , <EOL> zone_id = None , display_text = None , extra = None ) : <EOL> self . display_text = display_text <EOL> self . name = name <EOL> self . vpc_offering_id = vpc_offering_id <EOL> self . id = id <EOL> self . zone_id = zone_id <EOL> self . cidr = cidr <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . name , self . vpc_offering_id , self . id , <EOL> self . cidr , self . driver . name , self . zone_id , <EOL> self . display_text ) ) <EOL> class CloudStackVPCOffering ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , display_text , id , <EOL> driver , extra = None ) : <EOL> self . name = name <EOL> self . display_text = display_text <EOL> self . id = id <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . name , self . display_text , self . id , <EOL> self . driver . name ) ) <EOL> class CloudStackVpnGateway ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , account , domain , domain_id , <EOL> public_ip , vpc_id , driver , extra = None ) : <EOL> self . id = id <EOL> self . account = account <EOL> self . domain = domain <EOL> self . domain_id = domain_id <EOL> self . public_ip = public_ip <EOL> self . vpc_id = vpc_id <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> @ property <EOL> def vpc ( self ) : <EOL> for vpc in self . driver . ex_list_vpcs ( ) : <EOL> if self . vpc_id == vpc . id : <EOL> return vpc <EOL> raise LibcloudError ( '<STR_LIT>' % self . vpc_id ) <EOL> def delete ( self ) : <EOL> return self . driver . ex_delete_vpn_gateway ( vpn_gateway = self ) <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . account , self . domain , self . domain_id , <EOL> self . id , self . public_ip , self . vpc_id , self . driver . name ) ) <EOL> class CloudStackVpnCustomerGateway ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , cidr_list , esp_policy , gateway , <EOL> ike_policy , ipsec_psk , driver , extra = None ) : <EOL> self . id = id <EOL> self . cidr_list = cidr_list <EOL> self . esp_policy = esp_policy <EOL> self . gateway = gateway <EOL> self . ike_policy = ike_policy <EOL> self . ipsec_psk = ipsec_psk <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def delete ( self ) : <EOL> return self . driver . ex_delete_vpn_customer_gateway ( <EOL> vpn_customer_gateway = self ) <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . cidr_list , self . esp_policy , self . gateway , <EOL> self . ike_policy , self . ipsec_psk , self . driver . name ) ) <EOL> class CloudStackVpnConnection ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , passive , vpn_customer_gateway_id , <EOL> vpn_gateway_id , state , driver , extra = None ) : <EOL> self . id = id <EOL> self . passive = passive <EOL> self . vpn_customer_gateway_id = vpn_customer_gateway_id <EOL> self . vpn_gateway_id = vpn_gateway_id <EOL> self . state = state <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> @ property <EOL> def vpn_customer_gateway ( self ) : <EOL> try : <EOL> return self . driver . ex_list_vpn_customer_gateways ( <EOL> id = self . vpn_customer_gateway_id ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> raise LibcloudError ( '<STR_LIT>' % <EOL> self . vpn_customer_gateway_id ) <EOL> @ property <EOL> def vpn_gateway ( self ) : <EOL> try : <EOL> return self . driver . ex_list_vpn_gateways ( id = self . vpn_gateway_id ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> raise LibcloudError ( '<STR_LIT>' % <EOL> self . vpn_gateway_id ) <EOL> def delete ( self ) : <EOL> return self . driver . ex_delete_vpn_connection ( vpn_connection = self ) <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . passive , self . vpn_customer_gateway_id , <EOL> self . vpn_gateway_id , self . state , self . driver . name ) ) <EOL> class CloudStackRouter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , name , state , public_ip , vpc_id , driver ) : <EOL> self . id = id <EOL> self . name = name <EOL> self . state = state <EOL> self . public_ip = public_ip <EOL> self . vpc_id = vpc_id <EOL> self . driver = driver <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . name , self . state , <EOL> self . public_ip , self . vpc_id , self . driver . name ) ) <EOL> class CloudStackProject ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , name , display_text , driver , extra = None ) : <EOL> self . id = id <EOL> self . name = name <EOL> self . display_text = display_text <EOL> self . driver = driver <EOL> self . extra = extra or { } <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % ( self . id , self . display_text , self . name , <EOL> self . driver . name ) ) <EOL> class CloudStackAffinityGroup ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , account , description , domain , domainid , name , <EOL> group_type , virtualmachine_ids ) : <EOL> """<STR_LIT>""" <EOL> self . id = id <EOL> self . account = account <EOL> self . description = description <EOL> self . domain = domain <EOL> self . domainid = domainid <EOL> self . name = name <EOL> self . type = group_type <EOL> self . virtualmachine_ids = virtualmachine_ids <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' ) <EOL> % ( self . id , self . name , self . type ) ) <EOL> class CloudStackAffinityGroupType ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , type_name ) : <EOL> """<STR_LIT>""" <EOL> self . type = type_name <EOL> def __repr__ ( self ) : <EOL> return ( ( '<STR_LIT>' ) % self . type ) <EOL> class CloudStackNodeDriver ( CloudStackDriverMixIn , NodeDriver ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> api_name = '<STR_LIT>' <EOL> website = '<STR_LIT>' <EOL> type = Provider . CLOUDSTACK <EOL> features = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> NODE_STATE_MAP = { <EOL> '<STR_LIT>' : NodeState . RUNNING , <EOL> '<STR_LIT>' : NodeState . REBOOTING , <EOL> '<STR_LIT>' : NodeState . STOPPED , <EOL> '<STR_LIT>' : NodeState . PENDING , <EOL> '<STR_LIT>' : NodeState . TERMINATED , <EOL> '<STR_LIT>' : NodeState . PENDING , <EOL> '<STR_LIT>' : NodeState . TERMINATED <EOL> } <EOL> VOLUME_STATE_MAP = { <EOL> '<STR_LIT>' : StorageVolumeState . CREATING , <EOL> '<STR_LIT>' : StorageVolumeState . DELETING , <EOL> '<STR_LIT>' : StorageVolumeState . DELETING , <EOL> '<STR_LIT>' : StorageVolumeState . DELETED , <EOL> '<STR_LIT>' : StorageVolumeState . DELETED , <EOL> '<STR_LIT>' : StorageVolumeState . AVAILABLE , <EOL> '<STR_LIT>' : StorageVolumeState . AVAILABLE , <EOL> '<STR_LIT>' : StorageVolumeState . BACKUP , <EOL> '<STR_LIT>' : StorageVolumeState . ERROR <EOL> } <EOL> def __init__ ( self , key , secret = None , secure = True , host = None , <EOL> path = None , port = None , url = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if url : <EOL> parsed = urlparse . urlparse ( url ) <EOL> path = parsed . path <EOL> scheme = parsed . scheme <EOL> split = parsed . netloc . split ( '<STR_LIT::>' ) <EOL> if len ( split ) == <NUM_LIT:1> : <EOL> host = parsed . netloc <EOL> port = <NUM_LIT> if scheme == '<STR_LIT>' else <NUM_LIT> <EOL> else : <EOL> host = split [ <NUM_LIT:0> ] <EOL> port = int ( split [ <NUM_LIT:1> ] ) <EOL> else : <EOL> host = host if host else self . host <EOL> path = path if path else self . path <EOL> if path is not None : <EOL> self . path = path <EOL> if host is not None : <EOL> self . host = host <EOL> if ( self . type == Provider . CLOUDSTACK ) and ( not host or not path ) : <EOL> raise Exception ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> super ( CloudStackNodeDriver , self ) . __init__ ( key = key , <EOL> secret = secret , <EOL> secure = secure , <EOL> host = host , <EOL> port = port ) <EOL> def list_images ( self , location = None ) : <EOL> args = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> if location is not None : <EOL> args [ '<STR_LIT>' ] = location . id <EOL> imgs = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> images = [ ] <EOL> for img in imgs . get ( '<STR_LIT>' , [ ] ) : <EOL> extra = { '<STR_LIT>' : img [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] } <EOL> size = img . get ( '<STR_LIT:size>' , None ) <EOL> if size is not None : <EOL> extra . update ( { '<STR_LIT:size>' : img [ '<STR_LIT:size>' ] } ) <EOL> images . append ( NodeImage ( <EOL> id = img [ '<STR_LIT:id>' ] , <EOL> name = img [ '<STR_LIT:name>' ] , <EOL> driver = self . connection . driver , <EOL> extra = extra ) ) <EOL> return images <EOL> def list_locations ( self ) : <EOL> """<STR_LIT>""" <EOL> locs = self . _sync_request ( '<STR_LIT>' ) <EOL> locations = [ ] <EOL> for loc in locs [ '<STR_LIT>' ] : <EOL> location = NodeLocation ( str ( loc [ '<STR_LIT:id>' ] ) , loc [ '<STR_LIT:name>' ] , '<STR_LIT>' , <EOL> self ) <EOL> locations . append ( location ) <EOL> return locations <EOL> def list_nodes ( self , project = None , location = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if project : <EOL> args [ '<STR_LIT>' ] = project . id <EOL> if location is not None : <EOL> args [ '<STR_LIT>' ] = location . id <EOL> vms = self . _sync_request ( '<STR_LIT>' , params = args ) <EOL> addrs = self . _sync_request ( '<STR_LIT>' , params = args ) <EOL> port_forwarding_rules = self . _sync_request ( '<STR_LIT>' ) <EOL> ip_forwarding_rules = self . _sync_request ( '<STR_LIT>' ) <EOL> public_ips_map = { } <EOL> for addr in addrs . get ( '<STR_LIT>' , [ ] ) : <EOL> if '<STR_LIT>' not in addr : <EOL> continue <EOL> vm_id = str ( addr [ '<STR_LIT>' ] ) <EOL> if vm_id not in public_ips_map : <EOL> public_ips_map [ vm_id ] = { } <EOL> public_ips_map [ vm_id ] [ addr [ '<STR_LIT>' ] ] = addr [ '<STR_LIT:id>' ] <EOL> nodes = [ ] <EOL> for vm in vms . get ( '<STR_LIT>' , [ ] ) : <EOL> public_ips = public_ips_map . get ( str ( vm [ '<STR_LIT:id>' ] ) , { } ) . keys ( ) <EOL> public_ips = list ( public_ips ) <EOL> node = self . _to_node ( data = vm , public_ips = public_ips ) <EOL> addresses = public_ips_map . get ( str ( vm [ '<STR_LIT:id>' ] ) , { } ) . items ( ) <EOL> addresses = [ CloudStackAddress ( id = address_id , address = address , <EOL> driver = node . driver ) for <EOL> address , address_id in addresses ] <EOL> node . extra [ '<STR_LIT>' ] = addresses <EOL> rules = [ ] <EOL> for addr in addresses : <EOL> for r in ip_forwarding_rules . get ( '<STR_LIT>' , [ ] ) : <EOL> if str ( r [ '<STR_LIT>' ] ) == node . id : <EOL> rule = CloudStackIPForwardingRule ( node , r [ '<STR_LIT:id>' ] , <EOL> addr , <EOL> r [ '<STR_LIT>' ] <EOL> . upper ( ) , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] ) <EOL> rules . append ( rule ) <EOL> node . extra [ '<STR_LIT>' ] = rules <EOL> rules = [ ] <EOL> for r in port_forwarding_rules . get ( '<STR_LIT>' , [ ] ) : <EOL> if str ( r [ '<STR_LIT>' ] ) == node . id : <EOL> addr = [ CloudStackAddress ( id = a [ '<STR_LIT:id>' ] , <EOL> address = a [ '<STR_LIT>' ] , <EOL> driver = node . driver ) <EOL> for a in addrs . get ( '<STR_LIT>' , [ ] ) <EOL> if a [ '<STR_LIT>' ] == r [ '<STR_LIT>' ] ] <EOL> rule = CloudStackPortForwardingRule ( node , r [ '<STR_LIT:id>' ] , <EOL> addr [ <NUM_LIT:0> ] , <EOL> r [ '<STR_LIT>' ] . upper ( ) , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] ) <EOL> if not addr [ <NUM_LIT:0> ] . address in node . public_ips : <EOL> node . public_ips . append ( addr [ <NUM_LIT:0> ] . address ) <EOL> rules . append ( rule ) <EOL> node . extra [ '<STR_LIT>' ] = rules <EOL> nodes . append ( node ) <EOL> return nodes <EOL> def ex_get_node ( self , node_id , project = None ) : <EOL> """<STR_LIT>""" <EOL> list_nodes_args = { '<STR_LIT:id>' : node_id } <EOL> list_ips_args = { } <EOL> if project : <EOL> list_nodes_args [ '<STR_LIT>' ] = project . id <EOL> list_ips_args [ '<STR_LIT>' ] = project . id <EOL> vms = self . _sync_request ( '<STR_LIT>' , params = list_nodes_args ) <EOL> if not vms : <EOL> raise Exception ( "<STR_LIT>" % node_id ) <EOL> vm = vms [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> addrs = self . _sync_request ( '<STR_LIT>' , <EOL> params = list_ips_args ) <EOL> public_ips = { } <EOL> for addr in addrs . get ( '<STR_LIT>' , [ ] ) : <EOL> if '<STR_LIT>' not in addr : <EOL> continue <EOL> public_ips [ addr [ '<STR_LIT>' ] ] = addr [ '<STR_LIT:id>' ] <EOL> node = self . _to_node ( data = vm , public_ips = list ( public_ips . keys ( ) ) ) <EOL> addresses = [ CloudStackAddress ( id = address_id , address = address , <EOL> driver = node . driver ) for <EOL> address , address_id in public_ips . items ( ) ] <EOL> node . extra [ '<STR_LIT>' ] = addresses <EOL> rules = [ ] <EOL> list_fw_rules = { '<STR_LIT>' : node_id } <EOL> for addr in addresses : <EOL> result = self . _sync_request ( '<STR_LIT>' , <EOL> params = list_fw_rules ) <EOL> for r in result . get ( '<STR_LIT>' , [ ] ) : <EOL> if str ( r [ '<STR_LIT>' ] ) == node . id : <EOL> rule = CloudStackIPForwardingRule ( node , r [ '<STR_LIT:id>' ] , <EOL> addr , <EOL> r [ '<STR_LIT>' ] <EOL> . upper ( ) , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] ) <EOL> rules . append ( rule ) <EOL> node . extra [ '<STR_LIT>' ] = rules <EOL> rules = [ ] <EOL> public_ips = self . ex_list_public_ips ( ) <EOL> result = self . _sync_request ( '<STR_LIT>' , <EOL> params = list_fw_rules ) <EOL> for r in result . get ( '<STR_LIT>' , [ ] ) : <EOL> if str ( r [ '<STR_LIT>' ] ) == node . id : <EOL> addr = [ a for a in public_ips if <EOL> a . address == r [ '<STR_LIT>' ] ] <EOL> rule = CloudStackPortForwardingRule ( node , r [ '<STR_LIT:id>' ] , <EOL> addr [ <NUM_LIT:0> ] , <EOL> r [ '<STR_LIT>' ] . upper ( ) , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] , <EOL> r [ '<STR_LIT>' ] ) <EOL> if not addr [ <NUM_LIT:0> ] . address in node . public_ips : <EOL> node . public_ips . append ( addr [ <NUM_LIT:0> ] . address ) <EOL> rules . append ( rule ) <EOL> node . extra [ '<STR_LIT>' ] = rules <EOL> return node <EOL> def list_sizes ( self , location = None ) : <EOL> """<STR_LIT>""" <EOL> szs = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> sizes = [ ] <EOL> for sz in szs [ '<STR_LIT>' ] : <EOL> extra = { '<STR_LIT>' : sz [ '<STR_LIT>' ] } <EOL> sizes . append ( NodeSize ( sz [ '<STR_LIT:id>' ] , sz [ '<STR_LIT:name>' ] , sz [ '<STR_LIT>' ] , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> <NUM_LIT:0> , self , extra = extra ) ) <EOL> return sizes <EOL> def create_node ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> server_params = self . _create_args_to_params ( None , ** kwargs ) <EOL> data = self . _async_request ( command = '<STR_LIT>' , <EOL> params = server_params , <EOL> method = '<STR_LIT:GET>' ) [ '<STR_LIT>' ] <EOL> node = self . _to_node ( data = data ) <EOL> return node <EOL> def _create_args_to_params ( self , node , ** kwargs ) : <EOL> server_params = { } <EOL> name = kwargs . get ( '<STR_LIT:name>' , None ) <EOL> size = kwargs . get ( '<STR_LIT:size>' , None ) <EOL> image = kwargs . get ( '<STR_LIT:image>' , None ) <EOL> location = kwargs . get ( '<STR_LIT:location>' , None ) <EOL> networks = kwargs . get ( '<STR_LIT>' , None ) <EOL> project = kwargs . get ( '<STR_LIT>' , None ) <EOL> diskoffering = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_key_name = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_user_data = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_security_groups = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_displayname = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_ip_address = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_start_vm = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_rootdisksize = kwargs . get ( '<STR_LIT>' , None ) <EOL> ex_affinity_groups = kwargs . get ( '<STR_LIT>' , None ) <EOL> if name : <EOL> server_params [ '<STR_LIT:name>' ] = name <EOL> if ex_displayname : <EOL> server_params [ '<STR_LIT>' ] = ex_displayname <EOL> if size : <EOL> server_params [ '<STR_LIT>' ] = size . id <EOL> if image : <EOL> server_params [ '<STR_LIT>' ] = image . id <EOL> if location : <EOL> server_params [ '<STR_LIT>' ] = location . id <EOL> else : <EOL> server_params [ '<STR_LIT>' ] = self . list_locations ( ) [ <NUM_LIT:0> ] . id <EOL> if networks : <EOL> networks = '<STR_LIT:U+002C>' . join ( [ str ( network . id ) for network in networks ] ) <EOL> server_params [ '<STR_LIT>' ] = networks <EOL> if project : <EOL> server_params [ '<STR_LIT>' ] = project . id <EOL> if diskoffering : <EOL> server_params [ '<STR_LIT>' ] = diskoffering . id <EOL> if ex_key_name : <EOL> server_params [ '<STR_LIT>' ] = ex_key_name <EOL> if ex_user_data : <EOL> ex_user_data = base64 . b64encode ( b ( ex_user_data ) . decode ( '<STR_LIT:ascii>' ) ) <EOL> server_params [ '<STR_LIT>' ] = ex_user_data <EOL> if ex_security_groups : <EOL> ex_security_groups = '<STR_LIT:U+002C>' . join ( ex_security_groups ) <EOL> server_params [ '<STR_LIT>' ] = ex_security_groups <EOL> if ex_ip_address : <EOL> server_params [ '<STR_LIT>' ] = ex_ip_address <EOL> if ex_rootdisksize : <EOL> server_params [ '<STR_LIT>' ] = ex_rootdisksize <EOL> if ex_start_vm is not None : <EOL> server_params [ '<STR_LIT>' ] = ex_start_vm <EOL> if ex_affinity_groups : <EOL> affinity_group_ids = '<STR_LIT:U+002C>' . join ( ag . id for ag in ex_affinity_groups ) <EOL> server_params [ '<STR_LIT>' ] = affinity_group_ids <EOL> return server_params <EOL> def destroy_node ( self , node , ex_expunge = False ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT:id>' : node . id , <EOL> } <EOL> if ex_expunge : <EOL> args [ '<STR_LIT>' ] = ex_expunge <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def reboot_node ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : node . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_start ( self , node ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : node . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT>' ] [ '<STR_LIT:state>' ] <EOL> def ex_stop ( self , node ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : node . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT>' ] [ '<STR_LIT:state>' ] <EOL> def ex_list_disk_offerings ( self ) : <EOL> """<STR_LIT>""" <EOL> diskOfferings = [ ] <EOL> diskOfferResponse = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> for diskOfferDict in diskOfferResponse . get ( '<STR_LIT>' , ( ) ) : <EOL> diskOfferings . append ( <EOL> CloudStackDiskOffering ( <EOL> id = diskOfferDict [ '<STR_LIT:id>' ] , <EOL> name = diskOfferDict [ '<STR_LIT:name>' ] , <EOL> size = diskOfferDict [ '<STR_LIT>' ] , <EOL> customizable = diskOfferDict [ '<STR_LIT>' ] ) ) <EOL> return diskOfferings <EOL> def ex_list_networks ( self , project = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if project is not None : <EOL> args [ '<STR_LIT>' ] = project . id <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> nets = res . get ( '<STR_LIT>' , [ ] ) <EOL> networks = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for net in nets : <EOL> extra = self . _get_extra_dict ( net , extra_map ) <EOL> if '<STR_LIT>' in net : <EOL> extra [ '<STR_LIT>' ] = self . _get_resource_tags ( net [ '<STR_LIT>' ] ) <EOL> networks . append ( CloudStackNetwork ( <EOL> net [ '<STR_LIT>' ] , <EOL> net [ '<STR_LIT:name>' ] , <EOL> net [ '<STR_LIT>' ] , <EOL> net [ '<STR_LIT:id>' ] , <EOL> net [ '<STR_LIT>' ] , <EOL> self , <EOL> extra = extra ) ) <EOL> return networks <EOL> def ex_list_network_offerings ( self ) : <EOL> """<STR_LIT>""" <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> netoffers = res . get ( '<STR_LIT>' , [ ] ) <EOL> networkofferings = [ ] <EOL> for netoffer in netoffers : <EOL> networkofferings . append ( CloudStackNetworkOffering ( <EOL> netoffer [ '<STR_LIT:name>' ] , <EOL> netoffer [ '<STR_LIT>' ] , <EOL> netoffer [ '<STR_LIT>' ] , <EOL> netoffer [ '<STR_LIT:id>' ] , <EOL> netoffer [ '<STR_LIT>' ] , <EOL> netoffer [ '<STR_LIT>' ] , <EOL> self ) ) <EOL> return networkofferings <EOL> def ex_create_network ( self , display_text , name , network_offering , <EOL> location , gateway = None , netmask = None , <EOL> network_domain = None , vpc_id = None , project_id = None ) : <EOL> """<STR_LIT>""" <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> args = { <EOL> '<STR_LIT>' : display_text , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : network_offering . id , <EOL> '<STR_LIT>' : location . id , <EOL> } <EOL> if gateway is not None : <EOL> args [ '<STR_LIT>' ] = gateway <EOL> if netmask is not None : <EOL> args [ '<STR_LIT>' ] = netmask <EOL> if network_domain is not None : <EOL> args [ '<STR_LIT>' ] = network_domain <EOL> if vpc_id is not None : <EOL> args [ '<STR_LIT>' ] = vpc_id <EOL> if project_id is not None : <EOL> args [ '<STR_LIT>' ] = project_id <EOL> """<STR_LIT>""" <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> result = result [ '<STR_LIT>' ] <EOL> extra = self . _get_extra_dict ( result , extra_map ) <EOL> network = CloudStackNetwork ( display_text , <EOL> name , <EOL> network_offering . id , <EOL> result [ '<STR_LIT:id>' ] , <EOL> location . id , <EOL> self , <EOL> extra = extra ) <EOL> return network <EOL> def ex_delete_network ( self , network , force = None ) : <EOL> """<STR_LIT>""" <EOL> args = { '<STR_LIT:id>' : network . id , '<STR_LIT>' : force } <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_list_vpc_offerings ( self ) : <EOL> """<STR_LIT>""" <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> vpcoffers = res . get ( '<STR_LIT>' , [ ] ) <EOL> vpcofferings = [ ] <EOL> for vpcoffer in vpcoffers : <EOL> vpcofferings . append ( CloudStackVPCOffering ( <EOL> vpcoffer [ '<STR_LIT:name>' ] , <EOL> vpcoffer [ '<STR_LIT>' ] , <EOL> vpcoffer [ '<STR_LIT:id>' ] , <EOL> self ) ) <EOL> return vpcofferings <EOL> def ex_list_vpcs ( self , project = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if project is not None : <EOL> args [ '<STR_LIT>' ] = project . id <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> vpcs = res . get ( '<STR_LIT>' , [ ] ) <EOL> networks = [ ] <EOL> for vpc in vpcs : <EOL> networks . append ( CloudStackVPC ( <EOL> vpc [ '<STR_LIT:name>' ] , <EOL> vpc [ '<STR_LIT>' ] , <EOL> vpc [ '<STR_LIT:id>' ] , <EOL> vpc [ '<STR_LIT>' ] , <EOL> self , <EOL> vpc [ '<STR_LIT>' ] , <EOL> vpc [ '<STR_LIT>' ] ) ) <EOL> return networks <EOL> def ex_list_routers ( self , vpc_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if vpc_id is not None : <EOL> args [ '<STR_LIT>' ] = vpc_id <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> rts = res . get ( '<STR_LIT>' , [ ] ) <EOL> routers = [ ] <EOL> for router in rts : <EOL> routers . append ( CloudStackRouter ( <EOL> router [ '<STR_LIT:id>' ] , <EOL> router [ '<STR_LIT:name>' ] , <EOL> router [ '<STR_LIT:state>' ] , <EOL> router [ '<STR_LIT>' ] , <EOL> router [ '<STR_LIT>' ] , <EOL> self ) ) <EOL> return routers <EOL> def ex_create_vpc ( self , cidr , display_text , name , vpc_offering , <EOL> zone_id , network_domain = None ) : <EOL> """<STR_LIT>""" <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> args = { <EOL> '<STR_LIT>' : cidr , <EOL> '<STR_LIT>' : display_text , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : vpc_offering . id , <EOL> '<STR_LIT>' : zone_id , <EOL> } <EOL> if network_domain is not None : <EOL> args [ '<STR_LIT>' ] = network_domain <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> extra = self . _get_extra_dict ( result , extra_map ) <EOL> vpc = CloudStackVPC ( name , <EOL> vpc_offering . id , <EOL> result [ '<STR_LIT:id>' ] , <EOL> cidr , <EOL> self , <EOL> zone_id , <EOL> display_text , <EOL> extra = extra ) <EOL> return vpc <EOL> def ex_delete_vpc ( self , vpc ) : <EOL> """<STR_LIT>""" <EOL> args = { '<STR_LIT:id>' : vpc . id } <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_list_projects ( self ) : <EOL> """<STR_LIT>""" <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> projs = res . get ( '<STR_LIT>' , [ ] ) <EOL> projects = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for proj in projs : <EOL> extra = self . _get_extra_dict ( proj , extra_map ) <EOL> if '<STR_LIT>' in proj : <EOL> extra [ '<STR_LIT>' ] = self . _get_resource_tags ( proj [ '<STR_LIT>' ] ) <EOL> projects . append ( CloudStackProject ( <EOL> id = proj [ '<STR_LIT:id>' ] , <EOL> name = proj [ '<STR_LIT:name>' ] , <EOL> display_text = proj [ '<STR_LIT>' ] , <EOL> driver = self , <EOL> extra = extra ) ) <EOL> return projects <EOL> def create_volume ( self , size , name , location = None , snapshot = None ) : <EOL> """<STR_LIT>""" <EOL> for diskOffering in self . ex_list_disk_offerings ( ) : <EOL> if diskOffering . size == size or diskOffering . customizable : <EOL> break <EOL> else : <EOL> raise LibcloudError ( <EOL> '<STR_LIT>' % size ) <EOL> if location is None : <EOL> location = self . list_locations ( ) [ <NUM_LIT:0> ] <EOL> params = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : diskOffering . id , <EOL> '<STR_LIT>' : location . id } <EOL> if diskOffering . customizable : <EOL> params [ '<STR_LIT:size>' ] = size <EOL> requestResult = self . _async_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> volumeResponse = requestResult [ '<STR_LIT>' ] <EOL> state = self . _to_volume_state ( volumeResponse ) <EOL> return StorageVolume ( id = volumeResponse [ '<STR_LIT:id>' ] , <EOL> name = name , <EOL> size = size , <EOL> state = state , <EOL> driver = self , <EOL> extra = dict ( name = volumeResponse [ '<STR_LIT:name>' ] ) ) <EOL> def destroy_volume ( self , volume ) : <EOL> """<STR_LIT>""" <EOL> self . _sync_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : volume . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def attach_volume ( self , node , volume , device = None ) : <EOL> """<STR_LIT>""" <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : volume . id , <EOL> '<STR_LIT>' : node . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def detach_volume ( self , volume ) : <EOL> """<STR_LIT>""" <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : volume . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def list_volumes ( self , node = None ) : <EOL> """<STR_LIT>""" <EOL> if node : <EOL> volumes = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : node . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> else : <EOL> volumes = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> list_volumes = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for vol in volumes . get ( '<STR_LIT>' , [ ] ) : <EOL> extra = self . _get_extra_dict ( vol , extra_map ) <EOL> if '<STR_LIT>' in vol : <EOL> extra [ '<STR_LIT>' ] = self . _get_resource_tags ( vol [ '<STR_LIT>' ] ) <EOL> state = self . _to_volume_state ( vol ) <EOL> list_volumes . append ( StorageVolume ( id = vol [ '<STR_LIT:id>' ] , <EOL> name = vol [ '<STR_LIT:name>' ] , <EOL> size = vol [ '<STR_LIT:size>' ] , <EOL> state = state , <EOL> driver = self , <EOL> extra = extra ) ) <EOL> return list_volumes <EOL> def ex_get_volume ( self , volume_id , project = None ) : <EOL> """<STR_LIT>""" <EOL> args = { '<STR_LIT:id>' : volume_id } <EOL> if project : <EOL> args [ '<STR_LIT>' ] = project . id <EOL> volumes = self . _sync_request ( command = '<STR_LIT>' , params = args ) <EOL> if not volumes : <EOL> raise Exception ( "<STR_LIT>" % volume_id ) <EOL> vol = volumes [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> extra = self . _get_extra_dict ( vol , extra_map ) <EOL> if '<STR_LIT>' in vol : <EOL> extra [ '<STR_LIT>' ] = self . _get_resource_tags ( vol [ '<STR_LIT>' ] ) <EOL> state = self . _to_volume_state ( vol ) <EOL> volume = StorageVolume ( id = vol [ '<STR_LIT:id>' ] , name = vol [ '<STR_LIT:name>' ] , state = state , <EOL> size = vol [ '<STR_LIT:size>' ] , driver = self , extra = extra ) <EOL> return volume <EOL> def list_key_pairs ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> extra_args = kwargs . copy ( ) <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = extra_args , <EOL> method = '<STR_LIT:GET>' ) <EOL> key_pairs = res . get ( '<STR_LIT>' , [ ] ) <EOL> key_pairs = self . _to_key_pairs ( data = key_pairs ) <EOL> return key_pairs <EOL> def get_key_pair ( self , name ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT:name>' : name } <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> key_pairs = res . get ( '<STR_LIT>' , [ ] ) <EOL> if len ( key_pairs ) == <NUM_LIT:0> : <EOL> raise KeyPairDoesNotExistError ( name = name , driver = self ) <EOL> key_pair = self . _to_key_pair ( data = key_pairs [ <NUM_LIT:0> ] ) <EOL> return key_pair <EOL> def create_key_pair ( self , name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> extra_args = kwargs . copy ( ) <EOL> params = { '<STR_LIT:name>' : name } <EOL> params . update ( extra_args ) <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> key_pair = self . _to_key_pair ( data = res [ '<STR_LIT>' ] ) <EOL> return key_pair <EOL> def import_key_pair_from_string ( self , name , key_material ) : <EOL> """<STR_LIT>""" <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : key_material } , <EOL> method = '<STR_LIT:GET>' ) <EOL> key_pair = self . _to_key_pair ( data = res [ '<STR_LIT>' ] ) <EOL> return key_pair <EOL> def delete_key_pair ( self , key_pair , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> extra_args = kwargs . copy ( ) <EOL> params = { '<STR_LIT:name>' : key_pair . name } <EOL> params . update ( extra_args ) <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] == '<STR_LIT:true>' <EOL> def ex_list_public_ips ( self ) : <EOL> """<STR_LIT>""" <EOL> ips = [ ] <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> if not res : <EOL> return ips <EOL> for ip in res [ '<STR_LIT>' ] : <EOL> ips . append ( CloudStackAddress ( ip [ '<STR_LIT:id>' ] , <EOL> ip [ '<STR_LIT>' ] , <EOL> self , <EOL> ip . get ( '<STR_LIT>' , [ ] ) , <EOL> ip . get ( '<STR_LIT>' ) , <EOL> ip . get ( '<STR_LIT>' ) ) ) <EOL> return ips <EOL> def ex_allocate_public_ip ( self , vpc_id = None , network_id = None , <EOL> location = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if location is not None : <EOL> args [ '<STR_LIT>' ] = location . id <EOL> else : <EOL> args [ '<STR_LIT>' ] = self . list_locations ( ) [ <NUM_LIT:0> ] . id <EOL> if vpc_id is not None : <EOL> args [ '<STR_LIT>' ] = vpc_id <EOL> if network_id is not None : <EOL> args [ '<STR_LIT>' ] = network_id <EOL> addr = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> addr = addr [ '<STR_LIT>' ] <EOL> addr = CloudStackAddress ( addr [ '<STR_LIT:id>' ] , addr [ '<STR_LIT>' ] , self ) <EOL> return addr <EOL> def ex_release_public_ip ( self , address ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : address . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def ex_list_firewall_rules ( self ) : <EOL> """<STR_LIT>""" <EOL> rules = [ ] <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> if result != { } : <EOL> public_ips = self . ex_list_public_ips ( ) <EOL> for rule in result [ '<STR_LIT>' ] : <EOL> addr = [ a for a in public_ips if <EOL> a . address == rule [ '<STR_LIT>' ] ] <EOL> rules . append ( CloudStackFirewallRule ( rule [ '<STR_LIT:id>' ] , <EOL> addr [ <NUM_LIT:0> ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule . get ( '<STR_LIT>' ) , <EOL> rule . get ( '<STR_LIT>' ) , <EOL> rule . get ( '<STR_LIT>' ) , <EOL> rule . get ( '<STR_LIT>' ) ) ) <EOL> return rules <EOL> def ex_create_firewall_rule ( self , address , cidr_list , protocol , <EOL> icmp_code = None , icmp_type = None , <EOL> start_port = None , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : address . id , <EOL> '<STR_LIT>' : cidr_list , <EOL> '<STR_LIT>' : protocol <EOL> } <EOL> if icmp_code is not None : <EOL> args [ '<STR_LIT>' ] = int ( icmp_code ) <EOL> if icmp_type is not None : <EOL> args [ '<STR_LIT>' ] = int ( icmp_type ) <EOL> if start_port is not None : <EOL> args [ '<STR_LIT>' ] = int ( start_port ) <EOL> if end_port is not None : <EOL> args [ '<STR_LIT>' ] = int ( end_port ) <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> rule = CloudStackFirewallRule ( result [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> address , <EOL> cidr_list , <EOL> protocol , <EOL> icmp_code , <EOL> icmp_type , <EOL> start_port , <EOL> end_port ) <EOL> return rule <EOL> def ex_delete_firewall_rule ( self , firewall_rule ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : firewall_rule . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def ex_list_egress_firewall_rules ( self ) : <EOL> """<STR_LIT>""" <EOL> rules = [ ] <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> for rule in result [ '<STR_LIT>' ] : <EOL> rules . append ( CloudStackEgressFirewallRule ( rule [ '<STR_LIT:id>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule . get ( '<STR_LIT>' ) , <EOL> rule . get ( '<STR_LIT>' ) , <EOL> rule . get ( '<STR_LIT>' ) , <EOL> rule . get ( '<STR_LIT>' ) ) ) <EOL> return rules <EOL> def ex_create_egress_firewall_rule ( self , network_id , cidr_list , protocol , <EOL> icmp_code = None , icmp_type = None , <EOL> start_port = None , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : network_id , <EOL> '<STR_LIT>' : cidr_list , <EOL> '<STR_LIT>' : protocol <EOL> } <EOL> if icmp_code is not None : <EOL> args [ '<STR_LIT>' ] = int ( icmp_code ) <EOL> if icmp_type is not None : <EOL> args [ '<STR_LIT>' ] = int ( icmp_type ) <EOL> if start_port is not None : <EOL> args [ '<STR_LIT>' ] = int ( start_port ) <EOL> if end_port is not None : <EOL> args [ '<STR_LIT>' ] = int ( end_port ) <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> rule = CloudStackEgressFirewallRule ( result [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> network_id , <EOL> cidr_list , <EOL> protocol , <EOL> icmp_code , <EOL> icmp_type , <EOL> start_port , <EOL> end_port ) <EOL> return rule <EOL> def ex_delete_egress_firewall_rule ( self , firewall_rule ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : firewall_rule . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def ex_list_port_forwarding_rules ( self , account = None , domain_id = None , <EOL> id = None , ipaddress_id = None , <EOL> is_recursive = None , keyword = None , <EOL> list_all = None , network_id = None , <EOL> page = None , page_size = None , <EOL> project_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if account is not None : <EOL> args [ '<STR_LIT>' ] = account <EOL> if domain_id is not None : <EOL> args [ '<STR_LIT>' ] = domain_id <EOL> if id is not None : <EOL> args [ '<STR_LIT:id>' ] = id <EOL> if ipaddress_id is not None : <EOL> args [ '<STR_LIT>' ] = ipaddress_id <EOL> if is_recursive is not None : <EOL> args [ '<STR_LIT>' ] = is_recursive <EOL> if keyword is not None : <EOL> args [ '<STR_LIT>' ] = keyword <EOL> if list_all is not None : <EOL> args [ '<STR_LIT>' ] = list_all <EOL> if network_id is not None : <EOL> args [ '<STR_LIT>' ] = network_id <EOL> if page is not None : <EOL> args [ '<STR_LIT>' ] = page <EOL> if page_size is not None : <EOL> args [ '<STR_LIT>' ] = page_size <EOL> if project_id is not None : <EOL> args [ '<STR_LIT>' ] = project_id <EOL> rules = [ ] <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> if result != { } : <EOL> public_ips = self . ex_list_public_ips ( ) <EOL> nodes = self . list_nodes ( ) <EOL> for rule in result [ '<STR_LIT>' ] : <EOL> node = [ n for n in nodes <EOL> if n . id == str ( rule [ '<STR_LIT>' ] ) ] <EOL> addr = [ a for a in public_ips if <EOL> a . address == rule [ '<STR_LIT>' ] ] <EOL> rules . append ( CloudStackPortForwardingRule <EOL> ( node [ <NUM_LIT:0> ] , <EOL> rule [ '<STR_LIT:id>' ] , <EOL> addr [ <NUM_LIT:0> ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] ) ) <EOL> return rules <EOL> def ex_create_port_forwarding_rule ( self , node , address , <EOL> private_port , public_port , <EOL> protocol , <EOL> public_end_port = None , <EOL> private_end_port = None , <EOL> openfirewall = True , <EOL> network_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : address . id , <EOL> '<STR_LIT>' : protocol , <EOL> '<STR_LIT>' : int ( private_port ) , <EOL> '<STR_LIT>' : int ( public_port ) , <EOL> '<STR_LIT>' : node . id , <EOL> '<STR_LIT>' : openfirewall <EOL> } <EOL> if public_end_port : <EOL> args [ '<STR_LIT>' ] = int ( public_end_port ) <EOL> if private_end_port : <EOL> args [ '<STR_LIT>' ] = int ( private_end_port ) <EOL> if network_id : <EOL> args [ '<STR_LIT>' ] = network_id <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> rule = CloudStackPortForwardingRule ( node , <EOL> result [ '<STR_LIT>' ] <EOL> [ '<STR_LIT:id>' ] , <EOL> address , <EOL> protocol , <EOL> public_port , <EOL> private_port , <EOL> public_end_port , <EOL> private_end_port , <EOL> network_id ) <EOL> node . extra [ '<STR_LIT>' ] . append ( rule ) <EOL> node . public_ips . append ( address . address ) <EOL> return rule <EOL> def ex_delete_port_forwarding_rule ( self , node , rule ) : <EOL> """<STR_LIT>""" <EOL> node . extra [ '<STR_LIT>' ] . remove ( rule ) <EOL> node . public_ips . remove ( rule . address . address ) <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : rule . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def ex_list_ip_forwarding_rules ( self , account = None , domain_id = None , <EOL> id = None , ipaddress_id = None , <EOL> is_recursive = None , keyword = None , <EOL> list_all = None , page = None , page_size = None , <EOL> project_id = None , virtualmachine_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if account is not None : <EOL> args [ '<STR_LIT>' ] = account <EOL> if domain_id is not None : <EOL> args [ '<STR_LIT>' ] = domain_id <EOL> if id is not None : <EOL> args [ '<STR_LIT:id>' ] = id <EOL> if ipaddress_id is not None : <EOL> args [ '<STR_LIT>' ] = ipaddress_id <EOL> if is_recursive is not None : <EOL> args [ '<STR_LIT>' ] = is_recursive <EOL> if keyword is not None : <EOL> args [ '<STR_LIT>' ] = keyword <EOL> if list_all is not None : <EOL> args [ '<STR_LIT>' ] = list_all <EOL> if page is not None : <EOL> args [ '<STR_LIT>' ] = page <EOL> if page_size is not None : <EOL> args [ '<STR_LIT>' ] = page_size <EOL> if project_id is not None : <EOL> args [ '<STR_LIT>' ] = project_id <EOL> if virtualmachine_id is not None : <EOL> args [ '<STR_LIT>' ] = virtualmachine_id <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> rules = [ ] <EOL> if result != { } : <EOL> public_ips = self . ex_list_public_ips ( ) <EOL> nodes = self . list_nodes ( ) <EOL> for rule in result [ '<STR_LIT>' ] : <EOL> node = [ n for n in nodes <EOL> if n . id == str ( rule [ '<STR_LIT>' ] ) ] <EOL> addr = [ a for a in public_ips if <EOL> a . address == rule [ '<STR_LIT>' ] ] <EOL> rules . append ( CloudStackIPForwardingRule <EOL> ( node [ <NUM_LIT:0> ] , <EOL> rule [ '<STR_LIT:id>' ] , <EOL> addr [ <NUM_LIT:0> ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] , <EOL> rule [ '<STR_LIT>' ] ) ) <EOL> return rules <EOL> def ex_create_ip_forwarding_rule ( self , node , address , protocol , <EOL> start_port , end_port = None ) : <EOL> """<STR_LIT>""" <EOL> protocol = protocol . upper ( ) <EOL> if protocol not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return None <EOL> args = { <EOL> '<STR_LIT>' : address . id , <EOL> '<STR_LIT>' : protocol , <EOL> '<STR_LIT>' : int ( start_port ) <EOL> } <EOL> if end_port is not None : <EOL> args [ '<STR_LIT>' ] = int ( end_port ) <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> result = result [ '<STR_LIT>' ] <EOL> rule = CloudStackIPForwardingRule ( node , result [ '<STR_LIT:id>' ] , address , <EOL> protocol , start_port , end_port ) <EOL> node . extra [ '<STR_LIT>' ] . append ( rule ) <EOL> return rule <EOL> def ex_delete_ip_forwarding_rule ( self , node , rule ) : <EOL> """<STR_LIT>""" <EOL> node . extra [ '<STR_LIT>' ] . remove ( rule ) <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : rule . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_create_network_acllist ( self , name , vpc_id , description = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : vpc_id <EOL> } <EOL> if description : <EOL> args [ '<STR_LIT:description>' ] = description <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> acl_list = CloudStackNetworkACLList ( result [ '<STR_LIT:id>' ] , <EOL> name , <EOL> vpc_id , <EOL> self , <EOL> description ) <EOL> return acl_list <EOL> def ex_create_network_acl ( self , protocol , acl_id , cidr_list , <EOL> start_port , end_port , action = None , <EOL> traffic_type = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : protocol , <EOL> '<STR_LIT>' : acl_id , <EOL> '<STR_LIT>' : cidr_list , <EOL> '<STR_LIT>' : start_port , <EOL> '<STR_LIT>' : end_port <EOL> } <EOL> if action : <EOL> args [ '<STR_LIT:action>' ] = action <EOL> else : <EOL> action = "<STR_LIT>" <EOL> if traffic_type : <EOL> args [ '<STR_LIT>' ] = traffic_type <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> acl = CloudStackNetworkACL ( result [ '<STR_LIT>' ] [ '<STR_LIT:id>' ] , <EOL> protocol , <EOL> acl_id , <EOL> action , <EOL> cidr_list , <EOL> start_port , <EOL> end_port , <EOL> traffic_type ) <EOL> return acl <EOL> def ex_list_network_acllists ( self ) : <EOL> """<STR_LIT>""" <EOL> acllists = [ ] <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> if not result : <EOL> return acllists <EOL> for acllist in result [ '<STR_LIT>' ] : <EOL> acllists . append ( CloudStackNetworkACLList ( acllist [ '<STR_LIT:id>' ] , <EOL> acllist [ '<STR_LIT:name>' ] , <EOL> acllist . get ( '<STR_LIT>' , [ ] ) , <EOL> self , <EOL> acllist [ '<STR_LIT:description>' ] ) ) <EOL> return acllists <EOL> def ex_replace_network_acllist ( self , acl_id , network_id ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : acl_id , <EOL> '<STR_LIT>' : network_id <EOL> } <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_list_network_acl ( self ) : <EOL> """<STR_LIT>""" <EOL> acls = [ ] <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> if not result : <EOL> return acls <EOL> for acl in result [ '<STR_LIT>' ] : <EOL> acls . append ( CloudStackNetworkACL ( acl [ '<STR_LIT:id>' ] , <EOL> acl [ '<STR_LIT>' ] , <EOL> acl [ '<STR_LIT>' ] , <EOL> acl [ '<STR_LIT:action>' ] , <EOL> acl [ '<STR_LIT>' ] , <EOL> acl . get ( '<STR_LIT>' , [ ] ) , <EOL> acl . get ( '<STR_LIT>' , [ ] ) , <EOL> acl [ '<STR_LIT>' ] ) ) <EOL> return acls <EOL> def ex_list_keypairs ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> key_pairs = self . list_key_pairs ( ** kwargs ) <EOL> result = [ ] <EOL> for key_pair in key_pairs : <EOL> item = { <EOL> '<STR_LIT:name>' : key_pair . name , <EOL> '<STR_LIT>' : key_pair . fingerprint , <EOL> '<STR_LIT>' : key_pair . private_key <EOL> } <EOL> result . append ( item ) <EOL> return result <EOL> def ex_create_keypair ( self , name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> key_pair = self . create_key_pair ( name = name , ** kwargs ) <EOL> result = { <EOL> '<STR_LIT:name>' : key_pair . name , <EOL> '<STR_LIT>' : key_pair . fingerprint , <EOL> '<STR_LIT>' : key_pair . private_key <EOL> } <EOL> return result <EOL> def ex_import_keypair_from_string ( self , name , key_material ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> key_pair = self . import_key_pair_from_string ( name = name , <EOL> key_material = key_material ) <EOL> result = { <EOL> '<STR_LIT>' : key_pair . name , <EOL> '<STR_LIT>' : key_pair . fingerprint <EOL> } <EOL> return result <EOL> def ex_import_keypair ( self , name , keyfile ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> key_pair = self . import_key_pair_from_file ( name = name , <EOL> key_file_path = keyfile ) <EOL> result = { <EOL> '<STR_LIT>' : key_pair . name , <EOL> '<STR_LIT>' : key_pair . fingerprint <EOL> } <EOL> return result <EOL> def ex_delete_keypair ( self , keypair , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> warnings . warn ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> key_pair = KeyPair ( name = keypair , public_key = None , fingerprint = None , <EOL> driver = self ) <EOL> return self . delete_key_pair ( key_pair = key_pair ) <EOL> def ex_list_security_groups ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> extra_args = kwargs . copy ( ) <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = extra_args , <EOL> method = '<STR_LIT:GET>' ) <EOL> security_groups = res . get ( '<STR_LIT>' , [ ] ) <EOL> return security_groups <EOL> def ex_create_security_group ( self , name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> extra_args = kwargs . copy ( ) <EOL> for sg in self . ex_list_security_groups ( ) : <EOL> if name in sg [ '<STR_LIT:name>' ] : <EOL> raise LibcloudError ( '<STR_LIT>' ) <EOL> params = { '<STR_LIT:name>' : name } <EOL> params . update ( extra_args ) <EOL> return self . _sync_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) [ '<STR_LIT>' ] <EOL> def ex_delete_security_group ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . _sync_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:name>' : name } , <EOL> method = '<STR_LIT:GET>' ) [ '<STR_LIT:success>' ] <EOL> def ex_authorize_security_group_ingress ( self , securitygroupname , protocol , <EOL> cidrlist , startport = None , <EOL> endport = None , icmptype = None , <EOL> icmpcode = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> args = kwargs . copy ( ) <EOL> protocol = protocol . upper ( ) <EOL> args . update ( { <EOL> '<STR_LIT>' : securitygroupname , <EOL> '<STR_LIT>' : protocol , <EOL> '<STR_LIT>' : cidrlist <EOL> } ) <EOL> if protocol not in ( '<STR_LIT>' , '<STR_LIT>' ) and ( startport is not None or endport is not None ) : <EOL> raise LibcloudError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if protocol != '<STR_LIT>' and ( icmptype is not None or icmpcode is not None ) : <EOL> raise LibcloudError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if protocol in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if startport is None : <EOL> raise LibcloudError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if startport is not None and endport is None : <EOL> endport = startport <EOL> args . update ( { <EOL> '<STR_LIT>' : startport , <EOL> '<STR_LIT>' : endport <EOL> } ) <EOL> if protocol == '<STR_LIT>' : <EOL> if icmptype is None : <EOL> icmptype = - <NUM_LIT:1> <EOL> if icmpcode is None : <EOL> icmpcode = - <NUM_LIT:1> <EOL> args . update ( { <EOL> '<STR_LIT>' : icmptype , <EOL> '<STR_LIT>' : icmpcode <EOL> } ) <EOL> return self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) [ '<STR_LIT>' ] <EOL> def ex_revoke_security_group_ingress ( self , rule_id ) : <EOL> """<STR_LIT>""" <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : rule_id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_create_affinity_group ( self , name , group_type ) : <EOL> """<STR_LIT>""" <EOL> for ag in self . ex_list_affinity_groups ( ) : <EOL> if name == ag . name : <EOL> raise LibcloudError ( '<STR_LIT>' ) <EOL> params = { '<STR_LIT:name>' : name , '<STR_LIT:type>' : group_type . type } <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> return self . _to_affinity_group ( result [ '<STR_LIT>' ] ) <EOL> def ex_delete_affinity_group ( self , affinity_group ) : <EOL> """<STR_LIT>""" <EOL> return self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : affinity_group . id } , <EOL> method = '<STR_LIT:GET>' ) [ '<STR_LIT:success>' ] <EOL> def ex_update_node_affinity_group ( self , node , affinity_group_list ) : <EOL> """<STR_LIT>""" <EOL> affinity_groups = '<STR_LIT:U+002C>' . join ( ag . id for ag in affinity_group_list ) <EOL> result = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { <EOL> '<STR_LIT:id>' : node . id , <EOL> '<STR_LIT>' : affinity_groups } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return self . _to_node ( data = result [ '<STR_LIT>' ] ) <EOL> def ex_list_affinity_groups ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . _sync_request ( command = '<STR_LIT>' , method = '<STR_LIT:GET>' ) <EOL> if not result . get ( '<STR_LIT:count>' ) : <EOL> return [ ] <EOL> affinity_groups = [ ] <EOL> for ag in result [ '<STR_LIT>' ] : <EOL> affinity_groups . append ( self . _to_affinity_group ( ag ) ) <EOL> return affinity_groups <EOL> def ex_list_affinity_group_types ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> if not result . get ( '<STR_LIT:count>' ) : <EOL> return [ ] <EOL> affinity_group_types = [ ] <EOL> for agt in result [ '<STR_LIT>' ] : <EOL> affinity_group_types . append ( <EOL> CloudStackAffinityGroupType ( agt [ '<STR_LIT:type>' ] ) ) <EOL> return affinity_group_types <EOL> def ex_register_iso ( self , name , url , location = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if location is None : <EOL> location = self . list_locations ( ) [ <NUM_LIT:0> ] <EOL> params = { '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : name , <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : location . id } <EOL> params [ '<STR_LIT>' ] = kwargs . pop ( '<STR_LIT>' , False ) <EOL> if params [ '<STR_LIT>' ] : <EOL> os_type_id = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if not os_type_id : <EOL> raise LibcloudError ( '<STR_LIT>' ) <EOL> params [ '<STR_LIT>' ] = os_type_id <EOL> return self . _sync_request ( command = '<STR_LIT>' , <EOL> name = name , <EOL> displaytext = name , <EOL> url = url , <EOL> zoneid = location . id , <EOL> params = params ) <EOL> def ex_limits ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . _sync_request ( command = '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> limits = { } <EOL> resource_map = { <EOL> <NUM_LIT:0> : '<STR_LIT>' , <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' , <EOL> <NUM_LIT:3> : '<STR_LIT>' , <EOL> <NUM_LIT:4> : '<STR_LIT>' , <EOL> <NUM_LIT:5> : '<STR_LIT>' , <EOL> <NUM_LIT:6> : '<STR_LIT>' , <EOL> <NUM_LIT:7> : '<STR_LIT>' , <EOL> <NUM_LIT:8> : '<STR_LIT>' , <EOL> <NUM_LIT:9> : '<STR_LIT>' , <EOL> <NUM_LIT:10> : '<STR_LIT>' , <EOL> <NUM_LIT:11> : '<STR_LIT>' <EOL> } <EOL> for limit in result . get ( '<STR_LIT>' , [ ] ) : <EOL> resource = resource_map . get ( int ( limit [ '<STR_LIT>' ] ) , None ) <EOL> if not resource : <EOL> continue <EOL> limits [ resource ] = int ( limit [ '<STR_LIT>' ] ) <EOL> return limits <EOL> def ex_create_tags ( self , resource_ids , resource_type , tags ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : resource_type , <EOL> '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( resource_ids ) } <EOL> for i , key in enumerate ( tags ) : <EOL> params [ '<STR_LIT>' % i ] = key <EOL> params [ '<STR_LIT>' % i ] = tags [ key ] <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_delete_tags ( self , resource_ids , resource_type , tag_keys ) : <EOL> """<STR_LIT>""" <EOL> params = { '<STR_LIT>' : resource_type , <EOL> '<STR_LIT>' : '<STR_LIT:U+002C>' . join ( resource_ids ) } <EOL> for i , key in enumerate ( tag_keys ) : <EOL> params [ '<STR_LIT>' % i ] = key <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = params , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def list_snapshots ( self ) : <EOL> """<STR_LIT>""" <EOL> snapshots = self . _sync_request ( '<STR_LIT>' , <EOL> method = '<STR_LIT:GET>' ) <EOL> list_snapshots = [ ] <EOL> for snap in snapshots [ '<STR_LIT>' ] : <EOL> list_snapshots . append ( self . _to_snapshot ( snap ) ) <EOL> return list_snapshots <EOL> def create_volume_snapshot ( self , volume , name = None ) : <EOL> """<STR_LIT>""" <EOL> snapshot = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : volume . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return self . _to_snapshot ( snapshot [ '<STR_LIT>' ] ) <EOL> def destroy_volume_snapshot ( self , snapshot ) : <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : snapshot . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return True <EOL> def ex_create_snapshot_template ( self , snapshot , name , ostypeid , <EOL> displaytext = None ) : <EOL> """<STR_LIT>""" <EOL> if not displaytext : <EOL> displaytext = name <EOL> resp = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { <EOL> '<STR_LIT>' : displaytext , <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : ostypeid , <EOL> '<STR_LIT>' : snapshot . id } ) <EOL> img = resp . get ( '<STR_LIT>' ) <EOL> extra = { <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : img [ '<STR_LIT>' ] <EOL> } <EOL> return NodeImage ( id = img [ '<STR_LIT:id>' ] , <EOL> name = img [ '<STR_LIT:name>' ] , <EOL> driver = self . connection . driver , <EOL> extra = extra ) <EOL> def ex_list_os_types ( self ) : <EOL> """<STR_LIT>""" <EOL> ostypes = self . _sync_request ( '<STR_LIT>' ) <EOL> return ostypes [ '<STR_LIT>' ] <EOL> def ex_list_nics ( self , node ) : <EOL> """<STR_LIT>""" <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : node . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> items = res . get ( '<STR_LIT>' , [ ] ) <EOL> nics = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for item in items : <EOL> extra = self . _get_extra_dict ( item , extra_map ) <EOL> nics . append ( CloudStackNic ( <EOL> id = item [ '<STR_LIT:id>' ] , <EOL> network_id = item [ '<STR_LIT>' ] , <EOL> net_mask = item [ '<STR_LIT>' ] , <EOL> gateway = item [ '<STR_LIT>' ] , <EOL> ip_address = item [ '<STR_LIT>' ] , <EOL> is_default = item [ '<STR_LIT>' ] , <EOL> mac_address = item [ '<STR_LIT>' ] , <EOL> driver = self , <EOL> extra = extra ) ) <EOL> return nics <EOL> def ex_attach_nic_to_node ( self , node , network , ip_address = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : node . id , <EOL> '<STR_LIT>' : network . id <EOL> } <EOL> if ip_address is not None : <EOL> args [ '<STR_LIT>' ] = ip_address <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = args ) <EOL> return True <EOL> def ex_detach_nic_from_node ( self , nic , node ) : <EOL> """<STR_LIT>""" <EOL> self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT>' : nic . id , <EOL> '<STR_LIT>' : node . id } ) <EOL> return True <EOL> def ex_list_vpn_gateways ( self , account = None , domain_id = None , <EOL> for_display = None , id = None , is_recursive = None , <EOL> keyword = None , list_all = None , page = None , <EOL> page_size = None , project_id = None , vpc_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if account is not None : <EOL> args [ '<STR_LIT>' ] = account <EOL> if domain_id is not None : <EOL> args [ '<STR_LIT>' ] = domain_id <EOL> if for_display is not None : <EOL> args [ '<STR_LIT>' ] = for_display <EOL> if id is not None : <EOL> args [ '<STR_LIT:id>' ] = id <EOL> if is_recursive is not None : <EOL> args [ '<STR_LIT>' ] = is_recursive <EOL> if keyword is not None : <EOL> args [ '<STR_LIT>' ] = keyword <EOL> if list_all is not None : <EOL> args [ '<STR_LIT>' ] = list_all <EOL> if page is not None : <EOL> args [ '<STR_LIT>' ] = page <EOL> if page_size is not None : <EOL> args [ '<STR_LIT>' ] = page_size <EOL> if project_id is not None : <EOL> args [ '<STR_LIT>' ] = project_id <EOL> if vpc_id is not None : <EOL> args [ '<STR_LIT>' ] = vpc_id <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> items = res . get ( '<STR_LIT>' , [ ] ) <EOL> vpn_gateways = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for item in items : <EOL> extra = self . _get_extra_dict ( item , extra_map ) <EOL> vpn_gateways . append ( CloudStackVpnGateway ( <EOL> id = item [ '<STR_LIT:id>' ] , <EOL> account = item [ '<STR_LIT>' ] , <EOL> domain = item [ '<STR_LIT>' ] , <EOL> domain_id = item [ '<STR_LIT>' ] , <EOL> public_ip = item [ '<STR_LIT>' ] , <EOL> vpc_id = item [ '<STR_LIT>' ] , <EOL> driver = self , <EOL> extra = extra ) ) <EOL> return vpn_gateways <EOL> def ex_create_vpn_gateway ( self , vpc , for_display = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : vpc . id , <EOL> } <EOL> if for_display is not None : <EOL> args [ '<STR_LIT>' ] = for_display <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> item = res [ '<STR_LIT>' ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> return CloudStackVpnGateway ( id = item [ '<STR_LIT:id>' ] , <EOL> account = item [ '<STR_LIT>' ] , <EOL> domain = item [ '<STR_LIT>' ] , <EOL> domain_id = item [ '<STR_LIT>' ] , <EOL> public_ip = item [ '<STR_LIT>' ] , <EOL> vpc_id = vpc . id , <EOL> driver = self , <EOL> extra = self . _get_extra_dict ( item , <EOL> extra_map ) ) <EOL> def ex_delete_vpn_gateway ( self , vpn_gateway ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : vpn_gateway . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def ex_list_vpn_customer_gateways ( self , account = None , domain_id = None , <EOL> id = None , is_recursive = None , <EOL> keyword = None , list_all = None , <EOL> page = None , page_size = None , <EOL> project_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if account is not None : <EOL> args [ '<STR_LIT>' ] = account <EOL> if domain_id is not None : <EOL> args [ '<STR_LIT>' ] = domain_id <EOL> if id is not None : <EOL> args [ '<STR_LIT:id>' ] = id <EOL> if is_recursive is not None : <EOL> args [ '<STR_LIT>' ] = is_recursive <EOL> if keyword is not None : <EOL> args [ '<STR_LIT>' ] = keyword <EOL> if list_all is not None : <EOL> args [ '<STR_LIT>' ] = list_all <EOL> if page is not None : <EOL> args [ '<STR_LIT>' ] = page <EOL> if page_size is not None : <EOL> args [ '<STR_LIT>' ] = page_size <EOL> if project_id is not None : <EOL> args [ '<STR_LIT>' ] = project_id <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> items = res . get ( '<STR_LIT>' , [ ] ) <EOL> vpn_customer_gateways = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for item in items : <EOL> extra = self . _get_extra_dict ( item , extra_map ) <EOL> vpn_customer_gateways . append ( CloudStackVpnCustomerGateway ( <EOL> id = item [ '<STR_LIT:id>' ] , <EOL> cidr_list = item [ '<STR_LIT>' ] , <EOL> esp_policy = item [ '<STR_LIT>' ] , <EOL> gateway = item [ '<STR_LIT>' ] , <EOL> ike_policy = item [ '<STR_LIT>' ] , <EOL> ipsec_psk = item [ '<STR_LIT>' ] , <EOL> driver = self , <EOL> extra = extra ) ) <EOL> return vpn_customer_gateways <EOL> def ex_create_vpn_customer_gateway ( self , cidr_list , esp_policy , gateway , <EOL> ike_policy , ipsec_psk , account = None , <EOL> domain_id = None , dpd = None , <EOL> esp_lifetime = None , ike_lifetime = None , <EOL> name = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : cidr_list , <EOL> '<STR_LIT>' : esp_policy , <EOL> '<STR_LIT>' : gateway , <EOL> '<STR_LIT>' : ike_policy , <EOL> '<STR_LIT>' : ipsec_psk <EOL> } <EOL> if account is not None : <EOL> args [ '<STR_LIT>' ] = account <EOL> if domain_id is not None : <EOL> args [ '<STR_LIT>' ] = domain_id <EOL> if dpd is not None : <EOL> args [ '<STR_LIT>' ] = dpd <EOL> if esp_lifetime is not None : <EOL> args [ '<STR_LIT>' ] = esp_lifetime <EOL> if ike_lifetime is not None : <EOL> args [ '<STR_LIT>' ] = ike_lifetime <EOL> if name is not None : <EOL> args [ '<STR_LIT:name>' ] = name <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> item = res [ '<STR_LIT>' ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> return CloudStackVpnCustomerGateway ( id = item [ '<STR_LIT:id>' ] , <EOL> cidr_list = cidr_list , <EOL> esp_policy = esp_policy , <EOL> gateway = gateway , <EOL> ike_policy = ike_policy , <EOL> ipsec_psk = ipsec_psk , <EOL> driver = self , <EOL> extra = self . _get_extra_dict ( <EOL> item , extra_map ) ) <EOL> def ex_delete_vpn_customer_gateway ( self , vpn_customer_gateway ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : vpn_customer_gateway . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def ex_list_vpn_connections ( self , account = None , domain_id = None , <EOL> for_display = None , id = None , is_recursive = None , <EOL> keyword = None , list_all = None , page = None , <EOL> page_size = None , project_id = None , vpc_id = None ) : <EOL> """<STR_LIT>""" <EOL> args = { } <EOL> if account is not None : <EOL> args [ '<STR_LIT>' ] = account <EOL> if domain_id is not None : <EOL> args [ '<STR_LIT>' ] = domain_id <EOL> if for_display is not None : <EOL> args [ '<STR_LIT>' ] = for_display <EOL> if id is not None : <EOL> args [ '<STR_LIT:id>' ] = id <EOL> if is_recursive is not None : <EOL> args [ '<STR_LIT>' ] = is_recursive <EOL> if keyword is not None : <EOL> args [ '<STR_LIT>' ] = keyword <EOL> if list_all is not None : <EOL> args [ '<STR_LIT>' ] = list_all <EOL> if page is not None : <EOL> args [ '<STR_LIT>' ] = page <EOL> if page_size is not None : <EOL> args [ '<STR_LIT>' ] = page_size <EOL> if project_id is not None : <EOL> args [ '<STR_LIT>' ] = project_id <EOL> if vpc_id is not None : <EOL> args [ '<STR_LIT>' ] = vpc_id <EOL> res = self . _sync_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> items = res . get ( '<STR_LIT>' , [ ] ) <EOL> vpn_connections = [ ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> for item in items : <EOL> extra = self . _get_extra_dict ( item , extra_map ) <EOL> vpn_connections . append ( CloudStackVpnConnection ( <EOL> id = item [ '<STR_LIT:id>' ] , <EOL> passive = item [ '<STR_LIT>' ] , <EOL> vpn_customer_gateway_id = item [ '<STR_LIT>' ] , <EOL> vpn_gateway_id = item [ '<STR_LIT>' ] , <EOL> state = item [ '<STR_LIT:state>' ] , <EOL> driver = self , <EOL> extra = extra ) ) <EOL> return vpn_connections <EOL> def ex_create_vpn_connection ( self , vpn_customer_gateway , vpn_gateway , <EOL> for_display = None , passive = None ) : <EOL> """<STR_LIT>""" <EOL> args = { <EOL> '<STR_LIT>' : vpn_customer_gateway . id , <EOL> '<STR_LIT>' : vpn_gateway . id , <EOL> } <EOL> if for_display is not None : <EOL> args [ '<STR_LIT>' ] = for_display <EOL> if passive is not None : <EOL> args [ '<STR_LIT>' ] = passive <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = args , <EOL> method = '<STR_LIT:GET>' ) <EOL> item = res [ '<STR_LIT>' ] <EOL> extra_map = RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] <EOL> return CloudStackVpnConnection ( <EOL> id = item [ '<STR_LIT:id>' ] , <EOL> passive = item [ '<STR_LIT>' ] , <EOL> vpn_customer_gateway_id = vpn_customer_gateway . id , <EOL> vpn_gateway_id = vpn_gateway . id , <EOL> state = item [ '<STR_LIT:state>' ] , <EOL> driver = self , <EOL> extra = self . _get_extra_dict ( item , extra_map ) ) <EOL> def ex_delete_vpn_connection ( self , vpn_connection ) : <EOL> """<STR_LIT>""" <EOL> res = self . _async_request ( command = '<STR_LIT>' , <EOL> params = { '<STR_LIT:id>' : vpn_connection . id } , <EOL> method = '<STR_LIT:GET>' ) <EOL> return res [ '<STR_LIT:success>' ] <EOL> def _to_snapshot ( self , data ) : <EOL> """<STR_LIT>""" <EOL> extra = { <EOL> '<STR_LIT>' : data . get ( '<STR_LIT>' , None ) , <EOL> '<STR_LIT:name>' : data . get ( '<STR_LIT:name>' , None ) , <EOL> '<STR_LIT>' : data . get ( '<STR_LIT>' , None ) , <EOL> } <EOL> return VolumeSnapshot ( data [ '<STR_LIT:id>' ] , driver = self , extra = extra ) <EOL> def _to_node ( self , data , public_ips = None ) : <EOL> """<STR_LIT>""" <EOL> id = data [ '<STR_LIT:id>' ] <EOL> if '<STR_LIT:name>' in data : <EOL> name = data [ '<STR_LIT:name>' ] <EOL> elif '<STR_LIT>' in data : <EOL> name = data [ '<STR_LIT>' ] <EOL> else : <EOL> name = None <EOL> state = self . NODE_STATE_MAP [ data [ '<STR_LIT:state>' ] ] <EOL> public_ips = public_ips if public_ips else [ ] <EOL> private_ips = [ ] <EOL> for nic in data [ '<STR_LIT>' ] : <EOL> if is_private_subnet ( nic [ '<STR_LIT>' ] ) : <EOL> private_ips . append ( nic [ '<STR_LIT>' ] ) <EOL> else : <EOL> public_ips . append ( nic [ '<STR_LIT>' ] ) <EOL> security_groups = data . get ( '<STR_LIT>' , [ ] ) <EOL> if security_groups : <EOL> security_groups = [ sg [ '<STR_LIT:name>' ] for sg in security_groups ] <EOL> affinity_groups = data . get ( '<STR_LIT>' , [ ] ) <EOL> if affinity_groups : <EOL> affinity_groups = [ ag [ '<STR_LIT:id>' ] for ag in affinity_groups ] <EOL> created = data . get ( '<STR_LIT>' , False ) <EOL> extra = self . _get_extra_dict ( data , <EOL> RESOURCE_EXTRA_ATTRIBUTES_MAP [ '<STR_LIT>' ] ) <EOL> extra [ '<STR_LIT>' ] = security_groups <EOL> extra [ '<STR_LIT>' ] = affinity_groups <EOL> extra [ '<STR_LIT>' ] = [ ] <EOL> extra [ '<STR_LIT>' ] = [ ] <EOL> extra [ '<STR_LIT>' ] = [ ] <EOL> extra [ '<STR_LIT>' ] = created <EOL> if '<STR_LIT>' in data : <EOL> extra [ '<STR_LIT>' ] = self . _get_resource_tags ( data [ '<STR_LIT>' ] ) <EOL> node = CloudStackNode ( id = id , name = name , state = state , <EOL> public_ips = list ( set ( public_ips ) ) , <EOL> private_ips = private_ips , <EOL> driver = self , extra = extra ) <EOL> return node <EOL> def _to_key_pairs ( self , data ) : <EOL> key_pairs = [ self . _to_key_pair ( data = item ) for item in data ] <EOL> return key_pairs <EOL> def _to_key_pair ( self , data ) : <EOL> key_pair = KeyPair ( name = data [ '<STR_LIT:name>' ] , <EOL> fingerprint = data [ '<STR_LIT>' ] , <EOL> public_key = data . get ( '<STR_LIT>' , None ) , <EOL> private_key = data . get ( '<STR_LIT>' , None ) , <EOL> driver = self ) <EOL> return key_pair <EOL> def _to_affinity_group ( self , data ) : <EOL> affinity_group = CloudStackAffinityGroup ( <EOL> id = data [ '<STR_LIT:id>' ] , <EOL> name = data [ '<STR_LIT:name>' ] , <EOL> group_type = CloudStackAffinityGroupType ( data [ '<STR_LIT:type>' ] ) , <EOL> account = data . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> domain = data . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> domainid = data . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> description = data . get ( '<STR_LIT:description>' , '<STR_LIT>' ) , <EOL> virtualmachine_ids = data . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> return affinity_group <EOL> def _get_resource_tags ( self , tag_set ) : <EOL> """<STR_LIT>""" <EOL> tags = { } <EOL> for tag in tag_set : <EOL> for key , value in tag . iteritems ( ) : <EOL> key = tag [ '<STR_LIT:key>' ] <EOL> value = tag [ '<STR_LIT:value>' ] <EOL> tags [ key ] = value <EOL> return tags <EOL> def _get_extra_dict ( self , response , mapping ) : <EOL> """<STR_LIT>""" <EOL> extra = { } <EOL> for attribute , values in mapping . items ( ) : <EOL> transform_func = values [ '<STR_LIT>' ] <EOL> value = response . get ( values [ '<STR_LIT>' ] , None ) <EOL> if value is not None : <EOL> extra [ attribute ] = transform_func ( value ) <EOL> else : <EOL> extra [ attribute ] = None <EOL> return extra <EOL> def _to_volume_state ( self , vol ) : <EOL> state = self . VOLUME_STATE_MAP . get ( vol [ '<STR_LIT:state>' ] , <EOL> StorageVolumeState . UNKNOWN ) <EOL> if state == StorageVolumeState . AVAILABLE and '<STR_LIT>' in vol : <EOL> state = StorageVolumeState . INUSE <EOL> return state </s>
