The ooi.api.helpers
Module¶
-
class
ooi.api.helpers.
BaseHelper
(app, openstack_version)¶ Bases:
object
Base helper to interact with nova API.
-
static
get_from_response
(response, element, default)¶ Get a JSON element from a valid response or raise an exception.
This method will extract an element a JSON response (falling back to a default value) if the response has a code of 200, otherwise it will raise a webob.exc.exception
Parameters: - response – The webob.Response object
- element – The element to look for in the JSON body
- default – The default element to be returned if not found.
-
static
-
class
ooi.api.helpers.
OpenStackHelper
(app, openstack_version)¶ Bases:
ooi.api.helpers.BaseHelper
Class to interact with the nova API.
-
allocate_floating_ip
(req, pool=None)¶ Allocate a floating ip from a pool.
Parameters: - req – the incoming request
- pool – floating ip pool to get the IP from
-
assign_floating_ip
(req, network_id, device_id, pool=None)¶ assign floating ip to a server
Parameters: - req – the incoming request
- network_id – network id
- device_id – device id
-
associate_floating_ip
(req, server, address)¶ Associate a floating ip to a server.
Parameters: - req – the incoming request
- server – the server to associate the ip to
- address – ip to associate to the server
-
create_network
(req, name, cidr, gateway=None, ip_version=None)¶ Create a network in nova-network.
Parameters: - req – the incoming request
- name – network resource to manage
- cidr – parameters with values
- gateway – gateway ip
- ip_version – ip version
-
create_port
(req, network_id, device_id)¶ Add a port to the subnet
Returns the port information
Parameters: - req – the incoming network
- network_id – network id
- device_id – device id
-
create_server
(req, name, image, flavor, user_data=None, key_name=None, block_device_mapping_v2=None, networks=None)¶ Create a server.
Parameters: - req – the incoming request
- name – name for the new server
- image – image id for the new server
- flavor – flavor id for the new server
- user_data – user data to inject into the server
- key_name – user public key name
-
create_server_volumes_link
(req, server_id, vol_id, dev=None)¶
-
delete
(req, server_id)¶ Delete a server.
Parameters: - req – the incoming request
- server_id – server id to delete
-
delete_network
(req, id)¶ Delete a network.
It returns json code from the server
Parameters: - req – the incoming network
- id – net identification
- parameters – parameters with tenant
-
delete_port
(req, compute_id, ip_id)¶ Delete a port to the subnet
Returns the port information
Parameters: - req – the incoming network
- compute_id – compute id
- ip_id – ip id
-
delete_server_volumes_link
(req, server_id, vol_id)¶
-
get_compute_net_link
(req, compute_id, network_id, address)¶ Get a specific network/server link
It shows a specific link (either private or public ip)
Parameters: - req – the incoming request
- compute_id – server id
- network_id – network id
- address – ip connected
-
get_flavor
(req, flavor_id)¶ Get information from a flavor.
Parameters: - req – the incoming request
- flavor_id – flavor id to get info from
-
get_flavors
(req)¶ Get information from all flavors.
Parameters: req – the incoming request
-
get_floating_ip_pools
(req)¶ Get floating IP pools for the tenant.
Parameters: req – the incoming request
-
get_floating_ips
(req)¶ Get floating IPs for the tenant.
Parameters: req – the incoming request
-
get_image
(req, image_id)¶ Get information from an image.
Parameters: - req – the incoming request
- image_id – image id to get info from
-
get_images
(req)¶ Get information from all images.
Parameters: req – the incoming request
-
get_network_details
(req, id)¶ Get info from a network.
It returns json code from the server
Parameters: - req – the incoming network
- id – net identification
-
get_network_id
(req, mac, server_id)¶ Get the Network ID from the mac port
Parameters: - req – the incoming network
- mac – mac port
- server_id – server id
-
get_server
(req, server_id)¶ Get info from a server.
Parameters: - req – the incoming request
- server_id – server id to get info from
-
get_server_volumes_link
(req, server_id)¶ Get volumes attached to a server.
Parameters: - req – the incoming request
- server_id – server id to get volumes from
-
get_volume
(req, volume_id)¶ Get information from a volume.
Parameters: - req – the incoming request
- volume_id – volume id to get info from
-
get_volumes
(req)¶
-
index
(req)¶ Get a list of servers for a tenant.
Parameters: req – the incoming request
-
keypair_create
(req, name, public_key=None)¶ Create a keypair.
Parameters: - req – the incoming request
- name – name for the new keypair
- public_key – public ssh key to import
-
keypair_delete
(req, name)¶ Delete a keypair.
Parameters: - req – the incoming request
- name – keypair name to delete
-
list_compute_net_links
(req)¶ Get floating IPs for the tenant.
Parameters: req – the incoming request
-
list_networks
(req)¶ Get a list of servers for a tenant.
Parameters: - req – the incoming request
- parameters – parameters with tenant
-
release_floating_ip
(req, ip)¶ Release a floating ip.
Parameters: - req – the incoming request
- ip – floating ip pool to release
-
remove_floating_ip
(req, server, address)¶ Remove a floating ip to a server.
Parameters: - req – the incoming request
- server – the server to remove the ip from
- address – ip to remove from the server
-
required
= {'networks': {'occi.core.title': 'label', 'occi.network.address': 'cidr'}}¶
-
run_action
(req, action, server_id)¶ Run an action on a server.
Parameters: - req – the incoming request
- action – the action to run
- server_id – server id to delete
-
static
tenant_from_req
(req)¶
-
volume_create
(req, name, size)¶ Create a volume.
Parameters: - req – the incoming request
- name – name for the new volume
- size – size for the new volume
-
volume_delete
(req, vol_id)¶ Delete a volume.
Parameters: - req – the incoming request
- vol_id – volume id to delete
-
-
ooi.api.helpers.
exception_from_response
(response)¶ Convert an OpenStack V2 Fault into a webob exception.
Since we are calling the OpenStack API we should process the Faults produced by them. Extract the Fault information according to [1] and convert it back to a webob exception.
[1] http://docs.openstack.org/developer/nova/v2/faults.html
Parameters: response – a webob.Response containing an exception Returns: a webob.exc.exception object
-
ooi.api.helpers.
get_id_with_kind
(req, resource_url, kind=None)¶ Resolves the resource URL and tries to match it with the kind.
Parameters: - req – current request
- resource_url – absolute or relative resource url
Returns: a tuple with a base url and a resource id
Raises: ooi.exception.Invalid – if resource does not match kind