本文整理汇总了Python中neutron.db._utils.resource_fields函数的典型用法代码示例。如果您正苦于以下问题:Python resource_fields函数的具体用法?Python resource_fields怎么用?Python resource_fields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resource_fields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_flavor_next_provider
def get_flavor_next_provider(
self, context, flavor_id, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False
):
"""From flavor, choose service profile and find provider for driver."""
with db_api.context_manager.reader.using(context):
bind_qry = context.session.query(flavor_models.FlavorServiceProfileBinding)
binding = bind_qry.filter_by(flavor_id=flavor_id).first()
if not binding:
raise ext_flavors.FlavorServiceProfileBindingNotFound(sp_id="", fl_id=flavor_id)
# Get the service profile from the first binding
# TODO(jwarendt) Should become a scheduling framework instead
sp_db = self._get_service_profile(context, binding["service_profile_id"])
if not sp_db.enabled:
raise ext_flavors.ServiceProfileDisabled()
LOG.debug("Found driver %s.", sp_db.driver)
service_type_manager = sdb.ServiceTypeManager.get_instance()
providers = service_type_manager.get_service_providers(context, filters={"driver": sp_db.driver})
if not providers:
raise ext_flavors.ServiceProfileDriverNotFound(driver=sp_db.driver)
LOG.debug("Found providers %s.", providers)
res = {"driver": sp_db.driver, "provider": providers[0].get("name")}
return [db_utils.resource_fields(res, fields)]
示例2: _response
def _response(network_id, tenant_id, fields=None):
"""Build response for auto-allocated network."""
res = {
'id': network_id,
'tenant_id': tenant_id
}
return db_utils.resource_fields(res, fields)
示例3: _make_metering_label_rule_dict
def _make_metering_label_rule_dict(metering_label_rule, fields=None):
res = {'id': metering_label_rule['id'],
'metering_label_id': metering_label_rule['metering_label_id'],
'direction': metering_label_rule['direction'],
'remote_ip_prefix': metering_label_rule['remote_ip_prefix'],
'excluded': metering_label_rule['excluded']}
return db_utils.resource_fields(res, fields)
示例4: _make_metering_label_dict
def _make_metering_label_dict(metering_label, fields=None):
res = {'id': metering_label['id'],
'name': metering_label['name'],
'description': metering_label['description'],
'shared': metering_label['shared'],
'tenant_id': metering_label['tenant_id']}
return db_utils.resource_fields(res, fields)
示例5: _make_subnet_dict
def _make_subnet_dict(self, subnet, fields=None, context=None):
res = {'id': subnet['id'],
'name': subnet['name'],
'tenant_id': subnet['tenant_id'],
'network_id': subnet['network_id'],
'ip_version': subnet['ip_version'],
'cidr': subnet['cidr'],
'subnetpool_id': subnet.get('subnetpool_id'),
'allocation_pools': [{'start': pool['first_ip'],
'end': pool['last_ip']}
for pool in subnet['allocation_pools']],
'gateway_ip': subnet['gateway_ip'],
'enable_dhcp': subnet['enable_dhcp'],
'ipv6_ra_mode': subnet['ipv6_ra_mode'],
'ipv6_address_mode': subnet['ipv6_address_mode'],
'dns_nameservers': [dns['address']
for dns in subnet['dns_nameservers']],
'host_routes': [{'destination': route['destination'],
'nexthop': route['nexthop']}
for route in subnet['routes']],
}
# The shared attribute for a subnet is the same as its parent network
res['shared'] = self._is_network_shared(context, subnet.networks)
# Call auxiliary extend functions, if any
self._apply_dict_extend_functions(attributes.SUBNETS, res, subnet)
return db_utils.resource_fields(res, fields)
示例6: get_flavor_next_provider
def get_flavor_next_provider(
self, context, flavor_id, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False
):
"""From flavor, choose service profile and find provider for driver."""
objs = obj_flavor.FlavorServiceProfileBinding.get_objects(context, flavor_id=flavor_id)
if not objs:
raise ext_flavors.FlavorServiceProfileBindingNotFound(sp_id="", fl_id=flavor_id)
# Get the service profile from the first binding
# TODO(jwarendt) Should become a scheduling framework instead
sp_obj = self._get_service_profile(context, objs[0].service_profile_id)
if not sp_obj.enabled:
raise ext_flavors.ServiceProfileDisabled()
LOG.debug("Found driver %s.", sp_obj.driver)
service_type_manager = sdb.ServiceTypeManager.get_instance()
providers = service_type_manager.get_service_providers(context, filters={"driver": sp_obj.driver})
if not providers:
raise ext_flavors.ServiceProfileDriverNotFound(driver=sp_obj.driver)
LOG.debug("Found providers %s.", providers)
res = {"driver": sp_obj.driver, "provider": providers[0].get("name")}
return [db_utils.resource_fields(res, fields)]
示例7: get_flavor_service_profile
def get_flavor_service_profile(context, service_profile_id, flavor_id, fields=None):
if not obj_flavor.FlavorServiceProfileBinding.objects_exist(
context, service_profile_id=service_profile_id, flavor_id=flavor_id
):
raise ext_flavors.FlavorServiceProfileBindingNotFound(sp_id=service_profile_id, fl_id=flavor_id)
res = {"service_profile_id": service_profile_id, "flavor_id": flavor_id}
return db_utils.resource_fields(res, fields)
示例8: _make_address_scope_dict
def _make_address_scope_dict(address_scope, fields=None):
res = {'id': address_scope['id'],
'name': address_scope['name'],
'tenant_id': address_scope['tenant_id'],
'shared': address_scope['shared'],
'ip_version': address_scope['ip_version']}
return db_utils.resource_fields(res, fields)
示例9: _make_networks_dict
def _make_networks_dict(self, networks, context):
nets = []
for network in networks:
if network.mtu is None:
# TODO(ivar): also refactor this to run for bulk networks
network.mtu = self._get_network_mtu(network, validate=False)
res = {'id': network['id'],
'name': network['name'],
'tenant_id': network['tenant_id'],
'admin_state_up': network['admin_state_up'],
'mtu': network.get('mtu', n_const.DEFAULT_NETWORK_MTU),
'status': network['status'],
'subnets': [subnet['id']
for subnet in network['subnets']]}
res['shared'] = self._is_network_shared(context,
network.rbac_entries)
nets.append((res, network))
# Bulk extend first
resource_extend.apply_funcs(net_def.COLLECTION_NAME + '_BULK', nets,
None)
result = []
for res, network in nets:
res[api_plus.BULK_EXTENDED] = True
resource_extend.apply_funcs(net_def.COLLECTION_NAME, res, network)
res.pop(api_plus.BULK_EXTENDED, None)
result.append(db_utils.resource_fields(res, []))
return result
示例10: _make_service_profile_dict
def _make_service_profile_dict(sp_obj, fields=None):
res = {'id': sp_obj['id'],
'description': sp_obj['description'],
'driver': sp_obj['driver'],
'enabled': sp_obj['enabled'],
'metainfo': sp_obj['metainfo'],
'flavors': list(sp_obj['flavor_ids'])}
return db_utils.resource_fields(res, fields)
示例11: get_service_providers
def get_service_providers(self, filters=None, fields=None):
return [db_utils.resource_fields({'service_type': k[0],
'name': k[1],
'driver': v['driver'],
'default': v['default']},
fields)
for k, v in self.providers.items()
if self._check_entry(k, v, filters)]
示例12: _make_flavor_dict
def _make_flavor_dict(flavor_obj, fields=None):
res = {'id': flavor_obj['id'],
'name': flavor_obj['name'],
'description': flavor_obj['description'],
'service_type': flavor_obj['service_type'],
'enabled': flavor_obj['enabled'],
'service_profiles': list(flavor_obj['service_profile_ids'])}
return db_utils.resource_fields(res, fields)
示例13: _make_security_group_dict
def _make_security_group_dict(self, security_group, fields=None):
res = {'id': security_group['id'],
'name': security_group['name'],
'tenant_id': security_group['tenant_id'],
'description': security_group['description']}
res['security_group_rules'] = [self._make_security_group_rule_dict(r)
for r in security_group.rules]
self._apply_dict_extend_functions(ext_sg.SECURITYGROUPS, res,
security_group)
return db_utils.resource_fields(res, fields)
示例14: _make_service_profile_dict
def _make_service_profile_dict(sp_obj, fields=None):
res = {
"id": sp_obj["id"],
"description": sp_obj["description"],
"driver": sp_obj["driver"],
"enabled": sp_obj["enabled"],
"metainfo": sp_obj["metainfo"],
"flavors": list(sp_obj["flavor_ids"]),
}
return db_utils.resource_fields(res, fields)
示例15: _make_flavor_dict
def _make_flavor_dict(flavor_obj, fields=None):
res = {
"id": flavor_obj["id"],
"name": flavor_obj["name"],
"description": flavor_obj["description"],
"service_type": flavor_obj["service_type"],
"enabled": flavor_obj["enabled"],
"service_profiles": list(flavor_obj["service_profile_ids"]),
}
return db_utils.resource_fields(res, fields)