本文整理汇总了Python中neutron.api.v2.attributes.is_attr_set函数的典型用法代码示例。如果您正苦于以下问题:Python is_attr_set函数的具体用法?Python is_attr_set怎么用?Python is_attr_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_attr_set函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_port
def create_port(self, context, port):
if attr.is_attr_set(port['port'][psec.PORTSECURITY]):
self._enforce_set_auth(context, port,
self.port_security_enabled_create)
p = port['port']
with context.session.begin(subtransactions=True):
p[ext_sg.SECURITYGROUPS] = self._get_security_groups_on_port(
context, port)
neutron_db = super(PortSecurityTestPlugin, self).create_port(
context, port)
p.update(neutron_db)
(port_security, has_ip) = self._determine_port_security_and_has_ip(
context, p)
p[psec.PORTSECURITY] = port_security
self._process_port_security_create(context, p)
if (attr.is_attr_set(p.get(ext_sg.SECURITYGROUPS)) and
not (port_security and has_ip)):
raise psec.PortSecurityAndIPRequiredForSecurityGroups()
# Port requires ip and port_security enabled for security group
if has_ip and port_security:
self._ensure_default_security_group_on_port(context, port)
if (p.get(ext_sg.SECURITYGROUPS) and p[psec.PORTSECURITY]):
self._process_port_create_security_group(
context, p, p[ext_sg.SECURITYGROUPS])
self._extend_port_port_security_dict(context, p)
return port['port']
示例2: create_subnet
def create_subnet(self, context, subnet):
s = subnet["subnet"]
cidr = s.get("cidr", attributes.ATTR_NOT_SPECIFIED)
prefixlen = s.get("prefixlen", attributes.ATTR_NOT_SPECIFIED)
has_cidr = attributes.is_attr_set(cidr)
has_prefixlen = attributes.is_attr_set(prefixlen)
if has_cidr and has_prefixlen:
msg = _("cidr and prefixlen must not be supplied together")
raise n_exc.BadRequest(resource="subnets", msg=msg)
if has_cidr:
# turn the CIDR into a proper subnet
net = netaddr.IPNetwork(s["cidr"])
subnet["subnet"]["cidr"] = "%s/%s" % (net.network, net.prefixlen)
s["tenant_id"] = self._get_tenant_id_for_create(context, s)
subnetpool_id = self._get_subnetpool_id(s)
if not subnetpool_id:
if not has_cidr:
msg = _("A cidr must be specified in the absence of a " "subnet pool")
raise n_exc.BadRequest(resource="subnets", msg=msg)
# Create subnet from the implicit(AKA null) pool
created_subnet = self._create_subnet_from_implicit_pool(context, subnet)
else:
created_subnet = self._create_subnet_from_pool(context, subnet, subnetpool_id)
# If this subnet supports auto-addressing, then update any
# internal ports on the network with addresses for this subnet.
if ipv6_utils.is_auto_address_subnet(created_subnet):
self._add_auto_addrs_on_network_ports(context, created_subnet)
return created_subnet
示例3: create_device_template
def create_device_template(self, context, device_template):
template = device_template['device_template']
LOG.debug(_('template %s'), template)
infra_driver = template.get('infra_driver')
if not attributes.is_attr_set(infra_driver):
LOG.debug(_('hosting device driver must be specified'))
raise servicevm.InfraDriverNotSpecified()
if infra_driver not in cfg.CONF.servicevm.infra_driver:
LOG.debug(_('unknown hosting device driver '
'%(infra_driver)s in %(drivers)s'),
{'infra_driver': infra_driver,
'drivers': cfg.CONF.servicevm.infra_driver})
raise servicevm.InvalidInfraDriver(infra_driver=infra_driver)
service_types = template.get('service_types')
if not attributes.is_attr_set(service_types):
LOG.debug(_('service type must be specified'))
raise servicevm.ServiceTypesNotSpecified()
for service_type in service_types:
# TODO(yamahata):
# framework doesn't know what services are valid for now.
# so doesn't check it here yet.
pass
self._device_manager.invoke(
infra_driver, 'create_device_template_pre', plugin=self,
context=context, device_template=device_template)
return super(ServiceVMPlugin, self).create_device_template(
context, device_template)
示例4: _process_dvr_port_binding
def _process_dvr_port_binding(self, mech_context, context, attrs):
binding = mech_context.binding
host = attrs and attrs.get(portbindings.HOST_ID)
host_set = attributes.is_attr_set(host)
vnic_type = attrs and attrs.get(portbindings.VNIC_TYPE)
vnic_type_set = attributes.is_attr_set(vnic_type)
profile = attrs and attrs.get(portbindings.PROFILE)
profile_set = profile is not attributes.ATTR_NOT_SPECIFIED
if binding.vif_type != portbindings.VIF_TYPE_UNBOUND:
if (not host_set and not vnic_type_set and
not profile_set and binding.segment):
return False
self._delete_port_binding(mech_context)
if host_set:
binding.host = host
if binding.host:
self.mechanism_manager.bind_port(mech_context)
return True
示例5: _process_portbindings_create_and_update
def _process_portbindings_create_and_update(self, context, port_data,
port):
binding_profile = port.get(portbindings.PROFILE)
binding_profile_set = attr.is_attr_set(binding_profile)
if not binding_profile_set and binding_profile is not None:
del port[portbindings.PROFILE]
binding_vnic = port.get(portbindings.VNIC_TYPE)
binding_vnic_set = attr.is_attr_set(binding_vnic)
if not binding_vnic_set and binding_vnic is not None:
del port[portbindings.VNIC_TYPE]
host = port_data.get(portbindings.HOST_ID)
host_set = attr.is_attr_set(host)
with context.session.begin(subtransactions=True):
bind_port = context.session.query(
models.PortBinding).filter_by(port_id=port['id']).first()
if host_set:
if not bind_port:
context.session.add(models.PortBinding(
port_id=port['id'],
host=host,
vif_type=self.vif_type))
else:
bind_port.host = host
else:
host = bind_port.host if bind_port else None
self._extend_port_dict_binding_host(port, host)
示例6: _determine_port_security_and_has_ip
def _determine_port_security_and_has_ip(self, context, port):
"""Returns a tuple of booleans (port_security_enabled, has_ip).
Port_security is the value associated with the port if one is present
otherwise the value associated with the network is returned. has_ip is
if the port is associated with an ip or not.
"""
has_ip = self._ip_on_port(port)
# we don't apply security groups for dhcp, router
if (port.get('device_owner') and
port['device_owner'].startswith('network:')):
return (False, has_ip)
if attrs.is_attr_set(port.get(psec.PORTSECURITY)):
port_security_enabled = port[psec.PORTSECURITY]
# If port has an ip and security_groups are passed in
# conveniently set port_security_enabled to true this way
# user doesn't also have to pass in port_security_enabled=True
# when creating ports.
elif (has_ip and attrs.is_attr_set(port.get('security_groups'))):
port_security_enabled = True
else:
port_security_enabled = self._get_network_security_binding(
context, port['network_id'])
return (port_security_enabled, has_ip)
示例7: _save_subnet
def _save_subnet(self, context,
network,
subnet_args,
dns_nameservers,
host_routes,
allocation_pools):
allocation_pools = self._prepare_allocation_pools(context,
allocation_pools,
subnet_args)
self._validate_subnet_cidr(context, network, subnet_args['cidr'])
self._validate_network_subnetpools(network,
subnet_args['subnetpool_id'],
subnet_args['ip_version'])
subnet = models_v2.Subnet(**subnet_args)
context.session.add(subnet)
if attributes.is_attr_set(dns_nameservers):
for addr in dns_nameservers:
ns = models_v2.DNSNameServer(address=addr,
subnet_id=subnet.id)
context.session.add(ns)
if attributes.is_attr_set(host_routes):
for rt in host_routes:
route = models_v2.SubnetRoute(
subnet_id=subnet.id,
destination=rt['destination'],
nexthop=rt['nexthop'])
context.session.add(route)
self._save_allocation_pools(context, subnet, allocation_pools)
return subnet
示例8: process_create_policy_target_group
def process_create_policy_target_group(self, session, data, result):
data = data['policy_target_group']
proxied = data.get('proxied_group_id')
if attributes.is_attr_set(proxied):
# Set value for proxied group
record = (session.query(db.GroupProxyMapping).filter_by(
policy_target_group_id=proxied).first())
if record:
if record.proxy_group_id:
raise driver_proxy_group.InvalidProxiedGroup(
group_id=proxied)
record.proxy_group_id = result['id']
else:
# Record may not exist for that PTG yet
record = db.GroupProxyMapping(
policy_target_group_id=proxied,
proxy_group_id=result['id'],
proxied_group_id=None)
session.add(record)
if not attributes.is_attr_set(data.get('proxy_type')):
data['proxy_type'] = driver_proxy_group.DEFAULT_PROXY_TYPE
record = (session.query(db.GroupProxyMapping).filter_by(
policy_target_group_id=result['id']).one())
record.proxy_type = data['proxy_type']
result['proxy_type'] = data['proxy_type']
elif attributes.is_attr_set(data.get('proxy_type')):
raise driver_proxy_group.ProxyTypeSetWithoutProxiedPTG()
示例9: _process_portbindings_create_and_update
def _process_portbindings_create_and_update(self, context, port_data,
port):
binding_profile = port.get(portbindings.PROFILE)
binding_profile_set = attributes.is_attr_set(binding_profile)
if not binding_profile_set and binding_profile is not None:
del port[portbindings.PROFILE]
binding_vnic = port.get(portbindings.VNIC_TYPE)
binding_vnic_set = attributes.is_attr_set(binding_vnic)
if not binding_vnic_set and binding_vnic is not None:
del port[portbindings.VNIC_TYPE]
# REVISIT(irenab) Add support for vnic_type for plugins that
# can handle more than one type.
# Currently implemented for ML2 plugin that does not use
# PortBindingMixin.
host = port_data.get(portbindings.HOST_ID)
host_set = attributes.is_attr_set(host)
with context.session.begin(subtransactions=True):
bind_port = context.session.query(
PortBindingPort).filter_by(port_id=port['id']).first()
if host_set:
if not bind_port:
context.session.add(PortBindingPort(port_id=port['id'],
host=host))
else:
bind_port.host = host
else:
host = bind_port.host if bind_port else None
self._extend_port_dict_binding_host(port, host)
示例10: _get_subnetpool_id
def _get_subnetpool_id(self, subnet):
"""Returns the subnetpool id for this request
If the pool id was explicitly set in the request then that will be
returned, even if it is None.
Otherwise, the default pool for the IP version requested will be
returned. This will either be a pool id or None (the default for each
configuration parameter). This implies that the ip version must be
either set implicitly with a specific cidr or explicitly using
ip_version attribute.
:param subnet: The subnet dict from the request
"""
subnetpool_id = subnet.get('subnetpool_id',
attributes.ATTR_NOT_SPECIFIED)
if subnetpool_id != attributes.ATTR_NOT_SPECIFIED:
return subnetpool_id
cidr = subnet.get('cidr')
if attributes.is_attr_set(cidr):
ip_version = netaddr.IPNetwork(cidr).version
else:
ip_version = subnet.get('ip_version')
if not attributes.is_attr_set(ip_version):
msg = _('ip_version must be specified in the absence of '
'cidr and subnetpool_id')
raise n_exc.BadRequest(resource='subnets', msg=msg)
if ip_version == 4:
return cfg.CONF.default_ipv4_subnet_pool
return cfg.CONF.default_ipv6_subnet_pool
示例11: process_create_network
def process_create_network(self, context, data, result):
"""Implementation of abstract method from ExtensionDriver class."""
LOG.debug("RK: process_create_network(). data: %s", data)
net_id = result.get('id')
port_min_attr = data.get(rk_const.RK_MIN_RATE)
port_max_attr = data.get(rk_const.RK_MAX_RATE)
if not attributes.is_attr_set(port_min_attr) or \
not attributes.is_attr_set(port_max_attr):
port_min_attr = cfg.CONF.RATEKEEPER.default_min_rate
port_max_attr = cfg.CONF.RATEKEEPER.default_max_rate
port_min_attr, port_max_attr = self._validate_rates(port_min_attr, port_max_attr)
LOG.debug("RK: port_min_attr %s, port_max_attr %s", port_min_attr, port_max_attr)
with context.session.begin(subtransactions=True):
try:
rk_db.create_vnet_record(net_id, port_min_attr, port_max_attr, context.session)
except Exception as e:
LOG.error(_LE("RK: error %s" % e))
raise ml2_exc.MechanismDriverError()
result[rk_const.RK_MIN_RATE] = port_min_attr
result[rk_const.RK_MAX_RATE] = port_max_attr
示例12: _save_subnet
def _save_subnet(self, context,
network,
subnet_args,
dns_nameservers,
host_routes,
subnet_request):
self._validate_subnet_cidr(context, network, subnet_args['cidr'])
self._validate_network_subnetpools(network,
subnet_args['subnetpool_id'],
subnet_args['ip_version'])
subnet = models_v2.Subnet(**subnet_args)
context.session.add(subnet)
# NOTE(changzhi) Store DNS nameservers with order into DB one
# by one when create subnet with DNS nameservers
if attributes.is_attr_set(dns_nameservers):
for order, server in enumerate(dns_nameservers):
dns = models_v2.DNSNameServer(
address=server,
order=order,
subnet_id=subnet.id)
context.session.add(dns)
if attributes.is_attr_set(host_routes):
for rt in host_routes:
route = models_v2.SubnetRoute(
subnet_id=subnet.id,
destination=rt['destination'],
nexthop=rt['nexthop'])
context.session.add(route)
self.save_allocation_pools(context, subnet,
subnet_request.allocation_pools)
return subnet
示例13: process_update_network
def process_update_network(self, context, data, result):
"""Implementation of abstract method from ExtensionDriver class."""
LOG.debug("RK: process_update_network(). data: %s" , data)
net_id = result.get('id')
net_min_attr = data.get(rk_const.RK_MIN_RATE)
net_max_attr = data.get(rk_const.RK_MAX_RATE)
LOG.debug("RK: update_network: %s and %s", net_min_attr, net_max_attr)
if attributes.is_attr_set(net_min_attr) and \
attributes.is_attr_set(net_max_attr):
with context.session.begin(subtransactions=True):
try:
res = rk_db.get_vnet_profile(net_id, context.session)
if res:
rk_db.update_vnet_rate_limit(net_id, net_min_attr, net_max_attr, context.session)
else:
# Network not found and can't be updated. Create instead
try:
rk_db.create_vnet_record(net_id, net_min_attr, net_max_attr, context.session)
except Exception as e:
LOG.error(_LE("RK: update_network: error %s" % e))
raise ml2_exc.MechanismDriverError()
LOG.debug("RK: update_network: res: %s", res)
except Exception as a:
LOG.error(_LE("RK: update_network: error %s" % a))
raise ml2_exc.MechanismDriverError()
示例14: _process_provider_create
def _process_provider_create(self, network):
segments = []
if any(attributes.is_attr_set(network.get(f))
for f in (provider.NETWORK_TYPE, provider.PHYSICAL_NETWORK,
provider.SEGMENTATION_ID)):
# Verify that multiprovider and provider attributes are not set
# at the same time.
if attributes.is_attr_set(network.get(mpnet.SEGMENTS)):
raise mpnet.SegmentsSetInConjunctionWithProviders()
network_type = self._get_attribute(network, provider.NETWORK_TYPE)
physical_network = self._get_attribute(network,
provider.PHYSICAL_NETWORK)
segmentation_id = self._get_attribute(network,
provider.SEGMENTATION_ID)
segments = [{provider.NETWORK_TYPE: network_type,
provider.PHYSICAL_NETWORK: physical_network,
provider.SEGMENTATION_ID: segmentation_id}]
elif attributes.is_attr_set(network.get(mpnet.SEGMENTS)):
segments = network[mpnet.SEGMENTS]
else:
return
return [self._process_provider_segment(s) for s in segments]
示例15: create_subnet
def create_subnet(self, context, subnet):
s = subnet["subnet"]
cidr = s.get("cidr", attributes.ATTR_NOT_SPECIFIED)
prefixlen = s.get("prefixlen", attributes.ATTR_NOT_SPECIFIED)
has_cidr = attributes.is_attr_set(cidr)
has_prefixlen = attributes.is_attr_set(prefixlen)
if has_cidr and has_prefixlen:
msg = _("cidr and prefixlen must not be supplied together")
raise n_exc.BadRequest(resource="subnets", msg=msg)
if has_cidr:
# turn the CIDR into a proper subnet
net = netaddr.IPNetwork(s["cidr"])
subnet["subnet"]["cidr"] = "%s/%s" % (net.network, net.prefixlen)
s["tenant_id"] = self._get_tenant_id_for_create(context, s)
subnetpool_id = self._get_subnetpool_id(s)
if subnetpool_id:
self._validate_pools_with_subnetpool(s)
else:
if not has_cidr:
msg = _("A cidr must be specified in the absence of a " "subnet pool")
raise n_exc.BadRequest(resource="subnets", msg=msg)
self._validate_subnet(context, s)
return self._create_subnet(context, subnet, subnetpool_id)