Merge "Add tag for server nic"
This commit is contained in:
commit
67dc455dc9
|
@ -58,9 +58,9 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
|
||||||
NOVA_API_VERSION = '2.1'
|
NOVA_API_VERSION = '2.1'
|
||||||
|
|
||||||
validate_versions = [
|
validate_versions = [
|
||||||
V2_2, V2_8, V2_10, V2_15, V2_26, V2_37
|
V2_2, V2_8, V2_10, V2_15, V2_26, V2_37, V2_42
|
||||||
] = [
|
] = [
|
||||||
'2.2', '2.8', '2.10', '2.15', '2.26', '2.37'
|
'2.2', '2.8', '2.10', '2.15', '2.26', '2.37', '2.42'
|
||||||
]
|
]
|
||||||
|
|
||||||
supported_versions = [NOVA_API_VERSION] + validate_versions
|
supported_versions = [NOVA_API_VERSION] + validate_versions
|
||||||
|
|
|
@ -110,11 +110,11 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
||||||
_NETWORK_KEYS = (
|
_NETWORK_KEYS = (
|
||||||
NETWORK_UUID, NETWORK_ID, NETWORK_FIXED_IP, NETWORK_PORT,
|
NETWORK_UUID, NETWORK_ID, NETWORK_FIXED_IP, NETWORK_PORT,
|
||||||
NETWORK_SUBNET, NETWORK_PORT_EXTRA, NETWORK_FLOATING_IP,
|
NETWORK_SUBNET, NETWORK_PORT_EXTRA, NETWORK_FLOATING_IP,
|
||||||
ALLOCATE_NETWORK,
|
ALLOCATE_NETWORK, NIC_TAG,
|
||||||
) = (
|
) = (
|
||||||
'uuid', 'network', 'fixed_ip', 'port',
|
'uuid', 'network', 'fixed_ip', 'port',
|
||||||
'subnet', 'port_extra_properties', 'floating_ip',
|
'subnet', 'port_extra_properties', 'floating_ip',
|
||||||
'allocate_network',
|
'allocate_network', 'tag',
|
||||||
)
|
)
|
||||||
|
|
||||||
_SOFTWARE_CONFIG_FORMATS = (
|
_SOFTWARE_CONFIG_FORMATS = (
|
||||||
|
@ -475,6 +475,12 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
_('ID of the floating IP to associate.'),
|
_('ID of the floating IP to associate.'),
|
||||||
support_status=support.SupportStatus(version='6.0.0')
|
support_status=support.SupportStatus(version='6.0.0')
|
||||||
|
),
|
||||||
|
NIC_TAG: properties.Schema(
|
||||||
|
properties.Schema.STRING,
|
||||||
|
_('Port tag. Heat ignores any update on this property '
|
||||||
|
'as nova does not support it.'),
|
||||||
|
support_status=support.SupportStatus(version='9.0.0')
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -818,13 +824,17 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
||||||
|
|
||||||
server = None
|
server = None
|
||||||
try:
|
try:
|
||||||
|
api_version = None
|
||||||
# if 'auto' or 'none' is specified, we get the string type
|
# if 'auto' or 'none' is specified, we get the string type
|
||||||
# nics after self._build_nics(), and the string network
|
# nics after self._build_nics(), and the string network
|
||||||
# is supported since nova microversion 2.37
|
# is supported since nova microversion 2.37
|
||||||
if isinstance(nics, six.string_types):
|
if isinstance(nics, six.string_types):
|
||||||
nc = self.client(version=self.client_plugin().V2_37)
|
api_version = self.client_plugin().V2_37
|
||||||
else:
|
|
||||||
nc = self.client()
|
if self._is_nic_tagged(self.properties[self.NETWORKS]):
|
||||||
|
api_version = self.client_plugin().V2_42
|
||||||
|
|
||||||
|
nc = self.client(version=api_version)
|
||||||
|
|
||||||
server = nc.servers.create(
|
server = nc.servers.create(
|
||||||
name=self._server_name(),
|
name=self._server_name(),
|
||||||
|
@ -1478,6 +1488,19 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
|
||||||
self.SECURITY_GROUPS,
|
self.SECURITY_GROUPS,
|
||||||
"/".join([self.NETWORKS, self.NETWORK_PORT]))
|
"/".join([self.NETWORKS, self.NETWORK_PORT]))
|
||||||
|
|
||||||
|
# Check if nic tag is allowed to use
|
||||||
|
if self._is_nic_tagged(networks=networks):
|
||||||
|
try:
|
||||||
|
self.client(
|
||||||
|
version=self.client_plugin().V2_42)
|
||||||
|
except exception.InvalidServiceVersion as ex:
|
||||||
|
msg = (_('Cannot use "%(tag)s" property in networks - '
|
||||||
|
'nova does not support it: %(error)s')) % {
|
||||||
|
'tag': self.NIC_TAG,
|
||||||
|
'error': six.text_type(ex)
|
||||||
|
}
|
||||||
|
raise exception.StackValidationFailed(message=msg)
|
||||||
|
|
||||||
# Check if tags is allowed to use
|
# Check if tags is allowed to use
|
||||||
if self.properties[self.TAGS]:
|
if self.properties[self.TAGS]:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -252,6 +252,9 @@ class ServerNetworkMixin(object):
|
||||||
self._floating_ip_neutron_associate(
|
self._floating_ip_neutron_associate(
|
||||||
net.get(self.NETWORK_FLOATING_IP), floating_ip_data)
|
net.get(self.NETWORK_FLOATING_IP), floating_ip_data)
|
||||||
|
|
||||||
|
if net.get(self.NIC_TAG):
|
||||||
|
nic_info[self.NIC_TAG] = net.get(self.NIC_TAG)
|
||||||
|
|
||||||
nics.append(nic_info)
|
nics.append(nic_info)
|
||||||
return nics
|
return nics
|
||||||
|
|
||||||
|
@ -459,6 +462,15 @@ class ServerNetworkMixin(object):
|
||||||
if str_net:
|
if str_net:
|
||||||
return str_net
|
return str_net
|
||||||
|
|
||||||
|
def _is_nic_tagged(self, networks):
|
||||||
|
# if user specify 'tag', return True
|
||||||
|
# otherwise return False
|
||||||
|
for net in networks or []:
|
||||||
|
if net.get(self.NIC_TAG):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def calculate_networks(self, old_nets, new_nets, ifaces,
|
def calculate_networks(self, old_nets, new_nets, ifaces,
|
||||||
security_groups=None):
|
security_groups=None):
|
||||||
new_str_net = self._str_network(new_nets)
|
new_str_net = self._str_network(new_nets)
|
||||||
|
|
|
@ -2554,10 +2554,12 @@ class ServersTest(common.HeatTestCase):
|
||||||
|
|
||||||
self.assertIsNone(server._build_nics([]))
|
self.assertIsNone(server._build_nics([]))
|
||||||
self.assertIsNone(server._build_nics(None))
|
self.assertIsNone(server._build_nics(None))
|
||||||
self.assertEqual([{'port-id': 'aaaabbbb', 'net-id': None},
|
self.assertEqual([
|
||||||
{'v4-fixed-ip': '192.0.2.0', 'net-id': None}],
|
{'port-id': 'aaaabbbb', 'net-id': None, 'tag': 'nic1'},
|
||||||
server._build_nics([{'port': 'aaaabbbb'},
|
{'v4-fixed-ip': '192.0.2.0', 'net-id': None}],
|
||||||
{'fixed_ip': '192.0.2.0'}]))
|
server._build_nics([
|
||||||
|
{'port': 'aaaabbbb', 'tag': 'nic1'},
|
||||||
|
{'fixed_ip': '192.0.2.0'}]))
|
||||||
self.assertEqual([{'port-id': 'aaaabbbb', 'net-id': None},
|
self.assertEqual([{'port-id': 'aaaabbbb', 'net-id': None},
|
||||||
{'port-id': 'aaaabbbb', 'net-id': None}],
|
{'port-id': 'aaaabbbb', 'net-id': None}],
|
||||||
server._build_nics([{'port': 'aaaabbbb',
|
server._build_nics([{'port': 'aaaabbbb',
|
||||||
|
@ -3252,11 +3254,12 @@ class ServersTest(common.HeatTestCase):
|
||||||
def create_old_net(self, port=None, net=None,
|
def create_old_net(self, port=None, net=None,
|
||||||
ip=None, uuid=None, subnet=None,
|
ip=None, uuid=None, subnet=None,
|
||||||
port_extra_properties=None, floating_ip=None,
|
port_extra_properties=None, floating_ip=None,
|
||||||
str_network=None):
|
str_network=None, tag=None):
|
||||||
return {'port': port, 'network': net, 'fixed_ip': ip, 'uuid': uuid,
|
return {'port': port, 'network': net, 'fixed_ip': ip, 'uuid': uuid,
|
||||||
'subnet': subnet, 'floating_ip': floating_ip,
|
'subnet': subnet, 'floating_ip': floating_ip,
|
||||||
'port_extra_properties': port_extra_properties,
|
'port_extra_properties': port_extra_properties,
|
||||||
'allocate_network': str_network}
|
'allocate_network': str_network,
|
||||||
|
'tag': tag}
|
||||||
|
|
||||||
def create_fake_iface(self, port, net, ip):
|
def create_fake_iface(self, port, net, ip):
|
||||||
class fake_interface(object):
|
class fake_interface(object):
|
||||||
|
@ -3306,7 +3309,7 @@ class ServersTest(common.HeatTestCase):
|
||||||
for net in new_nets_copy:
|
for net in new_nets_copy:
|
||||||
for key in ('port', 'network', 'fixed_ip', 'uuid', 'subnet',
|
for key in ('port', 'network', 'fixed_ip', 'uuid', 'subnet',
|
||||||
'port_extra_properties', 'floating_ip',
|
'port_extra_properties', 'floating_ip',
|
||||||
'allocate_network'):
|
'allocate_network', 'tag'):
|
||||||
net.setdefault(key)
|
net.setdefault(key)
|
||||||
|
|
||||||
matched_nets = server._exclude_not_updated_networks(old_nets,
|
matched_nets = server._exclude_not_updated_networks(old_nets,
|
||||||
|
@ -3338,7 +3341,7 @@ class ServersTest(common.HeatTestCase):
|
||||||
for net in new_nets_copy:
|
for net in new_nets_copy:
|
||||||
for key in ('port', 'network', 'fixed_ip', 'uuid', 'subnet',
|
for key in ('port', 'network', 'fixed_ip', 'uuid', 'subnet',
|
||||||
'port_extra_properties', 'floating_ip',
|
'port_extra_properties', 'floating_ip',
|
||||||
'allocate_network'):
|
'allocate_network', 'tag'):
|
||||||
net.setdefault(key)
|
net.setdefault(key)
|
||||||
|
|
||||||
matched_nets = server._exclude_not_updated_networks(old_nets, new_nets)
|
matched_nets = server._exclude_not_updated_networks(old_nets, new_nets)
|
||||||
|
@ -3363,7 +3366,8 @@ class ServersTest(common.HeatTestCase):
|
||||||
'uuid': None,
|
'uuid': None,
|
||||||
'port_extra_properties': None,
|
'port_extra_properties': None,
|
||||||
'floating_ip': None,
|
'floating_ip': None,
|
||||||
'allocate_network': None}]
|
'allocate_network': None,
|
||||||
|
'tag': None}]
|
||||||
new_nets_copy = copy.deepcopy(new_nets)
|
new_nets_copy = copy.deepcopy(new_nets)
|
||||||
|
|
||||||
matched_nets = server._exclude_not_updated_networks(old_nets, new_nets)
|
matched_nets = server._exclude_not_updated_networks(old_nets, new_nets)
|
||||||
|
@ -3407,7 +3411,8 @@ class ServersTest(common.HeatTestCase):
|
||||||
'floating_ip': None,
|
'floating_ip': None,
|
||||||
'port_extra_properties': None,
|
'port_extra_properties': None,
|
||||||
'uuid': None,
|
'uuid': None,
|
||||||
'allocate_network': None},
|
'allocate_network': None,
|
||||||
|
'tag': None},
|
||||||
{'port': 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
{'port': 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||||
'network': 'gggggggg-1111-1111-1111-gggggggggggg',
|
'network': 'gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
'fixed_ip': '1.2.3.4',
|
'fixed_ip': '1.2.3.4',
|
||||||
|
@ -3415,7 +3420,8 @@ class ServersTest(common.HeatTestCase):
|
||||||
'port_extra_properties': None,
|
'port_extra_properties': None,
|
||||||
'floating_ip': None,
|
'floating_ip': None,
|
||||||
'uuid': None,
|
'uuid': None,
|
||||||
'allocate_network': None},
|
'allocate_network': None,
|
||||||
|
'tag': None},
|
||||||
{'port': 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
{'port': 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
||||||
'network': 'gggggggg-1111-1111-1111-gggggggggggg',
|
'network': 'gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
'fixed_ip': None,
|
'fixed_ip': None,
|
||||||
|
@ -3423,7 +3429,8 @@ class ServersTest(common.HeatTestCase):
|
||||||
'port_extra_properties': None,
|
'port_extra_properties': None,
|
||||||
'floating_ip': None,
|
'floating_ip': None,
|
||||||
'uuid': None,
|
'uuid': None,
|
||||||
'allocate_network': None},
|
'allocate_network': None,
|
||||||
|
'tag': None},
|
||||||
{'port': 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
{'port': 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
||||||
'network': None,
|
'network': None,
|
||||||
'fixed_ip': None,
|
'fixed_ip': None,
|
||||||
|
@ -3431,7 +3438,8 @@ class ServersTest(common.HeatTestCase):
|
||||||
'port_extra_properties': None,
|
'port_extra_properties': None,
|
||||||
'floating_ip': None,
|
'floating_ip': None,
|
||||||
'uuid': None,
|
'uuid': None,
|
||||||
'allocate_network': None},
|
'allocate_network': None,
|
||||||
|
'tag': None},
|
||||||
{'port': 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
|
{'port': 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
|
||||||
'uuid': 'gggggggg-1111-1111-1111-gggggggggggg',
|
'uuid': 'gggggggg-1111-1111-1111-gggggggggggg',
|
||||||
'fixed_ip': '5.6.7.8',
|
'fixed_ip': '5.6.7.8',
|
||||||
|
@ -3439,7 +3447,8 @@ class ServersTest(common.HeatTestCase):
|
||||||
'port_extra_properties': None,
|
'port_extra_properties': None,
|
||||||
'floating_ip': None,
|
'floating_ip': None,
|
||||||
'network': None,
|
'network': None,
|
||||||
'allocate_network': None}]
|
'allocate_network': None,
|
||||||
|
'tag': None}]
|
||||||
|
|
||||||
self.patchobject(neutron.NeutronClientPlugin,
|
self.patchobject(neutron.NeutronClientPlugin,
|
||||||
'find_resourceid_by_name_or_id',
|
'find_resourceid_by_name_or_id',
|
||||||
|
|
Loading…
Reference in New Issue