2011-08-03 17:41:33 -04:00
|
|
|
from novaclient import client
|
|
|
|
from novaclient.v1_1 import flavors
|
2011-12-28 17:33:43 -06:00
|
|
|
from novaclient.v1_1 import floating_ip_dns
|
2011-08-24 22:51:53 -07:00
|
|
|
from novaclient.v1_1 import floating_ips
|
2012-01-09 14:49:12 -08:00
|
|
|
from novaclient.v1_1 import floating_ip_pools
|
2011-08-03 17:41:33 -04:00
|
|
|
from novaclient.v1_1 import images
|
2011-08-06 13:08:53 -07:00
|
|
|
from novaclient.v1_1 import keypairs
|
2011-12-06 12:11:50 -05:00
|
|
|
from novaclient.v1_1 import limits
|
|
|
|
from novaclient.v1_1 import quotas
|
2011-08-10 14:55:50 -05:00
|
|
|
from novaclient.v1_1 import security_group_rules
|
2011-08-13 16:17:21 -07:00
|
|
|
from novaclient.v1_1 import security_groups
|
2011-08-03 17:41:33 -04:00
|
|
|
from novaclient.v1_1 import servers
|
2012-01-24 11:20:51 -08:00
|
|
|
from novaclient.v1_1 import virtual_interfaces
|
2011-09-29 08:09:50 -07:00
|
|
|
from novaclient.v1_1 import volumes
|
2011-11-09 10:36:16 -08:00
|
|
|
from novaclient.v1_1 import volume_snapshots
|
2011-08-04 17:07:22 -04:00
|
|
|
from novaclient.v1_1 import zones
|
2011-01-25 14:01:22 -06:00
|
|
|
|
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
class Client(object):
|
|
|
|
"""
|
|
|
|
Top-level object to access the OpenStack Compute API.
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
Create an instance with your creds::
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-11-09 04:35:39 -08:00
|
|
|
>>> client = Client(USERNAME, PASSWORD, PROJECT_ID, AUTH_URL)
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
Then call methods on its managers::
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
>>> client.servers.list()
|
|
|
|
...
|
|
|
|
>>> client.flavors.list()
|
|
|
|
...
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
"""
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-11-08 10:27:41 -08:00
|
|
|
# FIXME(jesse): project_id isn't required to authenticate
|
2011-11-17 12:48:58 -08:00
|
|
|
def __init__(self, username, api_key, project_id, auth_url,
|
2011-11-08 10:27:41 -08:00
|
|
|
insecure=False, timeout=None, token=None, region_name=None,
|
2011-12-15 19:39:33 +00:00
|
|
|
endpoint_name='publicURL', extensions=None):
|
2011-11-17 12:48:58 -08:00
|
|
|
# FIXME(comstud): Rename the api_key argument above when we
|
|
|
|
# know it's not being used as keyword argument
|
|
|
|
password = api_key
|
2011-08-03 17:41:33 -04:00
|
|
|
self.flavors = flavors.FlavorManager(self)
|
|
|
|
self.images = images.ImageManager(self)
|
2011-12-06 12:11:50 -05:00
|
|
|
self.limits = limits.LimitsManager(self)
|
2011-08-03 17:41:33 -04:00
|
|
|
self.servers = servers.ServerManager(self)
|
2011-08-06 13:08:53 -07:00
|
|
|
|
|
|
|
# extensions
|
2011-12-06 12:11:50 -05:00
|
|
|
self.floating_ips = floating_ips.FloatingIPManager(self)
|
2011-12-28 17:33:43 -06:00
|
|
|
self.floating_ip_dns = floating_ip_dns.FloatingIPDNSManager(self)
|
2012-01-09 14:49:12 -08:00
|
|
|
self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
|
2011-09-29 08:09:50 -07:00
|
|
|
self.volumes = volumes.VolumeManager(self)
|
2011-11-09 10:36:16 -08:00
|
|
|
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
|
2011-08-06 13:08:53 -07:00
|
|
|
self.keypairs = keypairs.KeypairManager(self)
|
2011-08-04 17:07:22 -04:00
|
|
|
self.zones = zones.ZoneManager(self)
|
2011-08-08 14:48:07 -07:00
|
|
|
self.quotas = quotas.QuotaSetManager(self)
|
2011-08-13 16:17:21 -07:00
|
|
|
self.security_groups = security_groups.SecurityGroupManager(self)
|
|
|
|
self.security_group_rules = \
|
|
|
|
security_group_rules.SecurityGroupRuleManager(self)
|
2012-01-24 11:20:51 -08:00
|
|
|
self.virtual_interfaces = \
|
|
|
|
virtual_interfaces.VirtualInterfaceManager(self)
|
2011-08-03 16:36:03 -04:00
|
|
|
|
2011-12-15 19:39:33 +00:00
|
|
|
# Add in any extensions...
|
|
|
|
if extensions:
|
2011-12-21 19:25:19 +00:00
|
|
|
for extension in extensions:
|
|
|
|
if extension.manager_class:
|
|
|
|
setattr(self, extension.name,
|
|
|
|
extension.manager_class(self))
|
2011-12-15 19:39:33 +00:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
self.client = client.HTTPClient(username,
|
2011-11-09 04:35:39 -08:00
|
|
|
password,
|
2011-08-03 17:41:33 -04:00
|
|
|
project_id,
|
|
|
|
auth_url,
|
2011-11-03 11:34:44 -05:00
|
|
|
insecure=insecure,
|
2011-08-30 05:50:12 -07:00
|
|
|
timeout=timeout,
|
2011-09-02 11:44:25 -07:00
|
|
|
token=token,
|
2011-11-08 10:27:41 -08:00
|
|
|
region_name=region_name,
|
|
|
|
endpoint_name=endpoint_name)
|
2011-01-25 14:01:22 -06:00
|
|
|
|
|
|
|
def authenticate(self):
|
|
|
|
"""
|
2011-08-03 17:41:33 -04:00
|
|
|
Authenticate against the server.
|
|
|
|
|
|
|
|
Normally this is called automatically when you first access the API,
|
|
|
|
but you can call this method to force authentication right now.
|
2011-01-25 14:01:22 -06:00
|
|
|
|
2011-08-03 17:41:33 -04:00
|
|
|
Returns on success; raises :exc:`exceptions.Unauthorized` if the
|
|
|
|
credentials are wrong.
|
2011-01-25 14:01:22 -06:00
|
|
|
"""
|
2011-08-03 17:41:33 -04:00
|
|
|
self.client.authenticate()
|