Merge "Define constants for Neutron client resource types"

This commit is contained in:
Zuul 2018-07-24 19:40:14 +00:00 committed by Gerrit Code Review
commit 8cfff53e26
27 changed files with 193 additions and 128 deletions

View File

@ -28,12 +28,28 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
service_types = [NETWORK] = ['network']
res_cmdres_mapping = {
RES_TYPES = (
RES_TYPE_NETWORK, RES_TYPE_SUBNET, RES_TYPE_ROUTER, RES_TYPE_PORT,
RES_TYPE_SUBNET_POOL, RES_TYPE_ADDRESS_SCOPE,
RES_TYPE_SECURITY_GROUP,
RES_TYPE_QOS_POLICY,
RES_TYPE_LOADBALANCER,
RES_TYPE_LB_LISTENER, RES_TYPE_LB_POOL, RES_TYPE_LB_L7POLICY,
) = (
'network', 'subnet', 'router', 'port',
'subnetpool', 'address_scope',
'security_group',
'policy',
'loadbalancer',
'listener', 'pool', 'l7policy',
)
_res_cmdres_mapping = {
# resource: cmd_resource
'policy': 'qos_policy',
'loadbalancer': 'lbaas_loadbalancer',
'pool': 'lbaas_pool',
'l7policy': 'lbaas_l7policy'
RES_TYPE_QOS_POLICY: 'qos_policy',
RES_TYPE_LOADBALANCER: 'lbaas_loadbalancer',
RES_TYPE_LB_POOL: 'lbaas_pool',
RES_TYPE_LB_L7POLICY: 'lbaas_l7policy'
}
def _create(self):
@ -75,8 +91,13 @@ class NeutronClientPlugin(client_plugin.ClientPlugin):
def find_resourceid_by_name_or_id(self, resource, name_or_id,
cmd_resource=None):
"""Find a resource ID given either a name or an ID.
The `resource` argument should be one of the constants defined in
RES_TYPES.
"""
cmd_resource = (cmd_resource or
self.res_cmdres_mapping.get(resource))
self._res_cmdres_mapping.get(resource))
return self._find_resource_id(self.context.tenant_id,
resource, name_or_id,
cmd_resource)

View File

@ -143,10 +143,10 @@ class ManilaShareNetwork(resource.Resource):
self.properties[self.NEUTRON_SUBNET]):
plg = self.client_plugin('neutron')
subnet_id = plg.find_resourceid_by_name_or_id(
'subnet', self.properties[self.NEUTRON_SUBNET])
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(
'network', self.properties[self.NEUTRON_NETWORK])
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.')
@ -155,22 +155,23 @@ class ManilaShareNetwork(resource.Resource):
raise exception.StackValidationFailed(message=msg)
def translation_rules(self, props):
neutron_client_plugin = self.client_plugin('neutron')
translation_rules = [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.NEUTRON_NETWORK],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=neutron_client_plugin.RES_TYPE_NETWORK
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.NEUTRON_SUBNET],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=neutron_client_plugin.RES_TYPE_SUBNET
)
]
return translation_rules

View File

@ -173,6 +173,7 @@ class FloatingIP(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -184,17 +185,17 @@ class FloatingIP(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.FLOATING_NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=client_plugin.RES_TYPE_NETWORK
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FLOATING_SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet',
entity=client_plugin.RES_TYPE_SUBNET
)
]

View File

@ -150,8 +150,9 @@ class HealthMonitor(neutron.NeutronResource):
@property
def lb_id(self):
if self._lb_id is None:
pool_id = self.client_plugin().find_resourceid_by_name_or_id(
self.POOL,
client_plugin = self.client_plugin()
pool_id = client_plugin.find_resourceid_by_name_or_id(
client_plugin.RES_TYPE_LB_POOL,
self.properties[self.POOL])
pool = self.client().show_lbaas_pool(pool_id)['pool']

View File

@ -107,9 +107,10 @@ class L7Rule(neutron.NeutronResource):
@property
def l7policy_id(self):
client_plugin = self.client_plugin()
if self._l7p_id is None:
self._l7p_id = self.client_plugin().find_resourceid_by_name_or_id(
self.L7POLICY,
self._l7p_id = client_plugin.find_resourceid_by_name_or_id(
client_plugin.RES_TYPE_LB_L7POLICY,
self.properties[self.L7POLICY])
return self._l7p_id

View File

@ -154,22 +154,23 @@ class Listener(neutron.NeutronResource):
self._lb_id = None
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.LOADBALANCER],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='loadbalancer'
entity=client_plugin.RES_TYPE_LOADBALANCER
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.DEFAULT_POOL],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='pool'
entity=client_plugin.RES_TYPE_LB_POOL
),
]

View File

@ -126,14 +126,15 @@ class LoadBalancer(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.VIP_SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=client_plugin.RES_TYPE_SUBNET
),
]

View File

@ -154,22 +154,23 @@ class Pool(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.LISTENER],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='listener'
entity=client_plugin.RES_TYPE_LB_LISTENER
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.LOADBALANCER],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='loadbalancer'
entity=client_plugin.RES_TYPE_LOADBALANCER
),
]

View File

@ -134,8 +134,9 @@ class PoolMember(neutron.NeutronResource):
@property
def pool_id(self):
if self._pool_id is None:
self._pool_id = self.client_plugin().find_resourceid_by_name_or_id(
self.POOL,
client_plugin = self.client_plugin()
self._pool_id = client_plugin.find_resourceid_by_name_or_id(
client_plugin.RES_TYPE_LB_POOL,
self.properties[self.POOL])
return self._pool_id

View File

@ -436,6 +436,7 @@ class Pool(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -447,9 +448,9 @@ class Pool(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=client_plugin.RES_TYPE_SUBNET
),
translation.TranslationRule(
props,
@ -457,7 +458,7 @@ class Pool(neutron.NeutronResource):
[self.VIP, self.VIP_SUBNET],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=client_plugin.RES_TYPE_SUBNET
)
]

View File

@ -152,6 +152,7 @@ class NetworkGateway(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -163,9 +164,9 @@ class NetworkGateway(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.CONNECTIONS, self.NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=client_plugin.RES_TYPE_NETWORK
)
]

View File

@ -399,6 +399,7 @@ class Port(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -416,17 +417,17 @@ class Port(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=client_plugin.RES_TYPE_NETWORK
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.FIXED_IPS, self.FIXED_IP_SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=client_plugin.RES_TYPE_SUBNET
)
]

View File

@ -105,15 +105,18 @@ class RBACPolicy(neutron.NeutronResource):
[self.OBJECT_ID],
client_plugin=self.client_plugin(),
finder='find_resourceid_by_name_or_id',
entity=self._get_resource_name(props[self.OBJECT_TYPE])
entity=self._get_client_res_type(props[self.OBJECT_TYPE])
)
]
def _get_resource_name(self, object_type):
resource_name = object_type
if object_type == self.OBJECT_QOS_POLICY:
resource_name = 'policy'
return resource_name
def _get_client_res_type(self, object_type):
client_plugin = self.client_plugin()
if object_type == self.OBJECT_NETWORK:
return client_plugin.RES_TYPE_NETWORK
elif object_type == self.OBJECT_QOS_POLICY:
return client_plugin.RES_TYPE_QOS_POLICY
else:
return object_type
def handle_create(self):
props = self.prepare_properties(

View File

@ -206,23 +206,26 @@ class Router(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
rules = [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.EXTERNAL_GATEWAY, self.EXTERNAL_GATEWAY_NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'),
entity=client_plugin.RES_TYPE_NETWORK
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.EXTERNAL_GATEWAY, self.EXTERNAL_GATEWAY_FIXED_IPS,
self.SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet')
]
entity=client_plugin.RES_TYPE_SUBNET
),
]
if props.get(self.L3_AGENT_ID):
rules.extend([
translation.TranslationRule(
@ -472,6 +475,7 @@ class RouterInterface(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -495,25 +499,25 @@ class RouterInterface(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.PORT],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port'
entity=client_plugin.RES_TYPE_PORT
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.ROUTER],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='router'
entity=client_plugin.RES_TYPE_ROUTER
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=client_plugin.RES_TYPE_SUBNET
)
@ -614,6 +618,7 @@ class RouterGateway(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -625,9 +630,9 @@ class RouterGateway(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=client_plugin.RES_TYPE_NETWORK
)
]

View File

@ -132,22 +132,23 @@ class SecurityGroupRule(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.SECURITY_GROUP],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='security_group'
entity=client_plugin.RES_TYPE_SECURITY_GROUP
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.REMOTE_GROUP],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='security_group'
entity=client_plugin.RES_TYPE_SECURITY_GROUP
),
]

View File

@ -85,14 +85,15 @@ class Segment(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=client_plugin.RES_TYPE_NETWORK
)]
def validate(self):

View File

@ -138,22 +138,23 @@ class FlowClassifier(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.LOGICAL_SOURCE_PORT],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port'
entity=client_plugin.RES_TYPE_PORT
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.LOGICAL_DESTINATION_PORT],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port'
entity=client_plugin.RES_TYPE_PORT
)
]

View File

@ -75,22 +75,23 @@ class PortPair(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.INGRESS],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port'
entity=client_plugin.RES_TYPE_PORT
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.EGRESS],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port'
entity=client_plugin.RES_TYPE_PORT
)
]

View File

@ -306,6 +306,7 @@ class Subnet(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -316,17 +317,17 @@ class Subnet(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.NETWORK],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'
entity=client_plugin.RES_TYPE_NETWORK
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.SUBNETPOOL],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnetpool'
entity=client_plugin.RES_TYPE_SUBNET_POOL
),
translation.TranslationRule(
props,

View File

@ -181,9 +181,11 @@ class SubnetPool(neutron.NeutronResource):
self.properties,
self.physical_resource_name())
if self.ADDRESS_SCOPE in props and props[self.ADDRESS_SCOPE]:
props['address_scope_id'] = self.client_plugin(
).find_resourceid_by_name_or_id(
'address_scope', props.pop(self.ADDRESS_SCOPE))
client_plugin = self.client_plugin()
scope_id = client_plugin.find_resourceid_by_name_or_id(
client_plugin.RES_TYPE_ADDRESS_SCOPE,
props.pop(self.ADDRESS_SCOPE))
props['address_scope_id'] = scope_id
tags = props.pop(self.TAGS, [])
subnetpool = self.client().create_subnetpool(
{'subnetpool': props})['subnetpool']
@ -203,14 +205,14 @@ class SubnetPool(neutron.NeutronResource):
self._validate_prefixes_for_update(prop_diff)
if self.ADDRESS_SCOPE in prop_diff:
if prop_diff[self.ADDRESS_SCOPE]:
prop_diff[
'address_scope_id'] = self.client_plugin(
).find_resourceid_by_name_or_id(
self.client(), 'address_scope',
client_plugin = self.client_plugin()
scope_id = client_plugin.find_resourceid_by_name_or_id(
self.client(),
client_plugin.RES_TYPE_ADDRESS_SCOPE,
prop_diff.pop(self.ADDRESS_SCOPE))
else:
prop_diff[
'address_scope_id'] = prop_diff.pop(self.ADDRESS_SCOPE)
scope_id = prop_diff.pop(self.ADDRESS_SCOPE)
prop_diff['address_scope_id'] = scope_id
if self.TAGS in prop_diff:
tags = prop_diff.pop(self.TAGS)
self.set_tags(tags)

View File

@ -176,22 +176,23 @@ class Trunk(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.PARENT_PORT],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port',
entity=client_plugin.RES_TYPE_PORT
),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
translation_path=[self.SUB_PORTS, self.PORT],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port',
entity=client_plugin.RES_TYPE_PORT
),
]

View File

@ -151,6 +151,7 @@ class VPNService(neutron.NeutronResource):
}
def translation_rules(self, props):
client_plugin = self.client_plugin()
return [
translation.TranslationRule(
props,
@ -162,9 +163,9 @@ class VPNService(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.SUBNET],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'
entity=client_plugin.RES_TYPE_SUBNET
),
translation.TranslationRule(
props,
@ -176,9 +177,9 @@ class VPNService(neutron.NeutronResource):
props,
translation.TranslationRule.RESOLVE,
[self.ROUTER],
client_plugin=self.client_plugin(),
client_plugin=client_plugin,
finder='find_resourceid_by_name_or_id',
entity='router'
entity=client_plugin.RES_TYPE_ROUTER
),
]

View File

@ -88,8 +88,10 @@ class NovaFloatingIp(resource.Resource):
def get_external_network_id(self, pool=None):
if pool:
return self.client_plugin(
'neutron').find_resourceid_by_name_or_id('network', pool)
neutron_plugin = self.client_plugin('neutron')
return neutron_plugin.find_resourceid_by_name_or_id(
neutron_plugin.RES_TYPE_NETWORK,
pool)
ext_filter = {'router:external': True}
ext_nets = self.neutron().list_networks(**ext_filter)['networks']
if len(ext_nets) != 1:

View File

@ -718,6 +718,8 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
default_client_name = 'nova'
def translation_rules(self, props):
neutron_client_plugin = self.client_plugin('neutron')
glance_client_plugin = self.client_plugin('glance')
rules = [
translation.TranslationRule(
props,
@ -734,7 +736,7 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
props,
translation.TranslationRule.RESOLVE,
translation_path=[self.IMAGE],
client_plugin=self.client_plugin('glance'),
client_plugin=glance_client_plugin,
finder='find_image_by_name_or_id'),
translation.TranslationRule(
props,
@ -747,29 +749,30 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
translation.TranslationRule.RESOLVE,
translation_path=[self.BLOCK_DEVICE_MAPPING_V2,
self.BLOCK_DEVICE_MAPPING_IMAGE],
client_plugin=self.client_plugin('glance'),
client_plugin=glance_client_plugin,
finder='find_image_by_name_or_id'),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
translation_path=[self.NETWORKS, self.NETWORK_ID],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network'),
entity=neutron_client_plugin.RES_TYPE_NETWORK),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
translation_path=[self.NETWORKS, self.NETWORK_SUBNET],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='subnet'),
entity=neutron_client_plugin.RES_TYPE_SUBNET),
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
translation_path=[self.NETWORKS, self.NETWORK_PORT],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='port')]
entity=neutron_client_plugin.RES_TYPE_PORT)
]
return rules
def __init__(self, name, json_snippet, stack):
@ -929,8 +932,9 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
client_plugin = self.client_plugin('neutron')
for net_key in reality_nets:
try:
net_id = client_plugin.find_resourceid_by_name_or_id('network',
net_key)
net_id = client_plugin.find_resourceid_by_name_or_id(
client_plugin.RES_TYPE_NETWORK,
net_key)
except Exception as ex:
if (client_plugin.is_not_found(ex) or
client_plugin.is_no_unique(ex)):
@ -1125,8 +1129,9 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
client_plugin = self.client_plugin('neutron')
for key in list(nets.keys()):
try:
net_id = client_plugin.find_resourceid_by_name_or_id('network',
key)
net_id = client_plugin.find_resourceid_by_name_or_id(
client_plugin.RES_TYPE_NETWORK,
key)
except Exception as ex:
if (client_plugin.is_not_found(ex) or
client_plugin.is_no_unique(ex)):

View File

@ -198,6 +198,7 @@ class SaharaCluster(resource.Resource):
entity = 'clusters'
def translation_rules(self, props):
neutron_client_plugin = self.client_plugin('neutron')
rules = [
translation.TranslationRule(
props,
@ -214,9 +215,10 @@ class SaharaCluster(resource.Resource):
props,
translation.TranslationRule.RESOLVE,
[self.MANAGEMENT_NETWORK],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network')]
entity=neutron_client_plugin.RES_TYPE_NETWORK)
]
return rules
def _cluster_name(self):

View File

@ -253,6 +253,7 @@ class SaharaNodeGroupTemplate(resource.Resource):
entity = 'node_group_templates'
def translation_rules(self, props):
neutron_client_plugin = self.client_plugin('neutron')
return [
translation.TranslationRule(
props,
@ -264,9 +265,9 @@ class SaharaNodeGroupTemplate(resource.Resource):
props,
translation.TranslationRule.RESOLVE,
[self.FLOATING_IP_POOL],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network')
entity=neutron_client_plugin.RES_TYPE_NETWORK)
]
def _ngt_name(self, name):
@ -303,13 +304,14 @@ class SaharaNodeGroupTemplate(resource.Resource):
pool = self.properties[self.FLOATING_IP_POOL]
if pool:
if self.is_using_neutron():
neutron_client_plugin = self.client_plugin('neutron')
try:
self.client_plugin(
'neutron').find_resourceid_by_name_or_id('network',
pool)
neutron_client_plugin.find_resourceid_by_name_or_id(
neutron_client_plugin.RES_TYPE_NETWORK,
pool)
except Exception as ex:
if (self.client_plugin('neutron').is_not_found(ex)
or self.client_plugin('neutron').is_no_unique(ex)):
if (neutron_client_plugin.is_not_found(ex)
or neutron_client_plugin.is_no_unique(ex)):
err_msg = encodeutils.exception_to_unicode(ex)
raise exception.StackValidationFailed(message=err_msg)
raise
@ -537,14 +539,16 @@ class SaharaClusterTemplate(resource.Resource):
entity = 'cluster_templates'
def translation_rules(self, props):
neutron_client_plugin = self.client_plugin('neutron')
return [
translation.TranslationRule(
props,
translation.TranslationRule.RESOLVE,
[self.MANAGEMENT_NETWORK],
client_plugin=self.client_plugin('neutron'),
client_plugin=neutron_client_plugin,
finder='find_resourceid_by_name_or_id',
entity='network')]
entity=neutron_client_plugin.RES_TYPE_NETWORK)
]
def _cluster_template_name(self, name):
if name:

View File

@ -348,16 +348,19 @@ class Instance(resource.Resource):
for nic in self.properties[self.NICS]:
nic_dict = {}
net = nic.get(self.NET)
if net:
net_id = self.client_plugin(
'neutron').find_resourceid_by_name_or_id('network',
net)
nic_dict['net-id'] = net_id
port = nic.get(self.PORT)
if port:
if net or port:
neutron = self.client_plugin('neutron')
nic_dict['port-id'] = neutron.find_resourceid_by_name_or_id(
'port', port)
if net:
net_id = neutron.find_resourceid_by_name_or_id(
neutron.RES_TYPE_NETWORK,
net)
nic_dict['net-id'] = net_id
if port:
port_id = neutron.find_resourceid_by_name_or_id(
neutron.RES_TYPE_PORT,
port)
nic_dict['port-id'] = port_id
ip = nic.get(self.V4_FIXED_IP)
if ip:
nic_dict['v4-fixed-ip'] = ip