|
|
|
@ -25,6 +25,7 @@ import six
|
|
|
|
|
|
|
|
|
|
from networking_arista._i18n import _, _LI, _LW, _LE |
|
|
|
|
from networking_arista.common import constants as const |
|
|
|
|
from networking_arista.common import db_lib |
|
|
|
|
from networking_arista.common import exceptions as arista_exc |
|
|
|
|
from networking_arista.ml2.rpc.base import AristaRPCWrapperBase |
|
|
|
|
|
|
|
|
@ -219,7 +220,7 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
def plug_port_into_network(self, device_id, host_id, port_id, |
|
|
|
|
net_id, tenant_id, port_name, device_owner, |
|
|
|
|
sg, orig_sg, vnic_type, segments, |
|
|
|
|
switch_bindings=None): |
|
|
|
|
switch_bindings=None, trunk_details=None): |
|
|
|
|
if device_owner == n_const.DEVICE_OWNER_DHCP: |
|
|
|
|
self.plug_dhcp_port_into_network(device_id, |
|
|
|
|
host_id, |
|
|
|
@ -229,7 +230,8 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
segments, |
|
|
|
|
port_name) |
|
|
|
|
elif (device_owner.startswith('compute') or |
|
|
|
|
device_owner.startswith('baremetal')): |
|
|
|
|
device_owner.startswith('baremetal') or |
|
|
|
|
device_owner.startswith('trunk')): |
|
|
|
|
if vnic_type == 'baremetal': |
|
|
|
|
self.plug_baremetal_into_network(device_id, |
|
|
|
|
host_id, |
|
|
|
@ -238,9 +240,11 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
tenant_id, |
|
|
|
|
segments, |
|
|
|
|
port_name, |
|
|
|
|
device_owner, |
|
|
|
|
sg, orig_sg, |
|
|
|
|
vnic_type, |
|
|
|
|
switch_bindings) |
|
|
|
|
switch_bindings, |
|
|
|
|
trunk_details) |
|
|
|
|
else: |
|
|
|
|
self.plug_host_into_network(device_id, |
|
|
|
|
host_id, |
|
|
|
@ -248,7 +252,8 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
net_id, |
|
|
|
|
tenant_id, |
|
|
|
|
segments, |
|
|
|
|
port_name) |
|
|
|
|
port_name, |
|
|
|
|
trunk_details) |
|
|
|
|
elif device_owner == n_const.DEVICE_OWNER_DVR_INTERFACE: |
|
|
|
|
self.plug_distributed_router_port_into_network(device_id, |
|
|
|
|
host_id, |
|
|
|
@ -259,7 +264,7 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
|
|
|
|
|
def unplug_port_from_network(self, device_id, device_owner, hostname, |
|
|
|
|
port_id, network_id, tenant_id, sg, vnic_type, |
|
|
|
|
switch_bindings=None): |
|
|
|
|
switch_bindings=None, trunk_details=None): |
|
|
|
|
if device_owner == n_const.DEVICE_OWNER_DHCP: |
|
|
|
|
self.unplug_dhcp_port_from_network(device_id, |
|
|
|
|
hostname, |
|
|
|
@ -267,7 +272,8 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
network_id, |
|
|
|
|
tenant_id) |
|
|
|
|
elif (device_owner.startswith('compute') or |
|
|
|
|
device_owner.startswith('baremetal')): |
|
|
|
|
device_owner.startswith('baremetal') or |
|
|
|
|
device_owner.startswith('trunk')): |
|
|
|
|
if vnic_type == 'baremetal': |
|
|
|
|
self.unplug_baremetal_from_network(device_id, |
|
|
|
|
hostname, |
|
|
|
@ -276,13 +282,15 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
tenant_id, |
|
|
|
|
sg, |
|
|
|
|
vnic_type, |
|
|
|
|
switch_bindings) |
|
|
|
|
switch_bindings, |
|
|
|
|
trunk_details) |
|
|
|
|
else: |
|
|
|
|
self.unplug_host_from_network(device_id, |
|
|
|
|
hostname, |
|
|
|
|
port_id, |
|
|
|
|
network_id, |
|
|
|
|
tenant_id) |
|
|
|
|
tenant_id, |
|
|
|
|
trunk_details) |
|
|
|
|
elif device_owner == n_const.DEVICE_OWNER_DVR_INTERFACE: |
|
|
|
|
self.unplug_distributed_router_port_from_network(device_id, |
|
|
|
|
port_id, |
|
|
|
@ -290,7 +298,8 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
tenant_id) |
|
|
|
|
|
|
|
|
|
def plug_host_into_network(self, vm_id, host, port_id, |
|
|
|
|
network_id, tenant_id, segments, port_name): |
|
|
|
|
network_id, tenant_id, segments, port_name, |
|
|
|
|
trunk_details=None): |
|
|
|
|
cmds = ['tenant %s' % tenant_id, |
|
|
|
|
'vm id %s hostid %s' % (vm_id, host)] |
|
|
|
|
if port_name: |
|
|
|
@ -302,12 +311,28 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
cmds.extend( |
|
|
|
|
'segment level %d id %s' % (level, segment['id']) |
|
|
|
|
for level, segment in enumerate(segments)) |
|
|
|
|
|
|
|
|
|
if trunk_details and trunk_details.get('sub_ports'): |
|
|
|
|
for subport in trunk_details['sub_ports']: |
|
|
|
|
port_id = subport['port_id'] |
|
|
|
|
net_id = self._ndb.get_network_id_from_port_id(port_id) |
|
|
|
|
filters = {'port_id': port_id} |
|
|
|
|
segments = db_lib.get_port_binding_level(filters) |
|
|
|
|
|
|
|
|
|
cmds.append('port id %s network-id %s' % |
|
|
|
|
(port_id, net_id)) |
|
|
|
|
cmds.extend( |
|
|
|
|
'segment level %d id %s' % (s.level, s.segment_id) |
|
|
|
|
for s in segments |
|
|
|
|
) |
|
|
|
|
self._run_openstack_cmds(cmds) |
|
|
|
|
|
|
|
|
|
def plug_baremetal_into_network(self, vm_id, host, port_id, |
|
|
|
|
network_id, tenant_id, segments, port_name, |
|
|
|
|
device_owner, |
|
|
|
|
sg=None, orig_sg=None, |
|
|
|
|
vnic_type=None, switch_bindings=None): |
|
|
|
|
vnic_type=None, switch_bindings=None, |
|
|
|
|
trunk_details=None): |
|
|
|
|
# Basic error checking for baremental deployments |
|
|
|
|
# notice that the following method throws and exception |
|
|
|
|
# if an error condition exists |
|
|
|
@ -325,21 +350,44 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
if not binding: |
|
|
|
|
# skip all empty entries |
|
|
|
|
continue |
|
|
|
|
if device_owner.startswith('trunk'): |
|
|
|
|
vlan_type = 'allowed' |
|
|
|
|
else: |
|
|
|
|
vlan_type = 'native' |
|
|
|
|
# Ensure that binding contains switch and port ID info |
|
|
|
|
if binding['switch_id'] and binding['port_id']: |
|
|
|
|
if port_name: |
|
|
|
|
cmds.append('port id %s name "%s" network-id %s ' |
|
|
|
|
'type native switch-id %s switchport %s' % |
|
|
|
|
'type %s switch-id %s switchport %s' % |
|
|
|
|
(port_id, port_name, network_id, |
|
|
|
|
binding['switch_id'], binding['port_id'])) |
|
|
|
|
vlan_type, binding['switch_id'], |
|
|
|
|
binding['port_id'])) |
|
|
|
|
else: |
|
|
|
|
cmds.append('port id %s network-id %s type native ' |
|
|
|
|
cmds.append('port id %s network-id %s type %s ' |
|
|
|
|
'switch-id %s switchport %s' % |
|
|
|
|
(port_id, network_id, binding['switch_id'], |
|
|
|
|
binding['port_id'])) |
|
|
|
|
(port_id, network_id, vlan_type, |
|
|
|
|
binding['switch_id'], |
|
|
|
|
binding['port_id'])) |
|
|
|
|
cmds.extend('segment level %d id %s' % (level, |
|
|
|
|
segment['id']) |
|
|
|
|
for level, segment in enumerate(segments)) |
|
|
|
|
|
|
|
|
|
if trunk_details and trunk_details.get('sub_ports'): |
|
|
|
|
for subport in trunk_details['sub_ports']: |
|
|
|
|
port_id = subport['port_id'] |
|
|
|
|
net_id = self._ndb.get_network_id_from_port_id( |
|
|
|
|
port_id) |
|
|
|
|
filters = {'port_id': port_id} |
|
|
|
|
segments = db_lib.get_port_binding_level(filters) |
|
|
|
|
|
|
|
|
|
cmds.append('port id %s network-id %s type allowed' |
|
|
|
|
' switch-id %s switchport %s' % |
|
|
|
|
(port_id, net_id, binding['switch_id'], |
|
|
|
|
binding['port_id'])) |
|
|
|
|
cmds.extend( |
|
|
|
|
'segment level %d id %s' % |
|
|
|
|
(s.level, s.segment_id) for s in segments |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
msg = _('switch and port ID not specified for baremetal') |
|
|
|
|
LOG.error(msg) |
|
|
|
@ -385,16 +433,22 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
self._run_openstack_cmds(cmds) |
|
|
|
|
|
|
|
|
|
def unplug_host_from_network(self, vm_id, host, port_id, |
|
|
|
|
network_id, tenant_id): |
|
|
|
|
network_id, tenant_id, trunk_details=None): |
|
|
|
|
cmds = ['tenant %s' % tenant_id, |
|
|
|
|
'vm id %s hostid %s' % (vm_id, host), |
|
|
|
|
'no port id %s' % port_id, |
|
|
|
|
] |
|
|
|
|
if trunk_details and trunk_details.get('sub_ports'): |
|
|
|
|
cmds.extend( |
|
|
|
|
'no port id %s' % subport['port_id'] |
|
|
|
|
for subport in trunk_details['sub_ports'] |
|
|
|
|
) |
|
|
|
|
cmds.append('no port id %s' % port_id) |
|
|
|
|
self._run_openstack_cmds(cmds) |
|
|
|
|
|
|
|
|
|
def unplug_baremetal_from_network(self, vm_id, host, port_id, |
|
|
|
|
network_id, tenant_id, sg, vnic_type, |
|
|
|
|
switch_bindings=None): |
|
|
|
|
switch_bindings=None, |
|
|
|
|
trunk_details=None): |
|
|
|
|
# Basic error checking for baremental deployments |
|
|
|
|
# notice that the following method throws and exception |
|
|
|
|
# if an error condition exists |
|
|
|
@ -403,6 +457,11 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
# Following is a temporary code for native VLANs - should be removed |
|
|
|
|
cmds = ['tenant %s' % tenant_id] |
|
|
|
|
cmds.append('instance id %s hostid %s type baremetal' % (vm_id, host)) |
|
|
|
|
if trunk_details and trunk_details.get('sub_ports'): |
|
|
|
|
cmds.extend( |
|
|
|
|
'no port id %s' % subport['port_id'] |
|
|
|
|
for subport in trunk_details['sub_ports'] |
|
|
|
|
) |
|
|
|
|
cmds.append('no port id %s' % port_id) |
|
|
|
|
self._run_openstack_cmds(cmds) |
|
|
|
|
|
|
|
|
@ -564,7 +623,8 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
'segment level %d id %s' % (level, segment['id']) |
|
|
|
|
for level, segment in enumerate(segments)) |
|
|
|
|
elif (device_owner.startswith('compute') or |
|
|
|
|
device_owner.startswith('baremetal')): |
|
|
|
|
device_owner.startswith('baremetal') or |
|
|
|
|
device_owner.startswith('trunk')): |
|
|
|
|
if vnic_type == 'baremetal': |
|
|
|
|
append_cmd('instance id %s hostid %s type baremetal' % |
|
|
|
|
(vm['vmId'], v_port['hosts'][0])) |
|
|
|
@ -574,21 +634,26 @@ class AristaRPCWrapperEapi(AristaRPCWrapperBase):
|
|
|
|
|
if not binding or not isinstance(binding, dict): |
|
|
|
|
# skip all empty entries |
|
|
|
|
continue |
|
|
|
|
if device_owner.startswith('trunk'): |
|
|
|
|
vlan_type = 'allowed' |
|
|
|
|
else: |
|
|
|
|
vlan_type = 'native' |
|
|
|
|
# Ensure that profile contains local link info |
|
|
|
|
if binding['switch_id'] and binding['port_id']: |
|
|
|
|
if port_name: |
|
|
|
|
cmds.append('port id %s name "%s" ' |
|
|
|
|
'network-id %s type native ' |
|
|
|
|
'network-id %s type %s ' |
|
|
|
|
'switch-id %s switchport %s' % |
|
|
|
|
(port_id, port_name, |
|
|
|
|
network_id, |
|
|
|
|
network_id, vlan_type, |
|
|
|
|
binding['switch_id'], |
|
|
|
|
binding['port_id'])) |
|
|
|
|
else: |
|
|
|
|
cmds.append('port id %s network-id %s ' |
|
|
|
|
'type native ' |
|
|
|
|
'type %s ' |
|
|
|
|
'switch-id %s switchport %s' % |
|
|
|
|
(port_id, network_id, |
|
|
|
|
vlan_type, |
|
|
|
|
binding['switch_id'], |
|
|
|
|
binding['port_id'])) |
|
|
|
|
cmds.extend('segment level %d id %s' % ( |
|
|
|
|