def test_getid(self): self.assertEqual(4, base.getid(4)) class TmpObject(object): id = 4 self.assertEqual(4, base.getid(TmpObject))
def delete(self, snapshot): """ Delete a snapshot. :param snapshot: The :class:`Snapshot` to delete. """ self._delete("/snapshots/%s" % base.getid(snapshot))
def list(self, server): """ Get a list of actions performed on an server. """ return self._list( '/servers/%s/os-instance-actions' % base.getid(server), 'instanceActions')
def delete(self, volume_type): """ Delete a specific volume_type. :param volume_type: The ID of the :class:`VolumeType` to get. """ self._delete("/types/%s" % base.getid(volume_type))
def delete(self, flavor): """ Delete a specific flavor. :param flavor: The ID of the :class:`Flavor` to get. """ self._delete("/flavors/%s" % base.getid(flavor))
def delete(self, key): """ Delete a keypair :param key: The :class:`Keypair` (or its ID) to delete. """ self._delete('/%s/%s' % (self.keypair_prefix, base.getid(key)))
def get_keys(self): """ Get extra specs from a flavor. """ _resp, body = self.manager.api.client.get( "/flavors/%s/os-extra_specs" % base.getid(self)) return body["extra_specs"]
def delete(self, rule): """ Delete a security group rule :param rule: The security group rule to delete (ID or Class) """ self._delete('/os-security-group-rules/%s' % base.getid(rule))
def delete(self, volume): """ Delete a volume. :param volume: The :class:`Volume` to delete. """ self._delete("/volumes/%s" % base.getid(volume))
def get(self, fixed_ip): """ Show information for a Fixed IP :param fixed_ip: Fixed IP address to get info for """ return self._get('/os-fixed-ips/%s' % base.getid(fixed_ip), "fixed_ip")
def delete(self, node): """ Delete a baremetal node. :param node: The :class:`BareMetalNode` to delete. """ self._delete('/os-baremetal-nodes/%s' % base.getid(node))
def delete(self, floating_ip): """ Delete (deallocate) a floating IP for a tenant :param floating_ip: The floating IP address to delete. """ self._delete("/os-floating-ips/%s" % base.getid(floating_ip))
def delete(self, network): """ Delete a specific network. :param network: The ID of the :class:`Network` to delete. """ self._delete("/os-networks/%s" % base.getid(network))
def delete(self, group): """ Delete a security group :param group: The security group to delete (group or ID) :rtype: None """ self._delete('/os-security-groups/%s' % base.getid(group))
def get(self, flavor): """ Get a specific flavor. :param flavor: The ID of the :class:`Flavor` to get. :rtype: :class:`Flavor` """ return self._get("/flavors/%s" % base.getid(flavor), "flavor")
def get(self, server): """ Get a server. :param server: ID of the :class:`Server` to get. :rtype: :class:`Server` """ return self._get("/servers/%s" % base.getid(server), "server")
def get(self, image): """ Get an image. :param image: The ID of the image to get. :rtype: :class:`Image` """ return self._get("/images/%s" % base.getid(image), "image")
def interface_list(self, server): """ List attached network interfaces :param server: The :class:`Server` (or its ID) to query. """ return self._list('/servers/%s/os-interface' % base.getid(server), 'interfaceAttachments')
def get(self, volume_type): """ Get a specific volume type. :param volume_type: The ID of the :class:`VolumeType` to get. :rtype: :class:`VolumeType` """ return self._get("/types/%s" % base.getid(volume_type), "volume_type")
def _action(self, action, server, info=None, **kwargs): """ Perform a server "action" -- reboot/rebuild/resize/etc. """ body = {action: info} self.run_hooks('modify_body_for_action', body, **kwargs) url = '/servers/%s/action' % base.getid(server) return self.api.client.post(url, body=body)
def unreserve(self, fixed_ip): """Unreserve a Fixed IP :param fixed_ip: Fixed IP address to unreserve """ body = {"unreserve": None} self.api.client.post('/os-fixed-ips/%s/action' % base.getid(fixed_ip), body=body)
def delete_meta(self, server, keys): """ Delete metadata from an server :param server: The :class:`Server` to add metadata to :param keys: A list of metadata keys to delete from the server """ for k in keys: self._delete("/servers/%s/metadata/%s" % (base.getid(server), k))
def get(self, server, request_id): """ Get details of an action performed on an instance. :param request_id: The request_id of the action to get. """ return self._get("/servers/%s/os-instance-actions/%s" % (base.getid(server), request_id), 'instanceAction')
def get(self, network): """ Get a specific network. :param network: The ID of the :class:`Network` to get. :rtype: :class:`Network` """ return self._get("/os-networks/%s" % base.getid(network), "network")
def get(self, server): """ Fping a specific server. :param server: ID of the server to fping. :rtype: :class:`Fping` """ return self._get("/os-fping/%s" % base.getid(server), "server")
def rebuild(self, server, image, password=None, disk_config=None, preserve_ephemeral=False, name=None, meta=None, files=None, **kwargs): """ Rebuild -- shut down and then re-image -- a server. :param server: The :class:`Server` (or its ID) to share onto. :param image: the :class:`Image` (or its ID) to re-image with. :param password: string to set as password on the rebuilt server. :param disk_config: partitioning mode to use on the rebuilt server. Valid values are 'AUTO' or 'MANUAL' :param preserve_ephemeral: If True, request that any ephemeral device be preserved when rebuilding the instance. Defaults to False. :param name: Something to name the server. :param meta: A dict of arbitrary key/value metadata to store for this server. A maximum of five entries is allowed, and both keys and values must be 255 characters or less. :param files: A dict of files to overwrite on the server upon boot. Keys are file names (i.e. ``/etc/passwd``) and values are the file contents (either as a string or as a file-like object). A maximum of five entries is allowed, and each file must be 10k or less. """ body = {'imageRef': base.getid(image)} if password is not None: body['adminPass'] = password if disk_config is not None: body['OS-DCF:diskConfig'] = disk_config if preserve_ephemeral is not False: body['preserve_ephemeral'] = True if name is not None: body['name'] = name if meta: body['metadata'] = meta if files: personality = body['personality'] = [] for filepath, file_or_string in sorted(files.items(), key=lambda x: x[0]): if hasattr(file_or_string, 'read'): data = file_or_string.read() else: data = file_or_string cont = base64.b64encode(data.encode('utf-8')).decode('utf-8') personality.append({ 'path': filepath, 'contents': cont, }) _resp, body = self._action('rebuild', server, body, **kwargs) return Server(self, body['server'])
def unset_keys(self, keys): """ Unset extra specs on a flavor. :param keys: A list of keys to be unset """ for k in keys: self.manager._delete("/flavors/%s/os-extra_specs/%s" % (base.getid(self), k))
def get(self, keypair): """ Get a keypair. :param keypair: The ID of the keypair to get. :rtype: :class:`Keypair` """ return self._get("/%s/%s" % (self.keypair_prefix, base.getid(keypair)), "keypair")
def associate_host(self, network, host): """ Associate a specific network with a host. :param network: The ID of the :class:`Network`. :param host: The name of the host to associate the network with """ self.api.client.post("/os-networks/%s/action" % base.getid(network), body={"associate_host": host})
def _action(self, action, flavor, info, **kwargs): """Perform a flavor action.""" body = {action: info} self.run_hooks('modify_body_for_action', body, **kwargs) url = '/flavors/%s/action' % base.getid(flavor) _resp, body = self.api.client.post(url, body=body) return [self.resource_class(self, res) for res in body['flavor_access']]
def unset_keys(self, keys): """ Unset extra specs on a flavor. :param keys: A list of keys to be unset """ for k in keys: self.manager._delete( "/flavors/%s/os-extra_specs/%s" % (base.getid(self), k))
def set_meta(self, server, metadata): """ Set a servers metadata :param server: The :class:`Server` to add metadata to :param metadata: A dict of metadata to add to the server """ body = {'metadata': metadata} return self._create("/servers/%s/metadata" % base.getid(server), body, "metadata")
def delete_meta(self, image, keys): """ Delete metadata from an image :param image: The :class:`Image` to delete metadata :param keys: A list of metadata keys to delete from the image """ for k in keys: self._delete("/images/%s/metadata/%s" % (base.getid(image), k))
def interface_detach(self, server, port_id): """ Detach a network_interface from an instance. :param server: The :class:`Server` (or its ID) to detach from. :param port_id: The port to detach. """ self._delete('/servers/%s/os-interface/%s' % (base.getid(server), port_id))
def delete(self, image): """ Delete an image. It should go without saying that you can't delete an image that you didn't create. :param image: The :class:`Image` (or its ID) to delete. """ self._delete("/images/%s" % base.getid(image))
def set_meta(self, image, metadata): """ Set an images metadata :param image: The :class:`Image` to add metadata to :param metadata: A dict of metadata to add to the image """ body = {'metadata': metadata} return self._create("/images/%s/metadata" % base.getid(image), body, "metadata")
def set_keys(self, metadata): """ Set extra specs on a flavor. :param metadata: A dict of key/value pairs to be set """ utils.validate_flavor_metadata_keys(metadata.keys()) body = {'extra_specs': metadata} return self.manager._create( "/flavors/%s/os-extra_specs" % base.getid(self), body, "extra_specs", return_raw=True)
def update(self, group, name, description): """ Update a security group :param group: The security group to update (group or ID) :param name: name for the security group to update :param description: description for the security group to update :rtype: the security group object """ body = {"security_group": {"name": name, 'description': description}} return self._update('/os-security-groups/%s' % base.getid(group), body, 'security_group')
def delete(self, aggregate): """Delete the specified aggregates.""" self._delete('/os-aggregates/%s' % (base.getid(aggregate)))
def get(self, floating_ip): """ Retrieve a floating IP """ return self._get("/os-floating-ips/%s" % base.getid(floating_ip), "floating_ip")
def remove_host(self, aggregate, host): """Remove a host from the Host Aggregate.""" body = {'remove_host': {'host': host}} return self._create("/os-aggregates/%s/action" % base.getid(aggregate), body, "aggregate")
def _list_by_flavor(self, flavor): return self._list('/flavors/%s/os-flavor-access' % base.getid(flavor), 'flavor_access')
def add_host(self, aggregate, host): """Add a host into the Host Aggregate.""" body = {'add_host': {'host': host}} return self._create("/os-aggregates/%s/action" % base.getid(aggregate), body, "aggregate")
def list(self, server): """ Get a list of actions performed on an server. """ return self._list('/servers/%s/os-instance-actions' % base.getid(server), 'instanceActions')
def set_metadata(self, aggregate, metadata): """Set a aggregate metadata, replacing the existing metadata.""" body = {'set_metadata': {'metadata': metadata}} return self._create("/os-aggregates/%s/action" % base.getid(aggregate), body, "aggregate")