75 lines
2.7 KiB
Python
Raw Normal View History

from novaclient import client
from novaclient.v1_1 import flavors
2011-08-24 22:51:53 -07:00
from novaclient.v1_1 import floating_ips
from novaclient.v1_1 import images
2011-08-06 13:08:53 -07:00
from novaclient.v1_1 import keypairs
2011-08-10 14:55:50 -05:00
from novaclient.v1_1 import security_group_rules
from novaclient.v1_1 import security_groups
from novaclient.v1_1 import servers
2011-08-08 14:48:07 -07:00
from novaclient.v1_1 import quotas
from novaclient.v1_1 import volumes
from novaclient.v1_1 import volume_snapshots
from novaclient.v1_1 import zones
2011-01-25 14:01:22 -06:00
class Client(object):
"""
Top-level object to access the OpenStack Compute API.
2011-01-25 14:01:22 -06: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
Then call methods on its managers::
2011-01-25 14:01:22 -06:00
>>> client.servers.list()
...
>>> client.flavors.list()
...
2011-01-25 14:01:22 -06: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
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,
endpoint_name='publicURL'):
# FIXME(comstud): Rename the api_key argument above when we
# know it's not being used as keyword argument
password = api_key
self.flavors = flavors.FlavorManager(self)
2011-08-24 22:51:53 -07:00
self.floating_ips = floating_ips.FloatingIPManager(self)
self.images = images.ImageManager(self)
self.servers = servers.ServerManager(self)
2011-08-06 13:08:53 -07:00
# extensions
self.volumes = volumes.VolumeManager(self)
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
2011-08-06 13:08:53 -07:00
self.keypairs = keypairs.KeypairManager(self)
self.zones = zones.ZoneManager(self)
2011-08-08 14:48:07 -07:00
self.quotas = quotas.QuotaSetManager(self)
self.security_groups = security_groups.SecurityGroupManager(self)
self.security_group_rules = \
security_group_rules.SecurityGroupRuleManager(self)
self.client = client.HTTPClient(username,
2011-11-09 04:35:39 -08:00
password,
project_id,
auth_url,
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):
"""
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
Returns on success; raises :exc:`exceptions.Unauthorized` if the
credentials are wrong.
2011-01-25 14:01:22 -06:00
"""
self.client.authenticate()