INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
TODO: support fbthrift finagle - thrift finagle - mux CORBA
def detect_protocol(cls, data, default=None): """ TODO: support fbthrift, finagle-thrift, finagle-mux, CORBA """ if cls.is_compact_protocol(data): return TCompactProtocol elif cls.is_binary_protocol(data): return TBinaryProtocol elif cls.is_json_protocol(data): ...
pops packets with _at least_ nbytes of payload
def pop(self, nbytes): """ pops packets with _at least_ nbytes of payload """ size = 0 popped = [] with self._lock_packets: while size < nbytes: try: packet = self._packets.pop(0) size += len(packet.data.data) ...
similar to pop but returns payload + last timestamp
def pop_data(self, nbytes): """ similar to pop, but returns payload + last timestamp """ last_timestamp = 0 data = [] for packet in self.pop(nbytes): last_timestamp = packet.timestamp data.append(packet.data.data) return ''.join(data), last_timestamp
push the packet into the queue
def push(self, ip_packet): """ push the packet into the queue """ data_len = len(ip_packet.data.data) seq_id = ip_packet.data.seq if data_len == 0: self._next_seq_id = seq_id return False # have we seen this packet? if self._next_seq_id != -1 an...
Deal with the incoming packets
def run(self, *args, **kwargs): """ Deal with the incoming packets """ while True: try: timestamp, ip_p = self._queue.popleft() src_ip = get_ip(ip_p, ip_p.src) dst_ip = get_ip(ip_p, ip_p.dst) src = intern('%s:%s' % (src_ip, ip...
write user/ passwd to login file or get them from file. This method is not Py3 safe ( byte vs. str )
def getLogin(filename, user, passwd): ''' write user/passwd to login file or get them from file. This method is not Py3 safe (byte vs. str) ''' if filename is None: return (user, passwd) isPy2 = sys.version_info[0] == 2 if os.path.exists(filename): print("Using file {} for Lo...
Waits for a list of requests to finish until timeout. timeout == 0 is interpreted as infinite wait time. Returns a dict of request_id - > result. result is a tuple ( return code request status message ) where return code 0: request successful 1: request failed - 1: timeout exceeded The wait_period is increased every sc...
def wait_for_requests(pbclient, request_ids=None, timeout=0, initial_wait=5, scaleup=10): ''' Waits for a list of requests to finish until timeout. timeout==0 is interpreted as infinite wait time. Returns a dict of request_id -> result. result is a tuple (return code, request s...
Returns all disk images within a location with a given image name. The name must match exactly. The list may be empty.
def get_disk_image_by_name(pbclient, location, image_name): """ Returns all disk images within a location with a given image name. The name must match exactly. The list may be empty. """ all_images = pbclient.list_images() matching = [i for i in all_images['items'] if i['prop...
Command line options.
def main(argv=None): '''Command line options.''' if argv is None: argv = sys.argv else: sys.argv.extend(argv) program_name = os.path.basename(sys.argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) program_version_message = '%%(prog)s %s (%s...
returns an attribute name w/ namespace prefix
def _nsattr(self, attr, ns=None): ''' returns an attribute name w/ namespace prefix''' if ns is None: return attr return '{' + self._ns[ns] + '}' + attr
Read the user configuration
def _read_config(self, filename=None): """ Read the user configuration """ if filename: self._config_filename = filename else: try: import appdirs except ImportError: raise Exception("Missing dependency for deter...
Save the given user configuration.
def _save_config(self, filename=None): """ Save the given user configuration. """ if filename is None: filename = self._config_filename parent_path = os.path.dirname(filename) if not os.path.isdir(parent_path): os.makedirs(parent_path) with...
Determine the username
def _get_username(self, username=None, use_config=True, config_filename=None): """Determine the username If a username is given, this name is used. Otherwise the configuration file will be consulted if `use_config` is set to True. The user is asked for the username if the username is no...
Determine the user password
def _get_password(self, password, use_config=True, config_filename=None, use_keyring=HAS_KEYRING): """ Determine the user password If the password is given, this password is used. Otherwise this function will try to get the password from the user's keyring ...
Retrieves a data center by its ID.
def get_datacenter(self, datacenter_id, depth=1): """ Retrieves a data center by its ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param depth: The depth of the response data. :type depth: ``int`` ...
Retrieves a data center by its name.
def get_datacenter_by_name(self, name, depth=1): """ Retrieves a data center by its name. Either returns the data center response or raises an Exception if no or more than one data center was found with the name. The search for the name is done in this relaxing way: - e...
Removes the data center and all its components such as servers NICs load balancers volumes.
def delete_datacenter(self, datacenter_id): """ Removes the data center and all its components such as servers, NICs, load balancers, volumes. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` """ response = self._pe...
Creates a data center -- both simple and complex are supported.
def create_datacenter(self, datacenter): """ Creates a data center -- both simple and complex are supported. """ server_items = [] volume_items = [] lan_items = [] loadbalancer_items = [] entities = dict() properties = { "name": data...
Retrieves a single firewall rule by ID.
def get_firewall_rule(self, datacenter_id, server_id, nic_id, firewall_rule_id): """ Retrieves a single firewall rule by ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The uniq...
Removes a firewall rule from the NIC.
def delete_firewall_rule(self, datacenter_id, server_id, nic_id, firewall_rule_id): """ Removes a firewall rule from the NIC. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The ...
Creates a firewall rule on the specified NIC and server.
def create_firewall_rule(self, datacenter_id, server_id, nic_id, firewall_rule): """ Creates a firewall rule on the specified NIC and server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param ...
Updates a firewall rule.
def update_firewall_rule(self, datacenter_id, server_id, nic_id, firewall_rule_id, **kwargs): """ Updates a firewall rule. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The uni...
Removes only user created images.
def delete_image(self, image_id): """ Removes only user created images. :param image_id: The unique ID of the image. :type image_id: ``str`` """ response = self._perform_request(url='/images/' + image_id, method='DELET...
Replace all properties of an image.
def update_image(self, image_id, **kwargs): """ Replace all properties of an image. """ data = {} for attr, value in kwargs.items(): data[self._underscore_to_camelcase(attr)] = value response = self._perform_request(url='/images/' + image_id, ...
Removes a single IP block from your account.
def delete_ipblock(self, ipblock_id): """ Removes a single IP block from your account. :param ipblock_id: The unique ID of the IP block. :type ipblock_id: ``str`` """ response = self._perform_request( url='/ipblocks/' + ipblock_id, method='DELETE'...
Reserves an IP block within your account.
def reserve_ipblock(self, ipblock): """ Reserves an IP block within your account. """ properties = { "name": ipblock.name } if ipblock.location: properties['location'] = ipblock.location if ipblock.size: properties['size'] = ...
Retrieves a single LAN by ID.
def get_lan(self, datacenter_id, lan_id, depth=1): """ Retrieves a single LAN by ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param lan_id: The unique ID of the LAN. :type lan_id: ``str`` :param...
Retrieves a list of LANs available in the account.
def list_lans(self, datacenter_id, depth=1): """ Retrieves a list of LANs available in the account. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param depth: The depth of the response data. :type depth: ``in...
Removes a LAN from the data center.
def delete_lan(self, datacenter_id, lan_id): """ Removes a LAN from the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param lan_id: The unique ID of the LAN. :type lan_id: ``str`` """ ...
Creates a LAN in the data center.
def create_lan(self, datacenter_id, lan): """ Creates a LAN in the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param lan: The LAN object to be created. :type lan: ``dict`` """ ...
Updates a LAN
def update_lan(self, datacenter_id, lan_id, name=None, public=None, ip_failover=None): """ Updates a LAN :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param lan_id: The unique ID of the LAN. :typ...
Retrieves the list of NICs that are part of the LAN.
def get_lan_members(self, datacenter_id, lan_id, depth=1): """ Retrieves the list of NICs that are part of the LAN. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param lan_id: The unique ID of the LAN. :type ...
Retrieves a single load balancer by ID.
def get_loadbalancer(self, datacenter_id, loadbalancer_id): """ Retrieves a single load balancer by ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer_id: The unique ID of the load balancer. :type...
Retrieves a list of load balancers in the data center.
def list_loadbalancers(self, datacenter_id, depth=1): """ Retrieves a list of load balancers in the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param depth: The depth of the response data. :type ...
Removes the load balancer from the data center.
def delete_loadbalancer(self, datacenter_id, loadbalancer_id): """ Removes the load balancer from the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer_id: The unique ID of the load balancer. ...
Creates a load balancer within the specified data center.
def create_loadbalancer(self, datacenter_id, loadbalancer): """ Creates a load balancer within the specified data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer: The load balancer object to be cre...
Updates a load balancer
def update_loadbalancer(self, datacenter_id, loadbalancer_id, **kwargs): """ Updates a load balancer :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer_id: The unique ID of the loa...
Retrieves the list of NICs that are associated with a load balancer.
def get_loadbalancer_members(self, datacenter_id, loadbalancer_id, depth=1): """ Retrieves the list of NICs that are associated with a load balancer. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` ...
Associates a NIC with the given load balancer.
def add_loadbalanced_nics(self, datacenter_id, loadbalancer_id, nic_id): """ Associates a NIC with the given load balancer. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer_id:...
Gets the properties of a load balanced NIC.
def get_loadbalanced_nic(self, datacenter_id, loadbalancer_id, nic_id, depth=1): """ Gets the properties of a load balanced NIC. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer...
Removes a NIC from the load balancer.
def remove_loadbalanced_nic(self, datacenter_id, loadbalancer_id, nic_id): """ Removes a NIC from the load balancer. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param loadbalancer_id: The ...
Retrieves a single location by ID.
def get_location(self, location_id, depth=0): """ Retrieves a single location by ID. :param location_id: The unique ID of the location. :type location_id: ``str`` """ response = self._perform_request('/locations/%s?depth=%s' % (location_id, depth)) re...
Retrieves a NIC by its ID.
def get_nic(self, datacenter_id, server_id, nic_id, depth=1): """ Retrieves a NIC by its ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str`...
Retrieves a list of all NICs bound to the specified server.
def list_nics(self, datacenter_id, server_id, depth=1): """ Retrieves a list of all NICs bound to the specified server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :t...
Removes a NIC from the server.
def delete_nic(self, datacenter_id, server_id, nic_id): """ Removes a NIC from the server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str`` ...
Creates a NIC on the specified server.
def create_nic(self, datacenter_id, server_id, nic): """ Creates a NIC on the specified server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``s...
Updates a NIC with the parameters provided.
def update_nic(self, datacenter_id, server_id, nic_id, **kwargs): """ Updates a NIC with the parameters provided. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the serve...
Retrieves a single request by ID.
def get_request(self, request_id, status=False): """ Retrieves a single request by ID. :param request_id: The unique ID of the request. :type request_id: ``str`` :param status: Retreive the full status of the request. :type status: ``bool`` ...
Retrieves a server by its ID.
def get_server(self, datacenter_id, server_id, depth=1): """ Retrieves a server by its ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str`` ...
Retrieves a list of all servers bound to the specified data center.
def list_servers(self, datacenter_id, depth=1): """ Retrieves a list of all servers bound to the specified data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param depth: The depth of the response data. :ty...
Removes the server from your data center.
def delete_server(self, datacenter_id, server_id): """ Removes the server from your data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``...
Creates a server within the data center.
def create_server(self, datacenter_id, server): """ Creates a server within the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server: A dict of the server to be created. :type server: ``dic...
Updates a server with the parameters provided.
def update_server(self, datacenter_id, server_id, **kwargs): """ Updates a server with the parameters provided. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type ...
Retrieves a list of volumes attached to the server.
def get_attached_volumes(self, datacenter_id, server_id, depth=1): """ Retrieves a list of volumes attached to the server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. ...
Retrieves volume information.
def get_attached_volume(self, datacenter_id, server_id, volume_id): """ Retrieves volume information. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_i...
Attaches a volume to a server.
def attach_volume(self, datacenter_id, server_id, volume_id): """ Attaches a volume to a server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``...
Detaches a volume from a server.
def detach_volume(self, datacenter_id, server_id, volume_id): """ Detaches a volume from a server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ...
Retrieves a list of CDROMs attached to the server.
def get_attached_cdroms(self, datacenter_id, server_id, depth=1): """ Retrieves a list of CDROMs attached to the server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :...
Retrieves an attached CDROM.
def get_attached_cdrom(self, datacenter_id, server_id, cdrom_id): """ Retrieves an attached CDROM. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ...
Attaches a CDROM to a server.
def attach_cdrom(self, datacenter_id, server_id, cdrom_id): """ Attaches a CDROM to a server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str...
Detaches a volume from a server.
def detach_cdrom(self, datacenter_id, server_id, cdrom_id): """ Detaches a volume from a server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``...
Starts the server.
def start_server(self, datacenter_id, server_id): """ Starts the server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str`` """ ...
Stops the server.
def stop_server(self, datacenter_id, server_id): """ Stops the server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str`` """ ...
Reboots the server.
def reboot_server(self, datacenter_id, server_id): """ Reboots the server. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param server_id: The unique ID of the server. :type server_id: ``str`` """ ...
Removes a snapshot from your account.
def delete_snapshot(self, snapshot_id): """ Removes a snapshot from your account. :param snapshot_id: The unique ID of the snapshot. :type snapshot_id: ``str`` """ response = self._perform_request( url='/snapshots/' + snapshot_id, method='DELETE')...
Removes a snapshot from your account.
def update_snapshot(self, snapshot_id, **kwargs): """ Removes a snapshot from your account. :param snapshot_id: The unique ID of the snapshot. :type snapshot_id: ``str`` """ data = {} for attr, value in kwargs.items(): data[self._underscor...
Creates a snapshot of the specified volume.
def create_snapshot(self, datacenter_id, volume_id, name=None, description=None): """ Creates a snapshot of the specified volume. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param volume_id: The u...
Restores a snapshot to the specified volume.
def restore_snapshot(self, datacenter_id, volume_id, snapshot_id): """ Restores a snapshot to the specified volume. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param volume_id: The unique ID of the volume. :type ...
Removes a snapshot.
def remove_snapshot(self, snapshot_id): """ Removes a snapshot. :param snapshot_id: The ID of the snapshot you wish to remove. :type snapshot_id: ``str`` """ response = self._perform_request( url='/snapshots/' + sn...
Retrieves a single group by ID.
def get_group(self, group_id, depth=1): """ Retrieves a single group by ID. :param group_id: The unique ID of the group. :type group_id: ``str`` :param depth: The depth of the response data. :type depth: ``int`` """ response = self...
Creates a new group and set group privileges.
def create_group(self, group): """ Creates a new group and set group privileges. :param group: The group object to be created. :type group: ``dict`` """ data = json.dumps(self._create_group_dict(group)) response = self._perform_request( u...
Updates a group.
def update_group(self, group_id, **kwargs): """ Updates a group. :param group_id: The unique ID of the group. :type group_id: ``str`` """ properties = {} # make the key camel-case transformable if 'create_datacenter' in kwargs: kw...
Removes a group.
def delete_group(self, group_id): """ Removes a group. :param group_id: The unique ID of the group. :type group_id: ``str`` """ response = self._perform_request( url='/um/groups/%s' % group_id, method='DELETE') return response
Retrieves a list of all shares though a group.
def list_shares(self, group_id, depth=1): """ Retrieves a list of all shares though a group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param depth: The depth of the response data. :type depth: ``int`` """ ...
Retrieves a specific resource share available to a group.
def get_share(self, group_id, resource_id, depth=1): """ Retrieves a specific resource share available to a group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param resource_id: The unique ID of the resource. :type resourc...
Shares a resource through a group.
def add_share(self, group_id, resource_id, **kwargs): """ Shares a resource through a group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param resource_id: The unique ID of the resource. :type resource_id: ``str`` ...
Removes a resource share from a group.
def delete_share(self, group_id, resource_id): """ Removes a resource share from a group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param resource_id: The unique ID of the resource. :type resource_id: ``str`` ""...
Retrieves a single user by ID.
def get_user(self, user_id, depth=1): """ Retrieves a single user by ID. :param user_id: The unique ID of the user. :type user_id: ``str`` :param depth: The depth of the response data. :type depth: ``int`` """ response = self._perf...
Creates a new user.
def create_user(self, user): """ Creates a new user. :param user: The user object to be created. :type user: ``dict`` """ data = self._create_user_dict(user=user) response = self._perform_request( url='/um/users', method='POST...
Updates a user.
def update_user(self, user_id, **kwargs): """ Updates a user. :param user_id: The unique ID of the user. :type user_id: ``str`` """ properties = {} for attr, value in kwargs.items(): properties[self._underscore_to_camelcase(attr)] = value...
Removes a user.
def delete_user(self, user_id): """ Removes a user. :param user_id: The unique ID of the user. :type user_id: ``str`` """ response = self._perform_request( url='/um/users/%s' % user_id, method='DELETE') return response
Retrieves a list of all users that are members of a particular group.
def list_group_users(self, group_id, depth=1): """ Retrieves a list of all users that are members of a particular group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param depth: The depth of the response data. :type depth:...
Adds an existing user to a group.
def add_group_user(self, group_id, user_id): """ Adds an existing user to a group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param user_id: The unique ID of the user. :type user_id: ``str`` """ data = { ...
Removes a user from a group.
def remove_group_user(self, group_id, user_id): """ Removes a user from a group. :param group_id: The unique ID of the group. :type group_id: ``str`` :param user_id: The unique ID of the user. :type user_id: ``str`` """ response = ...
Retrieves a list of all resources.
def list_resources(self, resource_type=None, depth=1): """ Retrieves a list of all resources. :param resource_type: The resource type: datacenter, image, snapshot or ipblock. Default is None, i.e., all resources are list...
Retrieves a single resource of a particular type.
def get_resource(self, resource_type, resource_id, depth=1): """ Retrieves a single resource of a particular type. :param resource_type: The resource type: datacenter, image, snapshot or ipblock. :type resource_type: ``str`` :param ...
Retrieves a single volume by ID.
def get_volume(self, datacenter_id, volume_id): """ Retrieves a single volume by ID. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param volume_id: The unique ID of the volume. :type volume_id: ``str`` ...
Retrieves a list of volumes in the data center.
def list_volumes(self, datacenter_id, depth=1): """ Retrieves a list of volumes in the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param depth: The depth of the response data. :type depth: ``in...
Removes a volume from the data center.
def delete_volume(self, datacenter_id, volume_id): """ Removes a volume from the data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param volume_id: The unique ID of the volume. :type volume_id: ``str...
Creates a volume within the specified data center.
def create_volume(self, datacenter_id, volume): """ Creates a volume within the specified data center. :param datacenter_id: The unique ID of the data center. :type datacenter_id: ``str`` :param volume: A volume dict. :type volume: ``dict`` ...
Poll resource request status until resource is provisioned.
def wait_for_completion(self, response, timeout=3600, initial_wait=5, scaleup=10): """ Poll resource request status until resource is provisioned. :param response: A response dict, which needs to have a 'requestId' item. :type response: ``dict`` :param timeout: ...
Returns the given string as a string of bytes. That means in Python2 as a str object and in Python3 as a bytes object. Raises a TypeError if it cannot be converted.
def _b(s, encoding='utf-8'): """ Returns the given string as a string of bytes. That means in Python2 as a str object, and in Python3 as a bytes object. Raises a TypeError, if it cannot be converted. """ if six.PY2: # This is Python2 if isinstance(...
Convert Python snake case back to mixed case.
def _underscore_to_camelcase(value): """ Convert Python snake case back to mixed case. """ def camelcase(): yield str.lower while True: yield str.capitalize c = camelcase() return "".join(next(c)(x) if x else '_' for x in value.spl...
Ask the user a question with a list of allowed answers ( like yes or no ).
def ask(question, options, default): """ Ask the user a question with a list of allowed answers (like yes or no). The user is presented with a question and asked to select an answer from the given options list. The default will be returned if the user enters nothing. The user is asked to repeat his...
Find a item a given list by a matching name.
def find_item_by_name(list_, namegetter, name): """ Find a item a given list by a matching name. The search for the name is done in this relaxing way: - exact name match - case-insentive name match - attribute starts with the name - attribute starts with the name (case insensitive) - n...
Creates a Datacenter dict -- both simple and complex are supported. This is copied from createDatacenter () and uses private methods.
def create_datacenter_dict(pbclient, datacenter): """ Creates a Datacenter dict -- both simple and complex are supported. This is copied from createDatacenter() and uses private methods. """ # pylint: disable=protected-access server_items = [] volume_items = [] lan_items = [] loadba...
Parse command line options and create a server/ volume composite.
def main(argv=None): '''Parse command line options and create a server/volume composite.''' if argv is None: argv = sys.argv else: sys.argv.extend(argv) program_name = os.path.basename(sys.argv[0]) program_version = "v%s" % __version__ program_build_date = str(__updated__) ...
gets info of servers of a data center
def getServerInfo(pbclient=None, dc_id=None): ''' gets info of servers of a data center''' if pbclient is None: raise ValueError("argument 'pbclient' must not be None") if dc_id is None: raise ValueError("argument 'dc_id' must not be None") # list of all found server's info server_in...
gets states of a server
def getServerStates(pbclient=None, dc_id=None, serverid=None, servername=None): ''' gets states of a server''' if pbclient is None: raise ValueError("argument 'pbclient' must not be None") if dc_id is None: raise ValueError("argument 'dc_id' must not be None") server = None if server...
wait for a server/ VM to reach a defined state for a specified time indicator: = { state|vmstate } specifies if server or VM stat is tested state specifies the status the indicator should have
def wait_for_server(pbclient=None, dc_id=None, serverid=None, indicator='state', state='AVAILABLE', timeout=300): ''' wait for a server/VM to reach a defined state for a specified time indicator := {state|vmstate} specifies if server or VM stat is tested state specifies the status th...