136 lines
5.5 KiB
Python
Raw Normal View History

from novaclient import client
from novaclient.v1_1 import certs
from novaclient.v1_1 import cloudpipe
from novaclient.v1_1 import aggregates
from novaclient.v1_1 import flavors
from novaclient.v1_1 import flavor_access
from novaclient.v1_1 import floating_ip_dns
2011-08-24 22:51:53 -07:00
from novaclient.v1_1 import floating_ips
from novaclient.v1_1 import floating_ip_pools
from novaclient.v1_1 import hosts
from novaclient.v1_1 import hypervisors
from novaclient.v1_1 import images
2011-08-06 13:08:53 -07:00
from novaclient.v1_1 import keypairs
from novaclient.v1_1 import limits
from novaclient.v1_1 import networks
from novaclient.v1_1 import quota_classes
from novaclient.v1_1 import quotas
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
from novaclient.v1_1 import usage
from novaclient.v1_1 import virtual_interfaces
from novaclient.v1_1 import volumes
from novaclient.v1_1 import volume_snapshots
from novaclient.v1_1 import volume_types
from novaclient.v1_1 import services
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=None,
insecure=False, timeout=None, proxy_tenant_id=None,
proxy_token=None, region_name=None,
endpoint_type='publicURL', extensions=None,
service_type='compute', service_name=None,
volume_service_name=None, timings=False,
bypass_url=None, no_cache=False, http_log_debug=False,
auth_system='keystone'):
# FIXME(comstud): Rename the api_key argument above when we
# know it's not being used as keyword argument
password = api_key
self.project_id = project_id
self.flavors = flavors.FlavorManager(self)
self.flavor_access = flavor_access.FlavorAccessManager(self)
self.images = images.ImageManager(self)
self.limits = limits.LimitsManager(self)
self.servers = servers.ServerManager(self)
2011-08-06 13:08:53 -07:00
# extensions
self.dns_domains = floating_ip_dns.FloatingIPDNSDomainManager(self)
self.dns_entries = floating_ip_dns.FloatingIPDNSEntryManager(self)
self.cloudpipe = cloudpipe.CloudpipeManager(self)
self.certs = certs.CertificateManager(self)
self.floating_ips = floating_ips.FloatingIPManager(self)
self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
self.volumes = volumes.VolumeManager(self)
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
self.volume_types = volume_types.VolumeTypeManager(self)
2011-08-06 13:08:53 -07:00
self.keypairs = keypairs.KeypairManager(self)
self.networks = networks.NetworkManager(self)
self.quota_classes = quota_classes.QuotaClassSetManager(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.usage = usage.UsageManager(self)
self.virtual_interfaces = \
virtual_interfaces.VirtualInterfaceManager(self)
self.aggregates = aggregates.AggregateManager(self)
self.hosts = hosts.HostManager(self)
self.hypervisors = hypervisors.HypervisorManager(self)
self.services = services.ServiceManager(self)
# Add in any extensions...
if extensions:
for extension in extensions:
if extension.manager_class:
setattr(self, extension.name,
extension.manager_class(self))
self.client = client.HTTPClient(username,
password,
project_id,
auth_url,
insecure=insecure,
timeout=timeout,
auth_system=auth_system,
proxy_token=proxy_token,
proxy_tenant_id=proxy_tenant_id,
region_name=region_name,
endpoint_type=endpoint_type,
service_type=service_type,
service_name=service_name,
volume_service_name=volume_service_name,
timings=timings,
bypass_url=bypass_url,
no_cache=no_cache,
http_log_debug=http_log_debug)
def set_management_url(self, url):
self.client.set_management_url(url)
def get_timings(self):
return self.client.get_timings()
2011-01-25 14:01:22 -06:00
def reset_timings(self):
self.client.reset_timings()
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()