def validate(self): super(Subnet, self).validate() subnetpool = self.properties[self.SUBNETPOOL] prefixlen = self.properties[self.PREFIXLEN] cidr = self.properties[self.CIDR] if subnetpool is not None and cidr: raise exception.ResourcePropertyConflict(self.SUBNETPOOL, self.CIDR) if subnetpool is None and not cidr: raise exception.PropertyUnspecifiedError(self.SUBNETPOOL, self.CIDR) if prefixlen and cidr: raise exception.ResourcePropertyConflict(self.PREFIXLEN, self.CIDR) ra_mode = self.properties[self.IPV6_RA_MODE] address_mode = self.properties[self.IPV6_ADDRESS_MODE] if (self.properties[self.IP_VERSION] == 4) and (ra_mode or address_mode): msg = _('ipv6_ra_mode and ipv6_address_mode are not supported ' 'for ipv4.') raise exception.StackValidationFailed(message=msg) if ra_mode and address_mode and (ra_mode != address_mode): msg = _('When both ipv6_ra_mode and ipv6_address_mode are set, ' 'they must be equal.') raise exception.StackValidationFailed(message=msg) gateway_ip = self.properties.get(self.GATEWAY_IP) if (gateway_ip and gateway_ip not in ['~', ''] and not netutils.is_valid_ip(gateway_ip)): msg = (_('Gateway IP address "%(gateway)s" is in ' 'invalid format.'), gateway_ip) raise exception.StackValidationFailed(message=msg)
def validate(self): super(ManilaShareNetwork, self).validate() if (self.properties[self.NEUTRON_NETWORK] and self.properties[self.NOVA_NETWORK]): raise exception.ResourcePropertyConflict(self.NEUTRON_NETWORK, self.NOVA_NETWORK) if (self.properties[self.NOVA_NETWORK] and self.properties[self.NEUTRON_SUBNET]): raise exception.ResourcePropertyConflict(self.NEUTRON_SUBNET, self.NOVA_NETWORK)
def _validate_network(self, network): net_id = network.get(self.NETWORK_ID) port = network.get(self.NETWORK_PORT) subnet = network.get(self.NETWORK_SUBNET) fixed_ip = network.get(self.NETWORK_FIXED_IP) if net_id is None and port is None and subnet is None: msg = _('One of the properties "%(id)s", "%(port_id)s" ' 'or "%(subnet)s" should be set for the ' 'specified network of server "%(server)s".' '') % dict(id=self.NETWORK_ID, port_id=self.NETWORK_PORT, subnet=self.NETWORK_SUBNET, server=self.name) raise exception.StackValidationFailed(message=msg) if port and not self.is_using_neutron(): msg = _('Property "%s" is supported only for ' 'Neutron.') % self.NETWORK_PORT raise exception.StackValidationFailed(message=msg) # Nova doesn't allow specify ip and port at the same time if fixed_ip and port: raise exception.ResourcePropertyConflict( "/".join([self.NETWORKS, self.NETWORK_FIXED_IP]), "/".join([self.NETWORKS, self.NETWORK_PORT]))
def validate(self): ''' Validate any of the provided params ''' super(Server, self).validate() # check validity of key key_name = self.properties.get('key_name', None) if key_name: nova_utils.get_keypair(self.nova(), key_name) # either volume_id or snapshot_id needs to be specified, but not both # for block device mapping. bdm = self.properties.get('block_device_mapping') or [] bootable_vol = False for mapping in bdm: if mapping['device_name'] == 'vda': bootable_vol = True if mapping.get('volume_id') and mapping.get('snapshot_id'): raise exception.ResourcePropertyConflict( 'volume_id', 'snapshot_id') if not mapping.get('volume_id') and not mapping.get('snapshot_id'): msg = _('Either volume_id or snapshot_id must be specified for' ' device mapping %s') % mapping['device_name'] raise exception.StackValidationFailed(message=msg) # make sure the image exists if specified. image = self.properties.get('image', None) if image: nova_utils.get_image_id(self.nova(), image) elif not image and not bootable_vol: msg = _('Neither image nor bootable volume is specified for' ' instance %s') % self.name raise exception.StackValidationFailed(message=msg)
def _exec_replace(self, translation_key, translation_data, value_key, value_data, value): value_ind = None if translation_data and translation_data.get(translation_key): if value_data and value_data.get(value_key): value_ind = value_key elif translation_data.get(self.value_name) is not None: value_ind = self.value_name if self.custom_value_path is not None: data = translation_data.get(self.value_name) for key in self.custom_value_path: data = data.get(key) if data is None: value_ind = None break if value_ind is not None: raise exception.ResourcePropertyConflict( props=[translation_key, value_ind]) if value is not None: translation_data[translation_key] = value elif (self.value_name is not None and translation_data.get(self.value_name) is not None): if self.custom_value_path: self.resolve_custom_value_path(translation_data, translation_key) else: translation_data[translation_key] = translation_data[ self.value_name] del translation_data[self.value_name] # If value defined with value_path, need to delete value_path # property data after it's replacing. if value_data and value_data.get(value_key): del value_data[value_key]
def validate(self): super(Port, self).validate() fixed_ips = self.properties.get(self.FIXED_IPS) no_fixed_ips = self.properties.get(self.NO_FIXED_IPS, False) if fixed_ips and no_fixed_ips: raise exception.ResourcePropertyConflict(self.FIXED_IPS, self.NO_FIXED_IPS)
def validate(self): """Validate provided params.""" res = super(CinderVolume, self).validate() if res is not None: return res # Scheduler hints are only supported from Cinder API v2 if (self.properties[self.CINDER_SCHEDULER_HINTS] and self.client().volume_api_version == 1): raise exception.StackValidationFailed( message=_('Scheduler hints are not supported by the current ' 'volume API.')) # Multi attach is only supported from Cinder API v2 if (self.properties[self.MULTI_ATTACH] and self.client().volume_api_version == 1): raise exception.StackValidationFailed( message=_('Multiple attach is not supported by the current ' 'volume API. Use this property since ' 'Cinder API v2.')) # can not specify both image and imageRef image = self.properties.get(self.IMAGE) imageRef = self.properties.get(self.IMAGE_REF) if image and imageRef: raise exception.ResourcePropertyConflict(self.IMAGE, self.IMAGE_REF) # if not create from backup, need to check other create sources if not self.properties.get(self.BACKUP_ID): self._validate_create_sources()
def validate(self): ''' Validate any of the provided params ''' res = super(Instance, self).validate() if res: return res # check validity of security groups vs. network interfaces security_groups = self._get_security_groups() if security_groups and self.properties.get(self.NETWORK_INTERFACES): raise exception.ResourcePropertyConflict( '/'.join([self.SECURITY_GROUPS, self.SECURITY_GROUP_IDS]), self.NETWORK_INTERFACES) # check bdm property # now we don't support without snapshot_id in bdm bdm = self.properties.get(self.BLOCK_DEVICE_MAPPINGS) if bdm: for mapping in bdm: ebs = mapping.get(self.EBS) if ebs: snapshot_id = ebs.get(self.SNAPSHOT_ID) if not snapshot_id: msg = _("SnapshotId is missing, this is required " "when specifying BlockDeviceMappings.") raise exception.StackValidationFailed(message=msg) else: msg = _("Ebs is missing, this is required " "when specifying BlockDeviceMappings.") raise exception.StackValidationFailed(message=msg)
def handle_create(self): """Add a floating IP address to a server.""" if self.properties[self.EIP] is not None \ and self.properties[self.ALLOCATION_ID] is not None: raise exception.ResourcePropertyConflict(self.EIP, self.ALLOCATION_ID) if self.properties[self.EIP]: if not self.properties[self.INSTANCE_ID]: logger.warn( _('Skipping association, InstanceId not ' 'specified')) return server = self.nova().servers.get(self.properties[self.INSTANCE_ID]) server.add_floating_ip(self.properties[self.EIP]) self.resource_id_set(self.properties[self.EIP]) logger.debug( _('ElasticIpAssociation ' '%(instance)s.add_floating_ip(%(eip)s)'), { 'instance': self.properties[self.INSTANCE_ID], 'eip': self.properties[self.EIP] }) elif self.properties[self.ALLOCATION_ID]: assert clients.neutronclient, "Neutron required for VPC operations" port_id = None port_rsrc = None if self.properties[self.NETWORK_INTERFACE_ID]: port_id = self.properties[self.NETWORK_INTERFACE_ID] port_rsrc = self.neutron().list_ports(id=port_id)['ports'][0] elif self.properties[self.INSTANCE_ID]: instance_id = self.properties[self.INSTANCE_ID] ports = self.neutron().list_ports(device_id=instance_id) port_rsrc = ports['ports'][0] port_id = port_rsrc['id'] else: logger.warn(_('Skipping association, resource not specified')) return float_id = self.properties[self.ALLOCATION_ID] self.resource_id_set(float_id) # assuming only one fixed_ip subnet_id = port_rsrc['fixed_ips'][0]['subnet_id'] subnets = self.neutron().list_subnets(id=subnet_id) subnet_rsrc = subnets['subnets'][0] netid = subnet_rsrc['network_id'] router = VPC.router_for_vpc(self.neutron(), netid) if router is not None: floatingip = self.neutron().show_floatingip(float_id) floating_net_id = \ floatingip['floatingip']['floating_network_id'] self.neutron().add_gateway_router( router['id'], {'network_id': floating_net_id}) self.neutron().update_floatingip( float_id, {'floatingip': { 'port_id': port_id }})
def _validate_deprecated_keys(props, key, deprecated_key): value = props.get(key) deprecated_value = props.get(deprecated_key) if value and deprecated_value: raise exception.ResourcePropertyConflict(key, deprecated_key) if not value and not deprecated_value: return False return True
def _validate_depr_subnet_keys(properties, subnet_key, depr_subnet_key): subnet_value = properties.get(subnet_key) subnet_id_value = properties.get(depr_subnet_key) if subnet_value and subnet_id_value: raise exception.ResourcePropertyConflict(subnet_key, subnet_key) if not subnet_value and not subnet_id_value: return False return True
def _validate_depr_property_required(properties, prop_key, depr_prop_key): prop_value = properties.get(prop_key) depr_prop_value = properties.get(depr_prop_key) if prop_value and depr_prop_value: raise exception.ResourcePropertyConflict(prop_key, depr_prop_key) if not prop_value and not depr_prop_value: raise exception.PropertyUnspecifiedError(prop_key, depr_prop_key)
def validate(self): super(Router, self).validate() is_distributed = self.properties.get(self.DISTRIBUTED) l3_agent_id = self.properties.get(self.L3_AGENT_ID) # do not specific l3_agent_id when creating a distributed router if is_distributed and l3_agent_id: raise exception.ResourcePropertyConflict(self.DISTRIBUTED, self.L3_AGENT_ID)
def validate(self): super(Workflow, self).validate() if self.properties.get(self.TYPE) == 'reverse': params = self.properties.get(self.PARAMS) if params is None or not params.get('task_name'): raise exception.StackValidationFailed( error=_('Mistral resource validation error'), path=[ self.name, ('properties' if self.stack.t.VERSION == 'heat_template_version' else 'Properties'), self.PARAMS ], message=_("'task_name' is not assigned in 'params' " "in case of reverse type workflow.")) for task in self.properties.get(self.TASKS): wf_value = task.get(self.WORKFLOW) action_value = task.get(self.ACTION) if wf_value and action_value: raise exception.ResourcePropertyConflict( self.WORKFLOW, self.ACTION) if not wf_value and not action_value: raise exception.PropertyUnspecifiedError( self.WORKFLOW, self.ACTION) if (task.get(self.REQUIRES) is not None and self.properties.get(self.TYPE)) == 'direct': msg = _("task %(task)s contains property 'requires' " "in case of direct workflow. Only reverse workflows " "can contain property 'requires'.") % { 'name': self.name, 'task': task.get(self.TASK_NAME) } raise exception.StackValidationFailed( error=_('Mistral resource validation error'), path=[ self.name, ('properties' if self.stack.t.VERSION == 'heat_template_version' else 'Properties'), self.TASKS, task.get(self.TASK_NAME), self.REQUIRES ], message=msg) if task.get(self.POLICIES) is not None: for task_item in task.get(self.POLICIES): if task.get(task_item) is not None: msg = _('Property %(policies)s and %(item)s cannot be ' 'used both at one time.') % { 'policies': self.POLICIES, 'item': task_item } raise exception.StackValidationFailed(message=msg) if (task.get(self.WITH_ITEMS) is None and task.get(self.CONCURRENCY) is not None): raise exception.ResourcePropertyDependency( prop1=self.CONCURRENCY, prop2=self.WITH_ITEMS)
def validate(self): super(Router, self).validate() is_distributed = self.properties[self.DISTRIBUTED] l3_agent_id = self.properties[self.L3_AGENT_ID] l3_agent_ids = self.properties[self.L3_AGENT_IDS] is_ha = self.properties[self.HA] if l3_agent_id and l3_agent_ids: raise exception.ResourcePropertyConflict(self.L3_AGENT_ID, self.L3_AGENT_IDS) # do not specific l3 agent when creating a distributed router if is_distributed and (l3_agent_id or l3_agent_ids): raise exception.ResourcePropertyConflict( self.DISTRIBUTED, "/".join([self.L3_AGENT_ID, self.L3_AGENT_IDS])) if is_ha and is_distributed: raise exception.ResourcePropertyConflict(self.DISTRIBUTED, self.HA) if not is_ha and l3_agent_ids and len(l3_agent_ids) > 1: msg = _('Non HA routers can only have one L3 agent.') raise exception.StackValidationFailed(message=msg)
def handle_create(self): """Add a floating IP address to a server.""" if self.properties['EIP'] is not None \ and self.properties['AllocationId'] is not None: raise exception.ResourcePropertyConflict('EIP', 'AllocationId') if self.properties['EIP']: if not self.properties['InstanceId']: logger.warn('Skipping association, InstanceId not specified') return server = self.nova().servers.get(self.properties['InstanceId']) server.add_floating_ip(self.properties['EIP']) self.resource_id_set(self.properties['EIP']) logger.debug( 'ElasticIpAssociation %s.add_floating_ip(%s)' % (self.properties['InstanceId'], self.properties['EIP'])) elif self.properties['AllocationId']: assert clients.neutronclient, "Neutron required for VPC operations" port_id = None port_rsrc = None if self.properties['NetworkInterfaceId']: port_id = self.properties['NetworkInterfaceId'] port_rsrc = self.neutron().list_ports(id=port_id)['ports'][0] elif self.properties['InstanceId']: instance_id = self.properties['InstanceId'] ports = self.neutron().list_ports(device_id=instance_id) port_rsrc = ports['ports'][0] port_id = port_rsrc['id'] else: logger.warn('Skipping association, resource not specified') return float_id = self.properties['AllocationId'] self.resource_id_set(float_id) # assuming only one fixed_ip subnet_id = port_rsrc['fixed_ips'][0]['subnet_id'] subnets = self.neutron().list_subnets(id=subnet_id) subnet_rsrc = subnets['subnets'][0] netid = subnet_rsrc['network_id'] router = VPC.router_for_vpc(self.neutron(), netid) if router is not None: floatingip = self.neutron().show_floatingip(float_id) floating_net_id = \ floatingip['floatingip']['floating_network_id'] self.neutron().add_gateway_router( router['id'], {'network_id': floating_net_id}) self.neutron().update_floatingip( float_id, {'floatingip': { 'port_id': port_id }})
def validate(self): ''' Validate any of the provided params ''' super(RouterInterface, self).validate() subnet_id = self.properties.get('subnet_id') port_id = self.properties.get('port_id') if subnet_id and port_id: raise exception.ResourcePropertyConflict('subnet_id', 'port_id') if not subnet_id and not port_id: msg = 'Either subnet_id or port_id must be specified.' raise exception.StackValidationFailed(message=msg)
def _validate_depr_property_required(properties, prop_key, depr_prop_key): prop_value = properties.get(prop_key) depr_prop_value = properties.get(depr_prop_key) if prop_value and depr_prop_value: raise exception.ResourcePropertyConflict(prop_key, depr_prop_key) if not prop_value and not depr_prop_value: msg = _('Either %(prop_key)s or %(depr_prop_key)s' ' should be specified.' ) % {'prop_key': prop_key, 'depr_prop_key': depr_prop_key} raise exception.StackValidationFailed(message=msg)
def _exec_replace(self, translation_key, translation_data, value_key, value_data, value): if isinstance(translation_data, list): for item in translation_data: if item.get(self.value_name) and item.get(translation_key): raise exception.ResourcePropertyConflict( props=[translation_key, self.value_name]) elif item.get(self.value_name) is not None: item[translation_key] = item[self.value_name] del item[self.value_name] elif value is not None: item[translation_key] = value else: if (translation_data and translation_data.get(translation_key) and value_data and value_data.get(value_key)): raise exception.ResourcePropertyConflict( props=[translation_key, value_key]) translation_data[translation_key] = value # If value defined with value_path, need to delete value_path # property data after it's replacing. if value_data and value_data.get(value_key): del value_data[value_key]
def validate(self): """Validate any of the provided params.""" super(RouterInterface, self).validate() prop_subnet_exists = self.properties.get(self.SUBNET) is not None prop_port_exists = self.properties.get(self.PORT) is not None if prop_subnet_exists and prop_port_exists: raise exception.ResourcePropertyConflict(self.SUBNET, self.PORT) if not prop_subnet_exists and not prop_port_exists: raise exception.PropertyUnspecifiedError(self.SUBNET, self.PORT)
def validate_assignment_properties(self): if self.properties.get(self.ROLES) is not None: for role_assignment in self.properties.get(self.ROLES): project = role_assignment.get(self.PROJECT) domain = role_assignment.get(self.DOMAIN) if project is not None and domain is not None: raise exception.ResourcePropertyConflict(self.PROJECT, self.DOMAIN) if project is None and domain is None: msg = _('Either project or domain must be specified for' ' role %s') % role_assignment.get(self.ROLE) raise exception.StackValidationFailed(message=msg)
def _validate_network(self, network): net_id = network.get(self.NETWORK_ID) port = network.get(self.NETWORK_PORT) fixed_ip = network.get(self.NETWORK_FIXED_IP) if net_id is None and port is None: raise exception.PropertyUnspecifiedError(self.NETWORK_ID, self.NETWORK_PORT) # Don't allow specify ip and port at the same time if fixed_ip and port is not None: raise exception.ResourcePropertyConflict( ".".join([self.NETWORKS, self.NETWORK_FIXED_IP]), ".".join([self.NETWORKS, self.NETWORK_PORT]))
def validate(self): ''' Validate any of the provided params ''' res = super(Instance, self).validate() if res: return res # check validity of security groups vs. network interfaces security_groups = self._get_security_groups() if security_groups and self.properties.get(self.NETWORK_INTERFACES): raise exception.ResourcePropertyConflict( '/'.join([self.SECURITY_GROUPS, self.SECURITY_GROUP_IDS]), self.NETWORK_INTERFACES)
def validate(self): super(ManilaShareNetwork, self).validate() if (self.properties[self.NEUTRON_NETWORK] and self.properties[self.NOVA_NETWORK]): raise exception.ResourcePropertyConflict(self.NEUTRON_NETWORK, self.NOVA_NETWORK) if (self.properties[self.NOVA_NETWORK] and self.properties[self.NEUTRON_SUBNET]): raise exception.ResourcePropertyConflict(self.NEUTRON_SUBNET, self.NOVA_NETWORK) if self.is_using_neutron() and self.properties[self.NOVA_NETWORK]: msg = _('With Neutron enabled you need to pass Neutron network ' 'and Neutron subnet instead of Nova network') raise exception.StackValidationFailed(message=msg) if (self.properties[self.NEUTRON_NETWORK] and not self.properties[self.NEUTRON_SUBNET]): raise exception.ResourcePropertyDependency( prop1=self.NEUTRON_NETWORK, prop2=self.NEUTRON_SUBNET) if (self.properties[self.NEUTRON_NETWORK] and self.properties[self.NEUTRON_SUBNET]): plg = self.client_plugin('neutron') subnet_id = plg.find_resourceid_by_name_or_id( plg.RES_TYPE_SUBNET, self.properties[self.NEUTRON_SUBNET]) net_id = plg.network_id_from_subnet_id(subnet_id) provided_net_id = plg.find_resourceid_by_name_or_id( plg.RES_TYPE_NETWORK, self.properties[self.NEUTRON_NETWORK]) if net_id != provided_net_id: msg = (_('Provided %(subnet)s does not belong ' 'to provided %(network)s.') % { 'subnet': self.NEUTRON_SUBNET, 'network': self.NEUTRON_NETWORK }) raise exception.StackValidationFailed(message=msg)
def _validate_network(self, network): net_uuid = network.get(self.NETWORK_UUID) net_id = network.get(self.NETWORK_ID) port = network.get(self.NETWORK_PORT) subnet = network.get(self.NETWORK_SUBNET) fixed_ip = network.get(self.NETWORK_FIXED_IP) if (net_id is None and port is None and net_uuid is None and subnet is None): msg = _('One of the properties "%(id)s", "%(port_id)s", ' '"%(uuid)s" or "%(subnet)s" should be set for the ' 'specified network of server "%(server)s".' '') % dict(id=self.NETWORK_ID, port_id=self.NETWORK_PORT, uuid=self.NETWORK_UUID, subnet=self.NETWORK_SUBNET, server=self.name) raise exception.StackValidationFailed(message=msg) if net_uuid and net_id: msg = _('Properties "%(uuid)s" and "%(id)s" are both set ' 'to the network "%(network)s" for the server ' '"%(server)s". The "%(uuid)s" property is deprecated. ' 'Use only "%(id)s" property.' '') % dict(uuid=self.NETWORK_UUID, id=self.NETWORK_ID, network=network[self.NETWORK_ID], server=self.name) raise exception.StackValidationFailed(message=msg) elif net_uuid: LOG.info(_LI('For the server "%(server)s" the "%(uuid)s" ' 'property is set to network "%(network)s". ' '"%(uuid)s" property is deprecated. Use ' '"%(id)s" property instead.'), dict(uuid=self.NETWORK_UUID, id=self.NETWORK_ID, network=network[self.NETWORK_ID], server=self.name)) if port and not self.is_using_neutron(): msg = _('Property "%s" is supported only for ' 'Neutron.') % self.NETWORK_PORT raise exception.StackValidationFailed(message=msg) # Nova doesn't allow specify ip and port at the same time if fixed_ip and port: raise exception.ResourcePropertyConflict( "/".join([self.NETWORKS, self.NETWORK_FIXED_IP]), "/".join([self.NETWORKS, self.NETWORK_PORT]))
def validate(self): ''' Validate any of the provided params ''' super(RouterInterface, self).validate() prop_subnet_exists = self._validate_depr_subnet_keys( self.properties, self.SUBNET, self.SUBNET_ID) port_id = self.properties.get(self.PORT_ID) if prop_subnet_exists and port_id: raise exception.ResourcePropertyConflict(self.SUBNET, self.PORT_ID) if not prop_subnet_exists and not port_id: msg = 'Either subnet or port_id must be specified.' raise exception.StackValidationFailed(message=msg)
def validate(self): """Validate provided params.""" res = super(CinderVolume, self).validate() if res is not None: return res # can not specify both image and imageRef image = self.properties.get(self.IMAGE) imageRef = self.properties.get(self.IMAGE_REF) if image and imageRef: raise exception.ResourcePropertyConflict(self.IMAGE, self.IMAGE_REF) # if not create from backup, need to check other create sources if not self.properties.get(self.BACKUP_ID): self._validate_create_sources()
def validate(self): super(SecurityGroupRule, self).validate() if (self.properties[self.REMOTE_GROUP] is not None and self.properties[self.REMOTE_IP_PREFIX] is not None): raise exception.ResourcePropertyConflict( self.REMOTE_GROUP, self.REMOTE_IP_PREFIX) port_max = self.properties[self.PORT_RANGE_MAX] port_min = self.properties[self.PORT_RANGE_MIN] protocol = self.properties[self.PROTOCOL] if (port_max is not None and port_min is not None and protocol not in ('icmp', 'icmpv6', 'ipv6-icmp') and port_max < port_min): msg = _('The minimum port number must be less than or equal to ' 'the maximum port number.') raise exception.StackValidationFailed(message=msg)
def validate(self): ''' Validate any of the provided params ''' super(RouterInterface, self).validate() prop_subnet_exists = self._validate_depr_subnet_keys( self.properties, self.SUBNET, self.SUBNET_ID) port_id = self.properties.get(self.PORT_ID) if prop_subnet_exists and port_id: raise exception.ResourcePropertyConflict(self.SUBNET, self.PORT_ID) if not prop_subnet_exists and not port_id: raise exception.PropertyUnspecifiedError(self.SUBNET, self.PORT_ID)
def _validate_network(self, network): net_id = network.get(self.NETWORK_ID) port = network.get(self.NETWORK_PORT) subnet = network.get(self.NETWORK_SUBNET) fixed_ip = network.get(self.NETWORK_FIXED_IP) floating_ip = network.get(self.NETWORK_FLOATING_IP) str_network = network.get(self.ALLOCATE_NETWORK) if (net_id is None and port is None and subnet is None and not str_network): msg = _('One of the properties "%(id)s", "%(port_id)s", ' '"%(str_network)s" or "%(subnet)s" should be set for the ' 'specified network of server "%(server)s".' '') % dict(id=self.NETWORK_ID, port_id=self.NETWORK_PORT, subnet=self.NETWORK_SUBNET, str_network=self.ALLOCATE_NETWORK, server=self.name) raise exception.StackValidationFailed(message=msg) # can not specify str_network with other keys of networks # at the same time has_value_keys = [k for k, v in network.items() if v is not None] if str_network and len(has_value_keys) != 1: msg = _('Can not specify "%s" with other keys of networks ' 'at the same time.') % self.ALLOCATE_NETWORK raise exception.StackValidationFailed(message=msg) # Nova doesn't allow specify ip and port at the same time if fixed_ip and port is not None: raise exception.ResourcePropertyConflict( "/".join([self.NETWORKS, self.NETWORK_FIXED_IP]), "/".join([self.NETWORKS, self.NETWORK_PORT])) # if user only specifies network and floating ip, floating ip # can't be associated as the the neutron port isn't created/managed # by heat if floating_ip is not None: if net_id is not None and port is None and subnet is None: msg = _('Property "%(fip)s" is not supported if only ' '"%(net)s" is specified, because the corresponding ' 'port can not be retrieved.' ) % dict(fip=self.NETWORK_FLOATING_IP, net=self.NETWORK_ID) raise exception.StackValidationFailed(message=msg)