4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 import netifaces as ni
17 from cmframework.apis import cmuserconfig
18 from cmframework.apis import cmerror
19 from cmdatahandlers.api import configerror
20 from cmdatahandlers.api import utils
22 This plugin is used to define the installation node in the system
24 class installhandler(cmuserconfig.CMUserConfigPlugin):
26 super(installhandler,self).__init__()
28 def handle(self, confman):
30 hostsconf = confman.get_hosts_config_handler()
31 hostname = 'controller-1'
32 if not utils.is_virtualized():
33 ownip = utils.get_own_hwmgmt_ip()
34 hostname = hostsconf.get_host_having_hwmgmt_address(ownip)
38 for host in hostsconf.get_hosts():
40 mgmt_addr[host] = hostsconf.get_mgmt_mac(host)[0]
43 for interface in ni.interfaces():
44 a = ni.ifaddresses(interface)
46 for mac in a[ni.AF_LINK]:
47 mac_list.append(mac.get('addr', None))
48 for host, mgmt_mac in mgmt_addr.iteritems():
49 if mgmt_mac in mac_list:
50 hostsconf.set_installation_host(host)
53 hostsconf.set_installation_host(hostname)
54 except configerror.ConfigError as exp:
55 raise cmerror.CMError(str(exp))