Merge "Add support of vnic_type to Profile"
This commit is contained in:
commit
32d6cf8b01
|
@ -64,10 +64,10 @@ class ServerProfile(base.Profile):
|
|||
)
|
||||
|
||||
NETWORK_KEYS = (
|
||||
PORT, FIXED_IP, NETWORK, PORT_SECURITY_GROUPS,
|
||||
PORT, VNIC_TYPE, FIXED_IP, NETWORK, PORT_SECURITY_GROUPS,
|
||||
FLOATING_NETWORK, FLOATING_IP,
|
||||
) = (
|
||||
'port', 'fixed_ip', 'network', 'security_groups',
|
||||
'port', 'vnic_type', 'fixed_ip', 'network', 'security_groups',
|
||||
'floating_network', 'floating_ip',
|
||||
)
|
||||
|
||||
|
@ -182,6 +182,9 @@ class ServerProfile(base.Profile):
|
|||
PORT: schema.String(
|
||||
_('Port ID to be used by the network.'),
|
||||
),
|
||||
VNIC_TYPE: schema.String(
|
||||
_('Define vnic_type to be used by port'),
|
||||
),
|
||||
FIXED_IP: schema.String(
|
||||
_('Fixed IP to be used by the network.'),
|
||||
),
|
||||
|
@ -628,6 +631,15 @@ class ServerProfile(base.Profile):
|
|||
) % {'p': self.PORT, 'fip': self.FIXED_IP})
|
||||
result[self.FIXED_IP] = fixed_ip
|
||||
|
||||
# Validate vnic_type input
|
||||
vnic_type = net_spec.get(self.VNIC_TYPE, None)
|
||||
if vnic_type is not None:
|
||||
if vnic_type not in ['normal', 'direct', 'macvtap']:
|
||||
_verify(_("vnic_type: '%(v)s' is not supported."
|
||||
"(supported types are: normal, direct, macvtap)"
|
||||
) % {'v': vnic_type})
|
||||
result[self.VNIC_TYPE] = vnic_type
|
||||
|
||||
# Check security_groups
|
||||
error = self._check_security_groups(nc, net_spec, result)
|
||||
_verify(error)
|
||||
|
@ -661,8 +673,12 @@ class ServerProfile(base.Profile):
|
|||
security_groups = net_spec.get(self.PORT_SECURITY_GROUPS, [])
|
||||
if security_groups:
|
||||
port_attr['security_groups'] = security_groups
|
||||
vnic_type = net_spec.get(self.VNIC_TYPE, None)
|
||||
if vnic_type:
|
||||
port_attr['binding_vnic_type'] = vnic_type
|
||||
try:
|
||||
port = self.network(obj).port_create(**port_attr)
|
||||
LOG.debug('Network port_attr : %s', port)
|
||||
return port, None
|
||||
except exc.InternalError as ex:
|
||||
return None, ex
|
||||
|
|
|
@ -433,6 +433,7 @@ class TestNovaServerBasic(base.SenlinTestCase):
|
|||
expect_params = {
|
||||
'floating_network': None,
|
||||
'network': 'FAKE_NET',
|
||||
'vnic_type': None,
|
||||
'fixed_ip': None,
|
||||
'floating_ip': None,
|
||||
'port': None,
|
||||
|
|
|
@ -1316,32 +1316,38 @@ class TestNovaServerUpdate(base.SenlinTestCase):
|
|||
|
||||
networks_create = [
|
||||
{'floating_network': None, 'network': 'net1', 'fixed_ip': 'ip2',
|
||||
'floating_ip': None, 'port': None, 'security_groups': None},
|
||||
'floating_ip': None, 'port': None, 'vnic_type': None,
|
||||
'security_groups': None},
|
||||
{'floating_network': None, 'network': 'net2', 'fixed_ip': None,
|
||||
'floating_ip': None, 'port': None, 'security_groups': None},
|
||||
'floating_ip': None, 'port': None, 'vnic_type': None,
|
||||
'security_groups': None},
|
||||
{'floating_network': None, 'network': None, 'fixed_ip': None,
|
||||
'floating_ip': None, 'port': 'port4', 'security_groups': None}
|
||||
'floating_ip': None, 'port': 'port4', 'vnic_type': None,
|
||||
'security_groups': None}
|
||||
]
|
||||
mock_create.assert_called_once_with(obj, networks_create)
|
||||
networks_delete = [
|
||||
{'floating_network': None, 'network': 'net1', 'fixed_ip': 'ip1',
|
||||
'floating_ip': None, 'port': None, 'security_groups': None},
|
||||
'floating_ip': None, 'port': None, 'vnic_type': None,
|
||||
'security_groups': None},
|
||||
{'floating_network': None, 'network': 'net1', 'fixed_ip': None,
|
||||
'floating_ip': None, 'port': None, 'security_groups': None},
|
||||
'floating_ip': None, 'port': None, 'vnic_type': None,
|
||||
'security_groups': None},
|
||||
{'floating_network': None, 'network': None, 'fixed_ip': None,
|
||||
'floating_ip': None, 'port': 'port3', 'security_groups': None}
|
||||
'floating_ip': None, 'port': 'port3', 'vnic_type': None,
|
||||
'security_groups': None}
|
||||
]
|
||||
mock_delete.assert_called_once_with(obj, networks_delete)
|
||||
networks_update = [
|
||||
{'network': 'net3', 'port': None, 'fixed_ip': 'ip1',
|
||||
'security_groups': ['default'], 'floating_network': None,
|
||||
'floating_ip': None},
|
||||
'vnic_type': None, 'floating_ip': None},
|
||||
{'network': 'net4', 'port': None, 'fixed_ip': 'ip1',
|
||||
'security_groups': ['default'], 'floating_network': None,
|
||||
'floating_ip': None},
|
||||
'vnic_type': None, 'floating_ip': None},
|
||||
{'network': None, 'port': 'port5', 'fixed_ip': None,
|
||||
'security_groups': ['default', 'blah'], 'floating_network': None,
|
||||
'floating_ip': None}
|
||||
'vnic_type': None, 'floating_ip': None}
|
||||
]
|
||||
mock_update.assert_called_once_with(obj, networks_update)
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ spec = {
|
|||
'floating_network': 'FAKE_FLOATING_NET',
|
||||
'security_groups': ['FAKE_SECURITY_GROUP'],
|
||||
'port': 'FAKE_PORT',
|
||||
'vnic_type': 'direct',
|
||||
'fixed_ip': 'FAKE_IP',
|
||||
'network': 'FAKE_NET',
|
||||
}],
|
||||
|
|
Loading…
Reference in New Issue