|
1 # Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. |
|
2 # |
|
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may |
|
4 # not use this file except in compliance with the License. You may obtain |
|
5 # a copy of the License at |
|
6 # |
|
7 # http://www.apache.org/licenses/LICENSE-2.0 |
|
8 # |
|
9 # Unless required by applicable law or agreed to in writing, software |
|
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
12 # License for the specific language governing permissions and limitations |
|
13 # under the License. |
|
14 # |
|
15 # @author: Girish Moodalbail, Oracle, Inc. |
|
16 |
|
17 from oslo.config import cfg |
|
18 |
|
19 from quantum.agent.linux import utils |
|
20 from quantum.agent.solaris import net_lib |
|
21 |
|
22 |
|
23 OPTS = [ |
|
24 cfg.StrOpt('evs_controller', default='ssh://evsuser@localhost', |
|
25 help=_("An URI that specifies an EVS controller")) |
|
26 ] |
|
27 |
|
28 |
|
29 class SolarisVNICDriver(object): |
|
30 """Driver used to manage Solaris EVS VNICs. |
|
31 |
|
32 This class provides methods to create/delete an EVS VNIC and |
|
33 plumb/unplumb ab IP interface and addresses on the EVS VNIC. |
|
34 """ |
|
35 |
|
36 # TODO(gmoodalb): dnsmasq uses old style `ifreq', so 16 is the maximum |
|
37 # length including the NUL character. If we change it to use new style |
|
38 # `lifreq', then we will be able to extend the length to 32 characters. |
|
39 VNIC_NAME_MAXLEN = 15 |
|
40 VNIC_NAME_PREFIX = 'evs' |
|
41 VNIC_NAME_SUFFIX = '_0' |
|
42 VNIC_NAME_LEN_WO_SUFFIX = VNIC_NAME_MAXLEN - \ |
|
43 len(VNIC_NAME_SUFFIX) |
|
44 |
|
45 def __init__(self, conf): |
|
46 self.conf = conf |
|
47 # Since there is no connect_uri() yet, we need to do this ourselves |
|
48 # parse ssh://user@hostname |
|
49 suh = self.conf.evs_controller.split('://') |
|
50 if len(suh) != 2 or suh[0] != 'ssh' or not suh[1].strip(): |
|
51 raise SystemExit(_("Specified evs_controller is invalid")) |
|
52 uh = suh[1].split('@') |
|
53 if len(uh) != 2 or not uh[0].strip() or not uh[1].strip(): |
|
54 raise SystemExit(_("'user' and 'hostname' need to be specified " |
|
55 "for evs_controller")) |
|
56 |
|
57 # set the controller property for this host |
|
58 cmd = ['/usr/sbin/evsadm', 'show-prop', '-co', 'value', '-p', |
|
59 'controller'] |
|
60 stdout = utils.execute(cmd) |
|
61 if conf.evs_controller != stdout.strip(): |
|
62 cmd = ['/usr/sbin/evsadm', 'set-prop', '-p', |
|
63 'controller=%s' % (conf.evs_controller)] |
|
64 utils.execute(cmd) |
|
65 |
|
66 def fini_l3(self, device_name): |
|
67 ipif = net_lib.IPInterface(device_name) |
|
68 ipif.delete_ip() |
|
69 |
|
70 def init_l3(self, device_name, ip_cidrs): |
|
71 """Set the L3 settings for the interface using data from the port. |
|
72 ip_cidrs: list of 'X.X.X.X/YY' strings |
|
73 """ |
|
74 ipif = net_lib.IPInterface(device_name) |
|
75 for ip_cidr in ip_cidrs: |
|
76 ipif.create_address(ip_cidr) |
|
77 |
|
78 # TODO(gmoodalb): - probably take PREFIX?? for L3 |
|
79 def get_device_name(self, port): |
|
80 vnicname = (self.VNIC_NAME_PREFIX + |
|
81 port.id)[:self.VNIC_NAME_LEN_WO_SUFFIX] |
|
82 vnicname += self.VNIC_NAME_SUFFIX |
|
83 return vnicname.replace('-', '_') |
|
84 |
|
85 def plug(self, tenant_id, network_id, port_id, datalink_name, |
|
86 namespace=None, prefix=None): |
|
87 """Plug in the interface.""" |
|
88 |
|
89 evs_vport = ('%s/%s') % (network_id, port_id) |
|
90 dl = net_lib.Datalink(datalink_name) |
|
91 dl.connect_vnic(evs_vport, tenant_id) |
|
92 |
|
93 def unplug(self, device_name, namespace=None, prefix=None): |
|
94 """Unplug the interface.""" |
|
95 |
|
96 dl = net_lib.Datalink(device_name) |
|
97 dl.delete_vnic() |