def list(self, host=None, status=None, cell_name=None): """ Get a list of migrations. :param host: (optional) filter migrations by host name. :param status: (optional) filter migrations by status. :param cell_name: (optional) filter migrations for a cell. """ opts = {} if host: opts['host'] = host if status: opts['status'] = status if cell_name: self.client.logger.warning( _LW("Argument 'cell_name' is " "deprecated since Pike, and will " "be removed in a future release.")) opts['cell_name'] = cell_name # Transform the dict to a sequence of two-element tuples in fixed # order, then the encoded string will be consistent in Python 2&3. new_opts = sorted(opts.items(), key=lambda x: x[0]) query_string = "?%s" % parse.urlencode(new_opts) if new_opts else "" return self._list("/os-migrations%s" % query_string, "migrations")
def check_headers(response, api_version): """Checks that 'X-OpenStack-Nova-API-Version' header in response.""" if api_version.ver_minor > 0 and HEADER_NAME not in response.headers: LOG.warning(_LW( "Your request was processed by a Nova API which does not support " "microversions (%s header is missing from response). " "Warning: Response may be incorrect."), HEADER_NAME)
def get_client_class(version): """Returns Client class based on given version.""" warnings.warn( _LW("'get_client_class' is deprecated. " "Please use `novaclient.client.Client` instead.")) _api_version, client_class = _get_client_class_and_version(version) return client_class
def __enter__(self): self.logger.warning( _LW("NovaClient instance can't be used as a " "context manager since Ocata (deprecated " "behaviour) since it is redundant in case of " "SessionClient.")) return self
def get_client_class(version): version = str(version) if version in DEPRECATED_VERSIONS: warnings.warn( _LW("Version %(deprecated_version)s is deprecated, using " "alternative version %(alternative)s instead.") % { "deprecated_version": version, "alternative": DEPRECATED_VERSIONS[version] }) version = DEPRECATED_VERSIONS[version] try: return importutils.import_class("novaclient.v%s.client.Client" % version) except ImportError: # NOTE(andreykurilin): available clients version should not be # hardcoded, so let's discover them. matcher = re.compile(r"v[0-9_]*$") submodules = pkgutil.iter_modules(['novaclient']) available_versions = [ name[1:].replace("_", ".") for loader, name, ispkg in submodules if matcher.search(name) ] msg = _("Invalid client version '%(version)s'. must be one of: " "%(keys)s") % { 'version': version, 'keys': ', '.join(available_versions) } raise exceptions.UnsupportedVersion(msg)
def warn(alternative=True): """Prints warning msg for contrib modules.""" frm = inspect.stack()[1] module_name = inspect.getmodule(frm[0]).__name__ if module_name.startswith("novaclient.v2.contrib."): msg = _LW("Module `%s` is deprecated as of OpenStack Ocata") % module_name if alternative: new_module_name = module_name.replace("contrib.", "") msg += _LW(" in favor of `%s`") % new_module_name msg += _LW(" and will be removed after OpenStack Pike.") if not alternative: msg += _LW( " All shell commands were moved to " "`novaclient.v2.shell` and will be automatically " "loaded." ) warnings.warn(msg)
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. Returns on success; raises :exc:`exceptions.Unauthorized` if the credentials are wrong. """ self.logger.warning(_LW( "Method 'authenticate' is deprecated since Ocata."))
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. Returns on success; raises :exc:`exceptions.Unauthorized` if the credentials are wrong. """ self.logger.warning( _LW("Method 'authenticate' is deprecated since Ocata."))
def warn(alternative=True): """Prints warning msg for contrib modules.""" frm = inspect.stack()[1] module_name = inspect.getmodule(frm[0]).__name__ if module_name.startswith("novaclient.v2.contrib."): if alternative: new_module_name = module_name.replace("contrib.", "") msg = _LW("Module `%(module)s` is deprecated as of OpenStack " "Ocata in favor of `%(new_module)s` and will be " "removed after OpenStack Pike.") % { "module": module_name, "new_module": new_module_name } if not alternative: msg = _LW("Module `%s` is deprecated as of OpenStack Ocata " "All shell commands were moved to " "`novaclient.v2.shell` and will be automatically " "loaded.") % module_name warnings.warn(msg)
def _check_arguments(kwargs, release, deprecated_name, right_name=None): """Process deprecation of arguments. Checks presence of deprecated argument in kwargs, prints proper warning message, renames key to right one it needed. """ if deprecated_name in kwargs: if right_name: if right_name in kwargs: msg = _LW("The '%(old)s' argument is deprecated in " "%(release)s and its use may result in errors " "in future releases. As '%(new)s' is provided, " "the '%(old)s' argument will be ignored.") % { "old": deprecated_name, "release": release, "new": right_name } kwargs.pop(deprecated_name) else: msg = _LW("The '%(old)s' argument is deprecated in " "%(release)s and its use may result in errors in " "future releases. Use '%(right)s' instead.") % { "old": deprecated_name, "release": release, "right": right_name } kwargs[right_name] = kwargs.pop(deprecated_name) else: msg = _LW("The '%(old)s' argument is deprecated in %(release)s " "and its use may result in errors in future " "releases.") % { "old": deprecated_name, "release": release } # just ignore it kwargs.pop(deprecated_name) warnings.warn(msg)
def _check_arguments(kwargs, release, deprecated_name, right_name=None): """Process deprecation of arguments. Checks presence of deprecated argument in kwargs, prints proper warning message, renames key to right one it needed. """ if deprecated_name in kwargs: msg = _LW("The '%(old)s' argument is deprecated in %(release)s and " "its use may result in errors in future releases.") % { "old": deprecated_name, "release": release} if right_name: if right_name in kwargs: msg += _LW(" As '%(new)s' is provided, the '%(old)s' argument " "will be ignored.") % {"old": deprecated_name, "new": right_name} kwargs.pop(deprecated_name) else: msg += _LW(" Use '%s' instead.") % right_name kwargs[right_name] = kwargs.pop(deprecated_name) else: # just ignore it kwargs.pop(deprecated_name) warnings.warn(msg)
def get_api_version(version_string): """Returns checked APIVersion object""" version_string = str(version_string) if version_string in DEPRECATED_VERSIONS: LOG.warning( _LW("Version %(deprecated_version)s is deprecated, using " "alternative version %(alternative)s instead.") % {"deprecated_version": version_string, "alternative": DEPRECATED_VERSIONS[version_string]} ) version_string = DEPRECATED_VERSIONS[version_string] if strutils.is_int_like(version_string): version_string = "%s.0" % version_string api_version = APIVersion(version_string) check_major_version(api_version) return api_version
def get_api_version(version_string): """Returns checked APIVersion object""" version_string = str(version_string) if version_string in DEPRECATED_VERSIONS: LOG.warning( _LW("Version %(deprecated_version)s is deprecated, using " "alternative version %(alternative)s instead.") % {"deprecated_version": version_string, "alternative": DEPRECATED_VERSIONS[version_string]}) version_string = DEPRECATED_VERSIONS[version_string] if strutils.is_int_like(version_string): version_string = "%s.0" % version_string api_version = APIVersion(version_string) check_major_version(api_version) return api_version
def get_client_class(version): version = str(version) if version in DEPRECATED_VERSIONS: warnings.warn(_LW( "Version %(deprecated_version)s is deprecated, using " "alternative version %(alternative)s instead.") % {"deprecated_version": version, "alternative": DEPRECATED_VERSIONS[version]}) version = DEPRECATED_VERSIONS[version] try: return importutils.import_class( "novaclient.v%s.client.Client" % version) except ImportError: available_versions = _get_available_client_versions() msg = _("Invalid client version '%(version)s'. must be one of: " "%(keys)s") % {'version': version, 'keys': ', '.join(available_versions)} raise exceptions.UnsupportedVersion(msg)
def get_client_class(version): version = str(version) if version in DEPRECATED_VERSIONS: warnings.warn( _LW("Version %(deprecated_version)s is deprecated, using " "alternative version %(alternative)s instead.") % { "deprecated_version": version, "alternative": DEPRECATED_VERSIONS[version] }) version = DEPRECATED_VERSIONS[version] try: return importutils.import_class("novaclient.v%s.client.Client" % version) except ImportError: available_versions = _get_available_client_versions() msg = _("Invalid client version '%(version)s'. must be one of: " "%(keys)s") % { 'version': version, 'keys': ', '.join(available_versions) } raise exceptions.UnsupportedVersion(msg)
def get_client_class(version): version = str(version) if version in DEPRECATED_VERSIONS: warnings.warn(_LW( "Version %(deprecated_version)s is deprecated, using " "alternative version %(alternative)s instead.") % {"deprecated_version": version, "alternative": DEPRECATED_VERSIONS[version]}) version = DEPRECATED_VERSIONS[version] try: return importutils.import_class( "novaclient.v%s.client.Client" % version) except ImportError: # NOTE(andreykurilin): available clients version should not be # hardcoded, so let's discover them. matcher = re.compile(r"v[0-9_]*$") submodules = pkgutil.iter_modules(['novaclient']) available_versions = [ name[1:].replace("_", ".") for loader, name, ispkg in submodules if matcher.search(name)] msg = _("Invalid client version '%(version)s'. must be one of: " "%(keys)s") % {'version': version, 'keys': ', '.join(available_versions)} raise exceptions.UnsupportedVersion(msg)
def __init__(self, username=None, api_key=None, project_id=None, 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, os_cache=False, no_cache=True, http_log_debug=False, auth_system='keystone', auth_plugin=None, auth_token=None, cacert=None, tenant_id=None, user_id=None, connection_pool=False, session=None, auth=None, api_version=None, direct_use=True, **kwargs): """Initialization of Client object. :param str username: Username :param str api_key: API Key :param str project_id: Project ID :param str auth_url: Auth URL :param bool insecure: Allow insecure :param float timeout: API timeout, None or 0 disables :param str proxy_tenant_id: Tenant ID :param str proxy_token: Proxy Token :param str region_name: Region Name :param str endpoint_type: Endpoint Type :param str extensions: Exensions :param str service_type: Service Type :param str service_name: Service Name :param str volume_service_name: Volume Service Name :param bool timings: Timings :param str bypass_url: Bypass URL :param bool os_cache: OS cache :param bool no_cache: No cache :param bool http_log_debug: Enable debugging for HTTP connections :param str auth_system: Auth system :param str auth_plugin: Auth plugin :param str auth_token: Auth token :param str cacert: cacert :param str tenant_id: Tenant ID :param str user_id: User ID :param bool connection_pool: Use a connection pool :param str session: Session :param str auth: Auth :param api_version: Compute API version :type api_version: novaclient.api_versions.APIVersion """ if direct_use: import warnings warnings.warn( _LW("'novaclient.v2.client.Client' is not designed to be " "initialized directly. It is inner class of novaclient. " "Please, use 'novaclient.client.Client' instead. " "Related lp bug-report: 1493576")) # FIXME(comstud): Rename the api_key argument above when we # know it's not being used as keyword argument # NOTE(cyeoh): In the novaclient context (unlike Nova) the # project_id is not the same as the tenant_id. Here project_id # is a name (what the Nova API often refers to as a project or # tenant name) and tenant_id is a UUID (what the Nova API # often refers to as a project_id or tenant_id). password = api_key self.projectid = project_id self.tenant_id = tenant_id self.user_id = user_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) self.versions = versions.VersionManager(self) self.api_version = api_version or api_versions.APIVersion("2.0") # extensions self.agents = agents.AgentsManager(self) 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.fping = fping.FpingManager(self) self.volumes = volumes.VolumeManager(self) self.volume_snapshots = volume_snapshots.SnapshotManager(self) self.volume_types = volume_types.VolumeTypeManager(self) self.keypairs = keypairs.KeypairManager(self) self.networks = networks.NetworkManager(self) self.quota_classes = quota_classes.QuotaClassSetManager(self) self.quotas = quotas.QuotaSetManager(self) self.security_groups = security_groups.SecurityGroupManager(self) self.security_group_rules = \ security_group_rules.SecurityGroupRuleManager(self) self.security_group_default_rules = \ security_group_default_rules.SecurityGroupDefaultRuleManager(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.hypervisor_stats = hypervisors.HypervisorStatsManager(self) self.services = services.ServiceManager(self) self.fixed_ips = fixed_ips.FixedIPsManager(self) self.floating_ips_bulk = floating_ips_bulk.FloatingIPBulkManager(self) self.os_cache = os_cache or not no_cache self.availability_zones = \ availability_zones.AvailabilityZoneManager(self) self.server_groups = server_groups.ServerGroupsManager(self) self.server_migrations = \ server_migrations.ServerMigrationsManager(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._construct_http_client( username=username, password=password, user_id=user_id, project_id=project_id, tenant_id=tenant_id, auth_url=auth_url, auth_token=auth_token, insecure=insecure, timeout=timeout, auth_system=auth_system, auth_plugin=auth_plugin, 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, os_cache=self.os_cache, http_log_debug=http_log_debug, cacert=cacert, connection_pool=connection_pool, session=session, auth=auth, api_version=api_version, **kwargs)
def get_client_class(version): """Returns Client class based on given version.""" warnings.warn(_LW("'get_client_class' is deprecated. " "Please use `novaclient.client.Client` instead.")) _api_version, client_class = _get_client_class_and_version(version) return client_class
def __init__(self, username=None, api_key=None, project_id=None, 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, os_cache=False, no_cache=True, http_log_debug=False, auth_system='keystone', auth_plugin=None, auth_token=None, cacert=None, tenant_id=None, user_id=None, connection_pool=False, session=None, auth=None, api_version=None, direct_use=True, **kwargs): """Initialization of Client object. :param str username: Username :param str api_key: API Key :param str project_id: Project ID :param str auth_url: Auth URL :param bool insecure: Allow insecure :param float timeout: API timeout, None or 0 disables :param str proxy_tenant_id: Tenant ID :param str proxy_token: Proxy Token :param str region_name: Region Name :param str endpoint_type: Endpoint Type :param str extensions: Exensions :param str service_type: Service Type :param str service_name: Service Name :param str volume_service_name: Volume Service Name :param bool timings: Timings :param str bypass_url: Bypass URL :param bool os_cache: OS cache :param bool no_cache: No cache :param bool http_log_debug: Enable debugging for HTTP connections :param str auth_system: Auth system :param str auth_plugin: Auth plugin :param str auth_token: Auth token :param str cacert: cacert :param str tenant_id: Tenant ID :param str user_id: User ID :param bool connection_pool: Use a connection pool :param str session: Session :param str auth: Auth :param api_version: Compute API version :type api_version: novaclient.api_versions.APIVersion """ if direct_use: import warnings warnings.warn( _LW("'novaclient.v2.client.Client' is not designed to be " "initialized directly. It is inner class of novaclient. " "Please, use 'novaclient.client.Client' instead. " "Related lp bug-report: 1493576")) # FIXME(comstud): Rename the api_key argument above when we # know it's not being used as keyword argument # NOTE(cyeoh): In the novaclient context (unlike Nova) the # project_id is not the same as the tenant_id. Here project_id # is a name (what the Nova API often refers to as a project or # tenant name) and tenant_id is a UUID (what the Nova API # often refers to as a project_id or tenant_id). password = api_key self.projectid = project_id self.tenant_id = tenant_id self.user_id = user_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) self.versions = versions.VersionManager(self) self.api_version = api_version or api_versions.APIVersion("2.0") # extensions self.agents = agents.AgentsManager(self) 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.fping = fping.FpingManager(self) self.volumes = volumes.VolumeManager(self) self.volume_snapshots = volume_snapshots.SnapshotManager(self) self.volume_types = volume_types.VolumeTypeManager(self) self.keypairs = keypairs.KeypairManager(self) self.networks = networks.NetworkManager(self) self.quota_classes = quota_classes.QuotaClassSetManager(self) self.quotas = quotas.QuotaSetManager(self) self.security_groups = security_groups.SecurityGroupManager(self) self.security_group_rules = \ security_group_rules.SecurityGroupRuleManager(self) self.security_group_default_rules = \ security_group_default_rules.SecurityGroupDefaultRuleManager(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.hypervisor_stats = hypervisors.HypervisorStatsManager(self) self.services = services.ServiceManager(self) self.fixed_ips = fixed_ips.FixedIPsManager(self) self.floating_ips_bulk = floating_ips_bulk.FloatingIPBulkManager(self) self.os_cache = os_cache or not no_cache self.availability_zones = \ availability_zones.AvailabilityZoneManager(self) self.server_groups = server_groups.ServerGroupsManager(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._construct_http_client( username=username, password=password, user_id=user_id, project_id=project_id, tenant_id=tenant_id, auth_url=auth_url, auth_token=auth_token, insecure=insecure, timeout=timeout, auth_system=auth_system, auth_plugin=auth_plugin, 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, os_cache=self.os_cache, http_log_debug=http_log_debug, cacert=cacert, connection_pool=connection_pool, session=session, auth=auth, api_version=api_version, **kwargs)
def management_url(self): self.logger.warning( _LW("Property `management_url` is deprecated for SessionClient. " "Use `endpoint_override` instead.")) return self.endpoint_override
def management_url(self, value): self.logger.warning( _LW("Property `management_url` is deprecated for SessionClient. " "It should be set via `endpoint_override` variable while class" " initialization.")) self.endpoint_override = value
def check_headers(response, api_version): """Checks that 'X-OpenStack-Nova-API-Version' header in response.""" if api_version.ver_minor > 0 and HEADER_NAME not in response.headers: LOG.warning(_LW( ""))
def check_headers(response, api_version): """Checks that 'X-OpenStack-Nova-API-Version' header in response.""" if api_version.ver_minor > 0 and HEADER_NAME not in response.headers: LOG.warning(_LW(""))
def tenant_id(self): self.logger.warning(_LW("Property 'tenant_id' is deprecated since " "Ocata. Use 'project_id' instead.")) return self.project_id
def tenant_id(self): self.logger.warning( _LW("Property 'tenant_id' is deprecated since " "Ocata. Use 'project_id' instead.")) return self.project_id
def __enter__(self): self.logger.warning(_LW("NovaClient instance can't be used as a " "context manager since Ocata (deprecated " "behaviour) since it is redundant in case of " "SessionClient.")) return self
def set_management_url(self, url): self.logger.warning( _LW("Method `set_management_url` is deprecated since Ocata. " "Use `endpoint_override` argument instead while initializing " "novaclient's instance.")) self.client.set_management_url(url)
def _warn_missing_microversion_header(header_name): """Log a warning about missing microversion response header.""" LOG.warning(_LW( "Your request was processed by a Nova API which does not support " "microversions (%s header is missing from response). " "Warning: Response may be incorrect."), header_name)
def _warn_missing_microversion_header(header_name): """Log a warning about missing microversion response header.""" LOG.warning( _LW("Your request was processed by a Nova API which does not support " "microversions (%s header is missing from response). " "Warning: Response may be incorrect."), header_name)