本文整理汇总了Python中trove.common.utils.get_id_from_href函数的典型用法代码示例。如果您正苦于以下问题:Python get_id_from_href函数的具体用法?Python get_id_from_href怎么用?Python get_id_from_href使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_id_from_href函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
def create(self, req, body, tenant_id):
# TODO(hub-cap): turn this into middleware
LOG.info(_LI("Creating a database instance for tenant '%s'"),
tenant_id)
LOG.debug("req : '%s'\n\n", strutils.mask_password(req))
LOG.debug("body : '%s'\n\n", strutils.mask_password(body))
context = req.environ[wsgi.CONTEXT_KEY]
context.notification = notification.DBaaSInstanceCreate(context,
request=req)
datastore_args = body['instance'].get('datastore', {})
datastore, datastore_version = (
datastore_models.get_datastore_version(**datastore_args))
image_id = datastore_version.image_id
name = body['instance']['name']
flavor_ref = body['instance']['flavorRef']
flavor_id = utils.get_id_from_href(flavor_ref)
configuration = self._configuration_parse(context, body)
databases = populate_validated_databases(
body['instance'].get('databases', []))
database_names = [database.get('_name', '') for database in databases]
users = None
try:
users = populate_users(body['instance'].get('users', []),
database_names)
except ValueError as ve:
raise exception.BadRequest(msg=ve)
if 'volume' in body['instance']:
volume_info = body['instance']['volume']
volume_size = int(volume_info['size'])
volume_type = volume_info.get('type')
else:
volume_size = None
volume_type = None
if 'restorePoint' in body['instance']:
backupRef = body['instance']['restorePoint']['backupRef']
backup_id = utils.get_id_from_href(backupRef)
else:
backup_id = None
availability_zone = body['instance'].get('availability_zone')
nics = body['instance'].get('nics')
slave_of_id = body['instance'].get('replica_of',
# also check for older name
body['instance'].get('slave_of'))
replica_count = body['instance'].get('replica_count')
instance = models.Instance.create(context, name, flavor_id,
image_id, databases, users,
datastore, datastore_version,
volume_size, backup_id,
availability_zone, nics,
configuration, slave_of_id,
replica_count=replica_count,
volume_type=volume_type)
view = views.InstanceDetailView(instance, req=req)
return wsgi.Result(view.data(), 200)
示例2: create
def create(self, req, body, tenant_id):
# TODO(hub-cap): turn this into middleware
LOG.info(_("Creating a database instance for tenant '%s'") % tenant_id)
LOG.info(logging.mask_password(_("req : '%s'\n\n") % req))
LOG.info(logging.mask_password(_("body : '%s'\n\n") % body))
context = req.environ[wsgi.CONTEXT_KEY]
datastore_args = body['instance'].get('datastore', {})
datastore, datastore_version = (
datastore_models.get_datastore_version(**datastore_args))
image_id = datastore_version.image_id
name = body['instance']['name']
flavor_ref = body['instance']['flavorRef']
flavor_id = utils.get_id_from_href(flavor_ref)
configuration = self._configuration_parse(context, body)
databases = populate_validated_databases(
body['instance'].get('databases', []))
database_names = [database.get('_name', '') for database in databases]
users = None
try:
users = populate_users(body['instance'].get('users', []),
database_names)
except ValueError as ve:
raise exception.BadRequest(msg=ve)
if 'volume' in body['instance']:
volume_size = int(body['instance']['volume']['size'])
else:
volume_size = None
if 'restorePoint' in body['instance']:
backupRef = body['instance']['restorePoint']['backupRef']
backup_id = utils.get_id_from_href(backupRef)
else:
backup_id = None
if 'availability_zone' in body['instance']:
availability_zone = body['instance']['availability_zone']
else:
availability_zone = None
if 'nics' in body['instance']:
nics = body['instance']['nics']
else:
nics = None
if 'slave_of' in body['instance']:
slave_of_id = body['instance']['slave_of']
else:
slave_of_id = None
instance = models.Instance.create(context, name, flavor_id,
image_id, databases, users,
datastore, datastore_version,
volume_size, backup_id,
availability_zone, nics,
configuration, slave_of_id)
view = views.InstanceDetailView(instance, req=req)
return wsgi.Result(view.data(), 200)
示例3: create
def create(self, req, body, tenant_id):
# TODO(hub-cap): turn this into middleware
LOG.info(_("Creating a database instance for tenant '%s'") % tenant_id)
LOG.info(_("req : '%s'\n\n") % req)
LOG.info(_("body : '%s'\n\n") % body)
context = req.environ[wsgi.CONTEXT_KEY]
# Set the service type to mysql if its not in the request
service_type = body["instance"].get("service_type") or CONF.service_type
service = models.ServiceImage.find_by(service_name=service_type)
image_id = service["image_id"]
name = body["instance"]["name"]
flavor_ref = body["instance"]["flavorRef"]
flavor_id = utils.get_id_from_href(flavor_ref)
databases = populate_validated_databases(body["instance"].get("databases", []))
users = None
try:
users = populate_users(body["instance"].get("users", []))
except ValueError as ve:
raise exception.BadRequest(msg=ve)
if "volume" in body["instance"]:
volume_size = int(body["instance"]["volume"]["size"])
else:
volume_size = None
if "restorePoint" in body["instance"]:
backupRef = body["instance"]["restorePoint"]["backupRef"]
backup_id = utils.get_id_from_href(backupRef)
else:
backup_id = None
if "availability_zone" in body["instance"]:
availability_zone = body["instance"]["availability_zone"]
else:
availability_zone = None
instance = models.Instance.create(
context,
name,
flavor_id,
image_id,
databases,
users,
service_type,
volume_size,
backup_id,
availability_zone,
)
view = views.InstanceDetailView(instance, req=req)
return wsgi.Result(view.data(), 200)
示例4: _create_resources
def _create_resources():
# parse the ID from the Ref
instance_id = utils.get_id_from_href(instance)
# verify that the instance exists and can perform actions
from trove.instance.models import Instance
instance_model = Instance.load(context, instance_id)
instance_model.validate_can_perform_action()
cls.verify_swift_auth_token(context)
try:
db_info = DBBackup.create(name=name,
description=description,
tenant_id=context.tenant,
state=BackupState.NEW,
instance_id=instance_id,
deleted=False)
except exception.InvalidModelError as ex:
LOG.exception("Unable to create Backup record:")
raise exception.BackupCreationError(str(ex))
backup_info = {'id': db_info.id,
'name': name,
'description': description,
'instance_id': instance_id,
'backup_type': db_info.backup_type,
'checksum': db_info.checksum,
}
api.API(context).create_backup(backup_info, instance_id)
return db_info
示例5: _parse_grow_item
def _parse_grow_item(self, item):
used_keys = []
def _check_option(key, required=False, valid_values=None):
if required and key not in item:
raise exception.TroveError(
_("An instance with the options %(given)s is missing " "the MongoDB required option %(expected)s.")
% {"given": item.keys(), "expected": key}
)
value = item.get(key, None)
if valid_values and value not in valid_values:
raise exception.TroveError(
_("The value %(value)s for key %(key)s is invalid. " "Allowed values are %(valid)s.")
% {"value": value, "key": key, "valid": valid_values}
)
used_keys.append(key)
return value
flavor_id = utils.get_id_from_href(_check_option("flavorRef", required=True))
volume_size = int(_check_option("volume", required=True)["size"])
instance_type = _check_option("type", required=True, valid_values=["replica", "query_router"])
name = _check_option("name")
related_to = _check_option("related_to")
unused_keys = list(set(item.keys()).difference(set(used_keys)))
if unused_keys:
raise exception.TroveError(_("The arguments %s are not supported by MongoDB.") % unused_keys)
instance = {"flavor_id": flavor_id, "volume_size": volume_size, "instance_type": instance_type}
if name:
instance["name"] = name
if related_to:
instance["related_to"] = related_to
return instance
示例6: action
def action(self, context, req, action, param):
if action == 'grow':
context.notification = DBaaSClusterGrow(context, request=req)
with StartNotification(context, cluster_id=self.id):
instances = []
for node in param:
instance = {
'flavor_id': utils.get_id_from_href(node['flavorRef'])
}
if 'name' in node:
instance['name'] = node['name']
if 'volume' in node:
instance['volume_size'] = int(node['volume']['size'])
if 'modules' in node:
instance['modules'] = node['modules']
if 'nics' in node:
instance['nics'] = node['nics']
if 'availability_zone' in node:
instance['availability_zone'] = (
node['availability_zone'])
instances.append(instance)
return self.grow(instances)
elif action == 'shrink':
context.notification = DBaaSClusterShrink(context, request=req)
with StartNotification(context, cluster_id=self.id):
instance_ids = [instance['id'] for instance in param]
return self.shrink(instance_ids)
else:
raise exception.BadRequest(_("Action %s not supported") % action)
示例7: create
def create(self, req, body, tenant_id):
# TODO(hub-cap): turn this into middleware
LOG.info(_("Creating a database instance for tenant '%s'") % tenant_id)
LOG.info(_("req : '%s'\n\n") % req)
LOG.info(_("body : '%s'\n\n") % body)
context = req.environ[wsgi.CONTEXT_KEY]
# Set the service type to mysql if its not in the request
service_type = (body['instance'].get('service_type') or
CONF.service_type)
service = models.ServiceImage.find_by(service_name=service_type)
image_id = service['image_id']
name = body['instance']['name']
flavor_ref = body['instance']['flavorRef']
flavor_id = utils.get_id_from_href(flavor_ref)
databases = populate_validated_databases(
body['instance'].get('databases', []))
database_names = [database.get('_name', '') for database in databases]
users = None
try:
users = populate_users(body['instance'].get('users', []),
database_names)
except ValueError as ve:
raise exception.BadRequest(msg=ve)
if 'volume' in body['instance']:
volume_size = int(body['instance']['volume']['size'])
else:
volume_size = None
if 'restorePoint' in body['instance']:
backupRef = body['instance']['restorePoint']['backupRef']
backup_id = utils.get_id_from_href(backupRef)
else:
backup_id = None
if 'availability_zone' in body['instance']:
availability_zone = body['instance']['availability_zone']
else:
availability_zone = None
instance = models.Instance.create(context, name, flavor_id,
image_id, databases, users,
service_type, volume_size,
backup_id, availability_zone)
view = views.InstanceDetailView(instance, req=req)
return wsgi.Result(view.data(), 200)
示例8: _action_resize_flavor
def _action_resize_flavor(self, context, req, instance, flavorRef):
context.notification = notification.DBaaSInstanceResizeInstance(
context, request=req)
new_flavor_id = utils.get_id_from_href(flavorRef)
with StartNotification(context, instance_id=instance.id,
new_flavor_id=new_flavor_id):
instance.resize_flavor(new_flavor_id)
return wsgi.Result(None, 202)
示例9: _parse_grow_item
def _parse_grow_item(self, item):
used_keys = []
def _check_option(key, required=False, valid_values=None,
flatten_value=False):
if required and key not in item:
raise exception.TroveError(
_('An instance with the options %(given)s is missing '
'the MongoDB required option %(expected)s.')
% {'given': item.keys(), 'expected': key}
)
value = item.get(key, None)
if value and flatten_value and isinstance(value, list):
value = ','.join(value)
if valid_values and value not in valid_values:
raise exception.TroveError(
_("The value '%(value)s' for key '%(key)s' is invalid. "
"Allowed values are %(valid)s.")
% {'value': value, 'key': key, 'valid': valid_values}
)
used_keys.append(key)
return value
flavor_id = utils.get_id_from_href(_check_option('flavorRef',
required=True))
volume_size = int(_check_option('volume', required=True)['size'])
instance_type = _check_option('type', required=True,
valid_values=['replica',
'query_router'],
flatten_value=True)
name = _check_option('name')
related_to = _check_option('related_to')
nics = _check_option('nics')
availability_zone = _check_option('availability_zone')
unused_keys = list(set(item.keys()).difference(set(used_keys)))
if unused_keys:
raise exception.TroveError(
_('The arguments %s are not supported by MongoDB.')
% unused_keys
)
instance = {'flavor_id': flavor_id,
'volume_size': volume_size,
'instance_type': instance_type}
if name:
instance['name'] = name
if related_to:
instance['related_to'] = related_to
if nics:
instance['nics'] = nics
if availability_zone:
instance['availability_zone'] = availability_zone
return instance
示例10: _action_grow_cluster
def _action_grow_cluster(self, cluster, body):
nodes = body["grow"]
instances = []
for node in nodes:
instance = {"flavor_id": utils.get_id_from_href(node["flavorRef"])}
if "name" in node:
instance["name"] = node["name"]
if "volume" in node:
instance["volume_size"] = int(node["volume"]["size"])
instances.append(instance)
return cluster.grow(instances)
示例11: _action_grow_cluster
def _action_grow_cluster(self, cluster, body):
nodes = body['grow']
instances = []
for node in nodes:
instance = {
'flavor_id': utils.get_id_from_href(node['flavorRef'])
}
if 'name' in node:
instance['name'] = node['name']
instances.append(instance)
return cluster.grow(instances)
示例12: create
def create(self, req, body, tenant_id):
LOG.debug("Creating a Cluster for Tenant '%s'" % tenant_id)
LOG.info(_("req : '%s'\n\n") % req)
LOG.info(_("body : '%s'\n\n") % body)
context = req.environ[wsgi.CONTEXT_KEY]
name = body['cluster']['name']
datastore_args = body['cluster'].get('datastore', {})
datastore, datastore_version = (
datastore_models.get_datastore_version(**datastore_args))
# TODO(saurabhs): add extended_properties to apischema
extended_properties = body['cluster'].get('extended_properties', {})
try:
clusters_enabled = (CONF.get(datastore_version.manager)
.get('cluster_support'))
except NoSuchOptError:
clusters_enabled = False
if not clusters_enabled:
raise exception.ClusterDatastoreNotSupported(
datastore=datastore.name,
datastore_version=datastore_version.name)
nodes = body['cluster']['instances']
instances = []
for node in nodes:
flavor_id = utils.get_id_from_href(node['flavorRef'])
volume_size = volume_type = nics = availability_zone = None
if 'volume' in node:
volume_size = int(node['volume']['size'])
volume_type = node['volume'].get('volume_type')
if 'nics' in node:
nics = node['nics']
if 'availability_zone' in node:
availability_zone = node['availability_zone']
instances.append({"flavor_id": flavor_id,
"volume_size": volume_size,
"volume_type": volume_type,
"nics": nics,
"availability_zone": availability_zone})
context.notification = notification.DBaaSClusterCreate(context,
request=req)
with StartNotification(context, name=name, datastore=datastore.name,
datastore_version=datastore_version.name):
cluster = models.Cluster.create(context, name, datastore,
datastore_version, instances,
extended_properties)
view = views.load_view(cluster, req=req, load_servers=False)
return wsgi.Result(view.data(), 200)
示例13: _create_resources
def _create_resources():
# parse the ID from the Ref
instance_id = utils.get_id_from_href(instance)
# verify that the instance exists and can perform actions
from trove.instance.models import Instance
instance_model = Instance.load(context, instance_id)
instance_model.validate_can_perform_action()
cls.validate_can_perform_action(
instance_model, 'backup_create')
cls.verify_swift_auth_token(context)
if instance_model.cluster_id is not None:
raise exception.ClusterInstanceOperationNotSupported()
ds = instance_model.datastore
ds_version = instance_model.datastore_version
parent = None
if parent_id:
# Look up the parent info or fail early if not found or if
# the user does not have access to the parent.
_parent = cls.get_by_id(context, parent_id)
parent = {
'location': _parent.location,
'checksum': _parent.checksum,
}
try:
db_info = DBBackup.create(name=name,
description=description,
tenant_id=context.tenant,
state=BackupState.NEW,
instance_id=instance_id,
parent_id=parent_id,
datastore_version_id=ds_version.id,
deleted=False)
except exception.InvalidModelError as ex:
LOG.exception(_("Unable to create backup record for "
"instance: %s"), instance_id)
raise exception.BackupCreationError(str(ex))
backup_info = {'id': db_info.id,
'name': name,
'description': description,
'instance_id': instance_id,
'backup_type': db_info.backup_type,
'checksum': db_info.checksum,
'parent': parent,
'datastore': ds.name,
'datastore_version': ds_version.name,
}
api.API(context).create_backup(backup_info, instance_id)
return db_info
示例14: _action_grow_cluster
def _action_grow_cluster(self, cluster, body):
nodes = body['grow']
instances = []
for node in nodes:
instance = {
'flavor_id': utils.get_id_from_href(node['flavorRef'])
}
if 'name' in node:
instance['name'] = node['name']
if 'volume' in node:
instance['volume_size'] = int(node['volume']['size'])
if 'nics' in node:
instance['nics'] = node['nics']
if 'availability_zone' in node:
instance['availability_zone'] = node['availability_zone']
instances.append(instance)
return cluster.grow(instances)
示例15: create
def create(self, req, body, tenant_id):
LOG.debug("Creating a Cluster for Tenant '%s'" % tenant_id)
LOG.info(_("req : '%s'\n\n") % req)
LOG.info(_("body : '%s'\n\n") % body)
context = req.environ[wsgi.CONTEXT_KEY]
name = body["cluster"]["name"]
datastore_args = body["cluster"].get("datastore", {})
datastore, datastore_version = datastore_models.get_datastore_version(**datastore_args)
try:
clusters_enabled = CONF.get(datastore_version.manager).get("cluster_support")
except NoSuchOptError:
clusters_enabled = False
if not clusters_enabled:
raise exception.ClusterDatastoreNotSupported(
datastore=datastore.name, datastore_version=datastore_version.name
)
nodes = body["cluster"]["instances"]
instances = []
for node in nodes:
flavor_id = utils.get_id_from_href(node["flavorRef"])
volume_size = nics = availability_zone = None
if "volume" in node:
volume_size = int(node["volume"]["size"])
if "nics" in node:
nics = node["nics"]
if "availability_zone" in node:
availability_zone = node["availability_zone"]
instances.append(
{
"flavor_id": flavor_id,
"volume_size": volume_size,
"nics": nics,
"availability_zone": availability_zone,
}
)
cluster = models.Cluster.create(context, name, datastore, datastore_version, instances)
view = views.load_view(cluster, req=req, load_servers=False)
return wsgi.Result(view.data(), 200)