Replace self.properties.get on self.properties[]

Remove unnecessary using self.properties.get for more
clear code. Using properties.get(prop, default) causes
next issues:
1. properties.get(prop) if prop not in properties_schema
will return None instead of expected KeyError.
2. properties.get(prop, default) returns "default" value
if current properties is not presented in properties_schema.
So using self.properties.get() makes sense only when we plan
to use this property with default option in another resource,
which has not it in property schema.
This patch replaces this methods in resources/openstack folder.

Change-Id: I523eb3feacb0cb7a16a928a92896ce56188e376f
This commit is contained in:
Peter Razumovsky 2015-04-30 14:23:45 +03:00
parent 4032e40cce
commit 4b5f296acc
21 changed files with 137 additions and 136 deletions

View File

@ -200,10 +200,10 @@ class CinderVolume(vb.BaseVolume):
'size': self.properties[self.SIZE],
'availability_zone': self.properties[self.AVAILABILITY_ZONE]
}
if self.properties.get(self.IMAGE):
if self.properties[self.IMAGE]:
arguments['imageRef'] = self.client_plugin('glance').get_image_id(
self.properties[self.IMAGE])
elif self.properties.get(self.IMAGE_REF):
elif self.properties[self.IMAGE_REF]:
arguments['imageRef'] = self.properties[self.IMAGE_REF]
optionals = (self.SNAPSHOT_ID, self.VOLUME_TYPE, self.SOURCE_VOLID,
@ -244,9 +244,9 @@ class CinderVolume(vb.BaseVolume):
if self.NAME in prop_diff or self.DESCRIPTION in prop_diff:
vol = cinder.volumes.get(self.resource_id)
update_name = (prop_diff.get(self.NAME) or
self.properties.get(self.NAME))
self.properties[self.NAME])
update_description = (prop_diff.get(self.DESCRIPTION) or
self.properties.get(self.DESCRIPTION))
self.properties[self.DESCRIPTION])
kwargs = self._fetch_name_and_description(
cinder.volume_api_version, update_name, update_description)
cinder.volumes.update(vol, **kwargs)
@ -360,7 +360,7 @@ class CinderVolume(vb.BaseVolume):
return res
# Scheduler hints are only supported from Cinder API v2
if (self.properties.get(self.CINDER_SCHEDULER_HINTS)
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 '
@ -418,11 +418,11 @@ class CinderVolumeAttachment(vb.BaseVolumeAttachment):
# could be updated in UpdateReplace manner,
# we still first detach the old resource so that
# self.resource_id is not replaced prematurely
volume_id = self.properties.get(self.VOLUME_ID)
volume_id = self.properties[self.VOLUME_ID]
if self.VOLUME_ID in prop_diff:
volume_id = prop_diff.get(self.VOLUME_ID)
device = self.properties.get(self.DEVICE)
device = self.properties[self.DEVICE]
if self.DEVICE in prop_diff:
device = prop_diff.get(self.DEVICE)

View File

@ -50,8 +50,9 @@ class CloudConfig(software_config.SoftwareConfig):
}
def handle_create(self):
cloud_config = template_format.yaml.dump(self.properties.get(
self.CLOUD_CONFIG), Dumper=template_format.yaml_dumper)
cloud_config = template_format.yaml.dump(
self.properties[self.CLOUD_CONFIG],
Dumper=template_format.yaml_dumper)
props = {
self.NAME: self.physical_resource_name(),
self.CONFIG: '#cloud-config\n%s' % cloud_config,

View File

@ -107,7 +107,7 @@ class MultipartMime(software_config.SoftwareConfig):
return self.message
subparts = []
for item in self.properties.get(self.PARTS):
for item in self.properties[self.PARTS]:
config = item.get(self.CONFIG)
part_type = item.get(self.TYPE, self.TEXT)
part = config

View File

@ -228,9 +228,9 @@ class RandomString(resource.Resource):
def validate(self):
super(RandomString, self).validate()
sequence = self.properties.get(self.SEQUENCE)
char_sequences = self.properties.get(self.CHARACTER_SEQUENCES)
char_classes = self.properties.get(self.CHARACTER_CLASSES)
sequence = self.properties[self.SEQUENCE]
char_sequences = self.properties[self.CHARACTER_SEQUENCES]
char_classes = self.properties[self.CHARACTER_CLASSES]
if sequence and (char_sequences or char_classes):
msg = (_("Cannot use deprecated '%(seq)s' property along with "
@ -245,7 +245,7 @@ class RandomString(resource.Resource):
return sum(char_dict[min_prop] for char_dict in char_dicts)
return 0
length = self.properties.get(self.LENGTH)
length = self.properties[self.LENGTH]
min_length = (char_min(char_sequences, self.CHARACTER_SEQUENCES_MIN) +
char_min(char_classes, self.CHARACTER_CLASSES_MIN))
if min_length > length:
@ -254,16 +254,16 @@ class RandomString(resource.Resource):
raise exception.StackValidationFailed(message=msg)
def handle_create(self):
char_sequences = self.properties.get(self.CHARACTER_SEQUENCES)
char_classes = self.properties.get(self.CHARACTER_CLASSES)
length = self.properties.get(self.LENGTH)
char_sequences = self.properties[self.CHARACTER_SEQUENCES]
char_classes = self.properties[self.CHARACTER_CLASSES]
length = self.properties[self.LENGTH]
if char_sequences or char_classes:
random_string = self._generate_random_string(char_sequences,
char_classes,
length)
else:
sequence = self.properties.get(self.SEQUENCE)
sequence = self.properties[self.SEQUENCE]
if not sequence: # Deprecated property not provided, use a default
sequence = "lettersdigits"

View File

@ -111,7 +111,7 @@ class SoftwareComponent(sc.SoftwareConfig):
props = dict(self.properties)
props[self.NAME] = self.physical_resource_name()
# use config property of SoftwareConfig to store configs list
configs = self.properties.get(self.CONFIGS)
configs = self.properties[self.CONFIGS]
props[self.CONFIG] = {self.CONFIGS: configs}
# set 'group' to enable component processing by in-instance hook
props[self.GROUP] = 'component'

View File

@ -179,20 +179,20 @@ class SoftwareDeployment(signal_responder.SignalResponder):
default_client_name = 'heat'
def _signal_transport_cfn(self):
return self.properties.get(
self.SIGNAL_TRANSPORT) == self.CFN_SIGNAL
return self.properties[
self.SIGNAL_TRANSPORT] == self.CFN_SIGNAL
def _signal_transport_heat(self):
return self.properties.get(
self.SIGNAL_TRANSPORT) == self.HEAT_SIGNAL
return self.properties[
self.SIGNAL_TRANSPORT] == self.HEAT_SIGNAL
def _signal_transport_none(self):
return self.properties.get(
self.SIGNAL_TRANSPORT) == self.NO_SIGNAL
return self.properties[
self.SIGNAL_TRANSPORT] == self.NO_SIGNAL
def _signal_transport_temp_url(self):
return self.properties.get(
self.SIGNAL_TRANSPORT) == self.TEMP_URL_SIGNAL
return self.properties[
self.SIGNAL_TRANSPORT] == self.TEMP_URL_SIGNAL
def _build_properties(self, properties, config_id, action):
props = {
@ -360,7 +360,7 @@ class SoftwareDeployment(signal_responder.SignalResponder):
scl.NAME: self.DEPLOY_SERVER_ID,
scl.DESCRIPTION: _('ID of the server being deployed to'),
scl.TYPE: 'String',
'value': self.properties.get(self.SERVER)
'value': self.properties[self.SERVER]
}, {
scl.NAME: self.DEPLOY_ACTION,
scl.DESCRIPTION: _('Name of the current action being deployed'),
@ -382,7 +382,7 @@ class SoftwareDeployment(signal_responder.SignalResponder):
scl.DESCRIPTION: _('How the server should signal to heat with '
'the deployment output values.'),
scl.TYPE: 'String',
'value': self.properties.get(self.SIGNAL_TRANSPORT)
'value': self.properties[self.SIGNAL_TRANSPORT]
}])
if self._signal_transport_cfn():
inputs.append({
@ -565,7 +565,7 @@ class SoftwareDeployment(signal_responder.SignalResponder):
:raises StackValidationFailed: if any property failed validation.
'''
super(SoftwareDeployment, self).validate()
server = self.properties.get(self.SERVER)
server = self.properties[self.SERVER]
if server:
res = self.stack.resource_by_refid(server)
if res:

View File

@ -135,8 +135,8 @@ class StructuredDeployment(sd.SoftwareDeployment):
def _build_derived_config(self, action, source,
derived_inputs, derived_options):
cfg = source.get(sc.SoftwareConfig.CONFIG)
input_key = self.properties.get(self.INPUT_KEY)
check_input_val = self.properties.get(self.INPUT_VALUES_VALIDATE)
input_key = self.properties[self.INPUT_KEY]
check_input_val = self.properties[self.INPUT_VALUES_VALIDATE]
inputs = dict((i['name'], i['value']) for i in derived_inputs)

View File

@ -124,9 +124,9 @@ class FloatingIP(neutron.NeutronResource):
gateway_network = resource.properties.get(
router.RouterGateway.NETWORK) or resource.properties.get(
router.RouterGateway.NETWORK_ID)
floating_network = self.properties.get(
self.FLOATING_NETWORK) or self.properties.get(
self.FLOATING_NETWORK_ID)
floating_network = self.properties[
self.FLOATING_NETWORK] or self.properties[
self.FLOATING_NETWORK_ID]
if gateway_network == floating_network:
deps += (self, resource)
@ -175,9 +175,9 @@ class FloatingIP(neutron.NeutronResource):
if gateway:
gateway_network = gateway.get(
router.Router.EXTERNAL_GATEWAY_NETWORK)
floating_network = self.properties.get(
self.FLOATING_NETWORK) or self.properties.get(
self.FLOATING_NETWORK_ID)
floating_network = self.properties[
self.FLOATING_NETWORK] or self.properties[
self.FLOATING_NETWORK_ID]
if gateway_network == floating_network:
deps += (self, resource)
@ -186,8 +186,8 @@ class FloatingIP(neutron.NeutronResource):
self._validate_depr_property_required(
self.properties, self.FLOATING_NETWORK, self.FLOATING_NETWORK_ID)
# fixed_ip_address cannot be specified without a port_id
if self.properties.get(self.PORT_ID) is None and self.properties.get(
self.FIXED_IP_ADDRESS) is not None:
if self.properties[self.PORT_ID] is None and self.properties[
self.FIXED_IP_ADDRESS] is not None:
raise exception.ResourcePropertyDependency(
prop1=self.FIXED_IP_ADDRESS, prop2=self.PORT_ID)
@ -216,11 +216,11 @@ class FloatingIP(neutron.NeutronResource):
neutron_client = self.neutron()
port_id = prop_diff.get(self.PORT_ID,
self.properties.get(self.PORT_ID))
self.properties[self.PORT_ID])
fixed_ip_address = prop_diff.get(
self.FIXED_IP_ADDRESS,
self.properties.get(self.FIXED_IP_ADDRESS))
self.properties[self.FIXED_IP_ADDRESS])
request_body = {
'floatingip': {
@ -302,15 +302,15 @@ class FloatingIPAssociation(neutron.NeutronResource):
client = self.neutron()
try:
client.update_floatingip(
self.properties.get(self.FLOATINGIP_ID),
self.properties[self.FLOATINGIP_ID],
{'floatingip': {'port_id': None}})
except Exception as ex:
self.client_plugin().ignore_not_found(ex)
def handle_update(self, json_snippet, tmpl_diff, prop_diff):
if prop_diff:
floatingip_id = self.properties.get(self.FLOATINGIP_ID)
port_id = self.properties.get(self.PORT_ID)
floatingip_id = self.properties[self.FLOATINGIP_ID]
port_id = self.properties[self.PORT_ID]
neutron_client = self.neutron()
# if the floatingip_id is changed, disassociate the port which
# associated with the old floatingip_id
@ -328,7 +328,7 @@ class FloatingIPAssociation(neutron.NeutronResource):
port_id = prop_diff.get(self.PORT_ID) or port_id
fixed_ip_address = (prop_diff.get(self.FIXED_IP_ADDRESS) or
self.properties.get(self.FIXED_IP_ADDRESS))
self.properties[self.FIXED_IP_ADDRESS])
request_body = {
'floatingip': {

View File

@ -604,7 +604,7 @@ class PoolMember(neutron.NeutronResource):
protocol_port = self.properties[self.PROTOCOL_PORT]
address = self.properties[self.ADDRESS]
admin_state_up = self.properties[self.ADMIN_STATE_UP]
weight = self.properties.get(self.WEIGHT)
weight = self.properties[self.WEIGHT]
params = {
'pool_id': pool,

View File

@ -267,8 +267,8 @@ class Port(neutron.NeutronResource):
dep_network = res.properties.get(
subnet.Subnet.NETWORK) or res.properties.get(
subnet.Subnet.NETWORK_ID)
network = self.properties.get(
self.NETWORK) or self.properties.get(self.NETWORK_ID)
network = self.properties[
self.NETWORK] or self.properties[self.NETWORK_ID]
if dep_network == network:
deps += (self, res)

View File

@ -93,8 +93,8 @@ class ProviderNet(net.Net):
'''
super(ProviderNet, self).validate()
if (self.properties.get(self.PROVIDER_SEGMENTATION_ID) and
self.properties.get(self.PROVIDER_NETWORK_TYPE) != 'vlan'):
if (self.properties[self.PROVIDER_SEGMENTATION_ID] and
self.properties[self.PROVIDER_NETWORK_TYPE] != 'vlan'):
msg = _('segmentation_id not allowed for flat network type.')
raise exception.StackValidationFailed(message=msg)

View File

@ -149,10 +149,10 @@ class Router(neutron.NeutronResource):
def validate(self):
super(Router, self).validate()
is_distributed = self.properties.get(self.DISTRIBUTED)
l3_agent_id = self.properties.get(self.L3_AGENT_ID)
l3_agent_ids = self.properties.get(self.L3_AGENT_IDS)
is_ha = self.properties.get(self.HA)
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)
@ -170,7 +170,7 @@ class Router(neutron.NeutronResource):
def add_dependencies(self, deps):
super(Router, self).add_dependencies(deps)
external_gw = self.properties.get(self.EXTERNAL_GATEWAY)
external_gw = self.properties[self.EXTERNAL_GATEWAY]
if external_gw:
external_gw_net = external_gw.get(self.EXTERNAL_GATEWAY_NETWORK)
for res in six.itervalues(self.stack):
@ -442,7 +442,7 @@ class RouterGateway(neutron.NeutronResource):
if resource.has_interface('OS::Neutron::RouterInterface'):
dep_router_id = resource.properties.get(
RouterInterface.ROUTER_ID)
router_id = self.properties.get(self.ROUTER_ID)
router_id = self.properties[self.ROUTER_ID]
if dep_router_id == router_id:
deps += (self, resource)
# depend on any subnet in this template with the same network_id
@ -452,13 +452,13 @@ class RouterGateway(neutron.NeutronResource):
dep_network = resource.properties.get(
subnet.Subnet.NETWORK) or resource.properties.get(
subnet.Subnet.NETWORK_ID)
network = self.properties.get(
self.NETWORK) or self.properties.get(self.NETWORK_ID)
network = self.properties[
self.NETWORK] or self.properties[self.NETWORK_ID]
if dep_network == network:
deps += (self, resource)
def handle_create(self):
router_id = self.properties.get(self.ROUTER_ID)
router_id = self.properties[self.ROUTER_ID]
network_id = self.client_plugin().resolve_network(
dict(self.properties), self.NETWORK, 'network_id')
self.neutron().add_gateway_router(

View File

@ -134,7 +134,7 @@ class SecurityGroup(neutron.NeutronResource):
def validate(self):
super(SecurityGroup, self).validate()
if self.properties.get(self.NAME) == 'default':
if self.properties[self.NAME] == 'default':
msg = _('Security groups cannot be assigned the name "default".')
raise exception.StackValidationFailed(message=msg)

View File

@ -235,9 +235,9 @@ class Subnet(neutron.NeutronResource):
super(Subnet, self).validate()
self._validate_depr_property_required(self.properties,
self.NETWORK, self.NETWORK_ID)
ra_mode = self.properties.get(self.IPV6_RA_MODE)
address_mode = self.properties.get(self.IPV6_ADDRESS_MODE)
if (self.properties.get(self.IP_VERSION) == 4) and (
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.')

View File

@ -68,7 +68,7 @@ class NovaFloatingIp(resource.Resource):
def handle_create(self):
try:
pool = self.properties.get(self.POOL)
pool = self.properties[self.POOL]
floating_ip = self.nova().floating_ips.create(pool=pool)
except Exception as e:
with excutils.save_and_reraise_exception():

View File

@ -64,7 +64,7 @@ class ServerGroup(resource.Resource):
self.client_plugin('nova').ignore_not_found(e)
def physical_resource_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
return super(ServerGroup, self).physical_resource_name()

View File

@ -499,7 +499,7 @@ class Server(stack_user.StackUser):
self._register_access_key()
def _server_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
@ -507,7 +507,7 @@ class Server(stack_user.StackUser):
def _config_drive(self):
# This method is overridden by the derived CloudServer resource
return self.properties.get(self.CONFIG_DRIVE)
return self.properties[self.CONFIG_DRIVE]
def _populate_deployments_metadata(self, meta):
meta['deployments'] = meta.get('deployments', [])
@ -593,23 +593,23 @@ class Server(stack_user.StackUser):
self.data_set('password', password, True)
def user_data_raw(self):
return self.properties.get(self.USER_DATA_FORMAT) == self.RAW
return self.properties[self.USER_DATA_FORMAT] == self.RAW
def user_data_software_config(self):
return self.properties.get(
self.USER_DATA_FORMAT) == self.SOFTWARE_CONFIG
return self.properties[
self.USER_DATA_FORMAT] == self.SOFTWARE_CONFIG
def transport_poll_server_cfn(self):
return self.properties.get(
self.SOFTWARE_CONFIG_TRANSPORT) == self.POLL_SERVER_CFN
return self.properties[
self.SOFTWARE_CONFIG_TRANSPORT] == self.POLL_SERVER_CFN
def transport_poll_server_heat(self):
return self.properties.get(
self.SOFTWARE_CONFIG_TRANSPORT) == self.POLL_SERVER_HEAT
return self.properties[
self.SOFTWARE_CONFIG_TRANSPORT] == self.POLL_SERVER_HEAT
def transport_poll_temp_url(self):
return self.properties.get(
self.SOFTWARE_CONFIG_TRANSPORT) == self.POLL_TEMP_URL
return self.properties[
self.SOFTWARE_CONFIG_TRANSPORT] == self.POLL_TEMP_URL
def get_software_config(self, ud_content):
try:
@ -621,10 +621,10 @@ class Server(stack_user.StackUser):
return ud_content
def handle_create(self):
security_groups = self.properties.get(self.SECURITY_GROUPS)
security_groups = self.properties[self.SECURITY_GROUPS]
user_data_format = self.properties.get(self.USER_DATA_FORMAT)
ud_content = self.properties.get(self.USER_DATA)
user_data_format = self.properties[self.USER_DATA_FORMAT]
ud_content = self.properties[self.USER_DATA]
if self.user_data_software_config() or self.user_data_raw():
if uuidutils.is_uuid_like(ud_content):
# attempt to load the userdata from software config
@ -652,18 +652,18 @@ class Server(stack_user.StackUser):
flavor = self.properties[self.FLAVOR]
availability_zone = self.properties[self.AVAILABILITY_ZONE]
image = self.properties.get(self.IMAGE)
image = self.properties[self.IMAGE]
if image:
image = self.client_plugin('glance').get_image_id(image)
flavor_id = self.client_plugin().get_flavor_id(flavor)
instance_meta = self.properties.get(self.METADATA)
instance_meta = self.properties[self.METADATA]
if instance_meta is not None:
instance_meta = self.client_plugin().meta_serialize(
instance_meta)
scheduler_hints = self.properties.get(self.SCHEDULER_HINTS)
scheduler_hints = self.properties[self.SCHEDULER_HINTS]
if cfg.CONF.stack_scheduler_hints:
if scheduler_hints is None:
scheduler_hints = {}
@ -672,16 +672,16 @@ class Server(stack_user.StackUser):
scheduler_hints['heat_stack_name'] = self.stack.name
scheduler_hints['heat_path_in_stack'] = self.stack.path_in_stack()
scheduler_hints['heat_resource_name'] = self.name
nics = self._build_nics(self.properties.get(self.NETWORKS))
nics = self._build_nics(self.properties[self.NETWORKS])
block_device_mapping = self._build_block_device_mapping(
self.properties.get(self.BLOCK_DEVICE_MAPPING))
self.properties[self.BLOCK_DEVICE_MAPPING])
block_device_mapping_v2 = self._build_block_device_mapping_v2(
self.properties.get(self.BLOCK_DEVICE_MAPPING_V2))
reservation_id = self.properties.get(self.RESERVATION_ID)
disk_config = self.properties.get(self.DISK_CONFIG)
admin_pass = self.properties.get(self.ADMIN_PASS) or None
personality_files = self.properties.get(self.PERSONALITY)
key_name = self.properties.get(self.KEY_NAME)
self.properties[self.BLOCK_DEVICE_MAPPING_V2])
reservation_id = self.properties[self.RESERVATION_ID]
disk_config = self.properties[self.DISK_CONFIG]
admin_pass = self.properties[self.ADMIN_PASS] or None
personality_files = self.properties[self.PERSONALITY]
key_name = self.properties[self.KEY_NAME]
server = None
try:
@ -912,7 +912,7 @@ class Server(stack_user.StackUser):
# It is not known which subnet a server might be assigned
# to so all subnets in a network should be created before
# the servers in that network.
nets = self.properties.get(self.NETWORKS)
nets = self.properties[self.NETWORKS]
if not nets:
return
for res in six.itervalues(self.stack):
@ -1002,7 +1002,7 @@ class Server(stack_user.StackUser):
def _update_flavor(self, server, prop_diff):
flavor_update_policy = (
prop_diff.get(self.FLAVOR_UPDATE_POLICY) or
self.properties.get(self.FLAVOR_UPDATE_POLICY))
self.properties[self.FLAVOR_UPDATE_POLICY])
flavor = prop_diff[self.FLAVOR]
if flavor_update_policy == 'REPLACE':
@ -1017,7 +1017,7 @@ class Server(stack_user.StackUser):
def _update_image(self, server, prop_diff):
image_update_policy = (
prop_diff.get(self.IMAGE_UPDATE_POLICY) or
self.properties.get(self.IMAGE_UPDATE_POLICY))
self.properties[self.IMAGE_UPDATE_POLICY])
if image_update_policy == 'REPLACE':
raise resource.UpdateReplace(self.name)
image = prop_diff[self.IMAGE]
@ -1027,7 +1027,7 @@ class Server(stack_user.StackUser):
preserve_ephemeral = (
image_update_policy == 'REBUILD_PRESERVE_EPHEMERAL')
password = (prop_diff.get(self.ADMIN_PASS) or
self.properties.get(self.ADMIN_PASS))
self.properties[self.ADMIN_PASS])
return scheduler.TaskRunner(
self.client_plugin().rebuild, server, image_id,
password=password,
@ -1040,7 +1040,7 @@ class Server(stack_user.StackUser):
if not new_networks:
new_networks = []
attach_first_free_port = True
old_networks = self.properties.get(self.NETWORKS)
old_networks = self.properties[self.NETWORKS]
if not server:
server = self.nova().servers.get(self.resource_id)
@ -1180,7 +1180,7 @@ class Server(stack_user.StackUser):
# either volume_id or snapshot_id needs to be specified, but not both
# for block device mapping.
bdm = self.properties.get(self.BLOCK_DEVICE_MAPPING) or []
bdm = self.properties[self.BLOCK_DEVICE_MAPPING] or []
bootable_vol = False
for mapping in bdm:
device_name = mapping[self.BLOCK_DEVICE_MAPPING_DEVICE_NAME]
@ -1198,7 +1198,7 @@ class Server(stack_user.StackUser):
' device mapping %s') % device_name
raise exception.StackValidationFailed(message=msg)
bdm_v2 = self.properties.get(self.BLOCK_DEVICE_MAPPING_V2) or []
bdm_v2 = self.properties[self.BLOCK_DEVICE_MAPPING_V2] or []
if bdm and bdm_v2:
raise exception.ResourcePropertyConflict(
self.BLOCK_DEVICE_MAPPING, self.BLOCK_DEVICE_MAPPING_V2)
@ -1237,7 +1237,7 @@ class Server(stack_user.StackUser):
bootable_vol = self._validate_block_device_mapping()
# make sure the image exists if specified.
image = self.properties.get(self.IMAGE)
image = self.properties[self.IMAGE]
if not image and not bootable_vol:
msg = _('Neither image nor bootable volume is specified for'
' instance %s') % self.name
@ -1245,7 +1245,7 @@ class Server(stack_user.StackUser):
# network properties 'uuid' and 'network' shouldn't be used
# both at once for all networks
networks = self.properties.get(self.NETWORKS) or []
networks = self.properties[self.NETWORKS] or []
# record if any networks include explicit ports
networks_with_port = False
for network in networks:
@ -1284,14 +1284,14 @@ class Server(stack_user.StackUser):
server=self.name))
# retrieve provider's absolute limits if it will be needed
metadata = self.properties.get(self.METADATA)
personality = self.properties.get(self.PERSONALITY)
metadata = self.properties[self.METADATA]
personality = self.properties[self.PERSONALITY]
if metadata is not None or personality:
limits = self.client_plugin().absolute_limits()
# if 'security_groups' present for the server and explict 'port'
# in one or more entries in 'networks', raise validation error
if networks_with_port and self.properties.get(self.SECURITY_GROUPS):
if networks_with_port and self.properties[self.SECURITY_GROUPS]:
raise exception.ResourcePropertyConflict(
self.SECURITY_GROUPS,
"/".join([self.NETWORKS, self.NETWORK_PORT]))

View File

@ -122,7 +122,7 @@ class SaharaCluster(resource.Resource):
raise exception.ResourcePropertyConflict(value, depr_value)
def _cluster_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
return self.physical_resource_name()
@ -146,8 +146,8 @@ class SaharaCluster(resource.Resource):
'img': self.IMAGE, 'tmpl': cluster_template_id}
raise exception.StackValidationFailed(message=msg)
key_name = self.properties.get(self.KEY_NAME)
net_id = self.properties.get(self.MANAGEMENT_NETWORK)
key_name = self.properties[self.KEY_NAME]
net_id = self.properties[self.MANAGEMENT_NETWORK]
if net_id:
if self.is_using_neutron():
net_id = self.client_plugin('neutron').find_neutron_resource(
@ -220,7 +220,7 @@ class SaharaCluster(resource.Resource):
self._validate_depr_keys(self.properties, self.IMAGE_ID, self.IMAGE)
# check if running on neutron and MANAGEMENT_NETWORK missing
if (self.is_using_neutron() and
not self.properties.get(self.MANAGEMENT_NETWORK)):
not self.properties[self.MANAGEMENT_NETWORK]):
msg = _("%s must be provided"
) % self.MANAGEMENT_NETWORK
raise exception.StackValidationFailed(message=msg)

View File

@ -160,7 +160,7 @@ class SaharaNodeGroupTemplate(resource.Resource):
physical_resource_name_limit = 50
def _ngt_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
return self.physical_resource_name()
@ -172,10 +172,10 @@ class SaharaNodeGroupTemplate(resource.Resource):
description = self.properties[self.DESCRIPTION]
flavor_id = self.client_plugin("nova").get_flavor_id(
self.properties[self.FLAVOR])
volumes_per_node = self.properties.get(self.VOLUMES_PER_NODE)
volumes_size = self.properties.get(self.VOLUMES_SIZE)
volume_type = self.properties.get(self.VOLUME_TYPE)
floating_ip_pool = self.properties.get(self.FLOATING_IP_POOL)
volumes_per_node = self.properties[self.VOLUMES_PER_NODE]
volumes_size = self.properties[self.VOLUMES_SIZE]
volume_type = self.properties[self.VOLUME_TYPE]
floating_ip_pool = self.properties[self.FLOATING_IP_POOL]
security_groups = self.properties[self.SECURITY_GROUPS]
auto_security_group = self.properties[self.AUTO_SECURITY_GROUP]
availability_zone = self.properties[self.AVAILABILITY_ZONE]
@ -185,7 +185,7 @@ class SaharaNodeGroupTemplate(resource.Resource):
floating_ip_pool = self.client_plugin(
'neutron').find_neutron_resource(
self.properties, self.FLOATING_IP_POOL, 'network')
node_configs = self.properties.get(self.NODE_CONFIGS)
node_configs = self.properties[self.NODE_CONFIGS]
node_group_template = self.client().node_group_templates.create(
self._ngt_name(),
@ -349,7 +349,7 @@ class SaharaClusterTemplate(resource.Resource):
physical_resource_name_limit = 50
def _cluster_template_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
return self.physical_resource_name()
@ -357,9 +357,9 @@ class SaharaClusterTemplate(resource.Resource):
def handle_create(self):
plugin_name = self.properties[self.PLUGIN_NAME]
hadoop_version = self.properties[self.HADOOP_VERSION]
description = self.properties.get(self.DESCRIPTION)
image_id = self.properties.get(self.IMAGE_ID)
net_id = self.properties.get(self.MANAGEMENT_NETWORK)
description = self.properties[self.DESCRIPTION]
image_id = self.properties[self.IMAGE_ID]
net_id = self.properties[self.MANAGEMENT_NETWORK]
if net_id:
if self.is_using_neutron():
net_id = self.client_plugin('neutron').find_neutron_resource(
@ -367,9 +367,9 @@ class SaharaClusterTemplate(resource.Resource):
else:
net_id = self.client_plugin('nova').get_nova_network_id(
net_id)
anti_affinity = self.properties.get(self.ANTI_AFFINITY)
cluster_configs = self.properties.get(self.CLUSTER_CONFIGS)
node_groups = self.properties.get(self.NODE_GROUPS)
anti_affinity = self.properties[self.ANTI_AFFINITY]
cluster_configs = self.properties[self.CLUSTER_CONFIGS]
node_groups = self.properties[self.NODE_GROUPS]
cluster_template = self.client().cluster_templates.create(
self._cluster_template_name(),
plugin_name, hadoop_version,
@ -402,7 +402,7 @@ class SaharaClusterTemplate(resource.Resource):
return res
# check if running on neutron and MANAGEMENT_NETWORK missing
if (self.is_using_neutron() and
not self.properties.get(self.MANAGEMENT_NETWORK)):
not self.properties[self.MANAGEMENT_NETWORK]):
msg = _("%s must be provided"
) % self.MANAGEMENT_NETWORK
raise exception.StackValidationFailed(message=msg)

View File

@ -109,7 +109,7 @@ class SwiftContainer(resource.Resource):
default_client_name = 'swift'
def physical_resource_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
@ -138,7 +138,7 @@ class SwiftContainer(resource.Resource):
"account", self.properties[self.X_ACCOUNT_META])
for key in (self.X_CONTAINER_READ, self.X_CONTAINER_WRITE):
if self.properties.get(key) is not None:
if self.properties[key] is not None:
container_headers[key] = self.properties[key]
LOG.debug('SwiftContainer create container %(container)s with '

View File

@ -273,7 +273,7 @@ class OSDBInstance(resource.Resource):
return self._dbinstance
def _dbinstance_name(self):
name = self.properties.get(self.NAME)
name = self.properties[self.NAME]
if name:
return name
@ -286,14 +286,14 @@ class OSDBInstance(resource.Resource):
self.flavor = self.client_plugin().get_flavor_id(
self.properties[self.FLAVOR])
self.volume = {'size': self.properties[self.SIZE]}
self.databases = self.properties.get(self.DATABASES)
self.users = self.properties.get(self.USERS)
restore_point = self.properties.get(self.RESTORE_POINT)
self.databases = self.properties[self.DATABASES]
self.users = self.properties[self.USERS]
restore_point = self.properties[self.RESTORE_POINT]
if restore_point:
restore_point = {"backupRef": restore_point}
zone = self.properties.get(self.AVAILABILITY_ZONE)
self.datastore_type = self.properties.get(self.DATASTORE_TYPE)
self.datastore_version = self.properties.get(self.DATASTORE_VERSION)
zone = self.properties[self.AVAILABILITY_ZONE]
self.datastore_type = self.properties[self.DATASTORE_TYPE]
self.datastore_version = self.properties[self.DATASTORE_VERSION]
# convert user databases to format required for troveclient.
# that is, list of database dictionaries
@ -303,7 +303,7 @@ class OSDBInstance(resource.Resource):
# convert networks to format required by troveclient
nics = []
for nic in self.properties.get(self.NICS):
for nic in self.properties[self.NICS]:
nic_dict = {}
net = nic.get(self.NET)
if net:
@ -430,17 +430,17 @@ class OSDBInstance(resource.Resource):
if res:
return res
datastore_type = self.properties.get(self.DATASTORE_TYPE)
datastore_version = self.properties.get(self.DATASTORE_VERSION)
datastore_type = self.properties[self.DATASTORE_TYPE]
datastore_version = self.properties[self.DATASTORE_VERSION]
self.client_plugin().validate_datastore(
datastore_type, datastore_version,
self.DATASTORE_TYPE, self.DATASTORE_VERSION)
# check validity of user and databases
users = self.properties.get(self.USERS)
users = self.properties[self.USERS]
if users:
databases = self.properties.get(self.DATABASES)
databases = self.properties[self.DATABASES]
if not databases:
msg = _('Databases property is required if users property '
'is provided for resource %s.') % self.name
@ -459,7 +459,7 @@ class OSDBInstance(resource.Resource):
# check validity of NICS
is_neutron = self.is_using_neutron()
nics = self.properties.get(self.NICS)
nics = self.properties[self.NICS]
for nic in nics:
if not is_neutron and nic.get(self.PORT):
msg = _("Can not use %s property on Nova-network.") % self.PORT