summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--compass-cobbler/Dockerfile8
-rwxr-xr-xcompass-cobbler/fence_libvirt106
-rw-r--r--compass-cobbler/fence_libvirt.template4
-rw-r--r--compass-deck/apiclient/restful.py24
-rw-r--r--compass-deck/db/api/cluster.py6
-rw-r--r--compass-deck/db/api/machine.py24
-rw-r--r--compass-deck/db/api/switch.py22
-rw-r--r--compass-deck/db/api/utils.py35
-rw-r--r--compass-deck/db/models.py15
-rw-r--r--compass-tasks-base/apiclient/restful.py24
-rw-r--r--compass-tasks-base/db/api/cluster.py6
-rw-r--r--compass-tasks-base/db/api/machine.py24
-rw-r--r--compass-tasks-base/db/api/switch.py22
-rw-r--r--compass-tasks-base/db/api/utils.py35
-rw-r--r--compass-tasks-base/db/models.py15
-rw-r--r--compass-tasks-base/deployment/deploy_manager.py29
-rw-r--r--compass-tasks-base/deployment/installers/config_manager.py22
-rw-r--r--compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py28
-rw-r--r--compass-tasks-base/deployment/utils/constants.py4
19 files changed, 298 insertions, 155 deletions
diff --git a/compass-cobbler/Dockerfile b/compass-cobbler/Dockerfile
index e5c1459..9ee1e64 100644
--- a/compass-cobbler/Dockerfile
+++ b/compass-cobbler/Dockerfile
@@ -7,7 +7,7 @@ ARG BRANCH=master
RUN yum -y update && \
yum -y install epel-release && \
yum -y install wget dhcp bind syslinux pykickstart file initscripts net-tools tcpdump xinetd vim \
- avahi avahi-tools ntp fence_agents && \
+ avahi avahi-tools ntp fence-agents libvirt-devel python-devel gcc python-pip && \
wget http://artifacts.opnfv.org/compass4nfv/package/cobbler/cobbler-2.6.10-1.fc22.noarch.rpm && \
wget http://artifacts.opnfv.org/compass4nfv/package/cobbler/cobbler-web-2.6.10-1.fc22.noarch.rpm && \
yum -y localinstall cobbler-2.6.10-1.fc22.noarch.rpm cobbler-web-2.6.10-1.fc22.noarch.rpm && \
@@ -16,7 +16,11 @@ RUN yum -y update && \
systemctl enable httpd && \
systemctl enable dhcpd && \
systemctl enable xinetd && \
- systemctl enable ntpd
+ systemctl enable ntpd && \
+ pip install libvirt-python click
+
+COPY fence_libvirt /usr/sbin/fence_libvirt
+COPY fence_libvirt.template /etc/cobbler/power/fence_libvirt.template
# some tweaks on services
RUN sed -i -e 's/\(^.*disable.*=\) yes/\1 no/' /etc/xinetd.d/tftp && \
diff --git a/compass-cobbler/fence_libvirt b/compass-cobbler/fence_libvirt
new file mode 100755
index 0000000..a59373b
--- /dev/null
+++ b/compass-cobbler/fence_libvirt
@@ -0,0 +1,106 @@
+#!/usr/bin/env python
+import libvirt
+import yaml
+import multiprocessing
+import click
+import sys
+
+
+SETTING = "/root/cobbler/settings"
+power_action_map = {
+ "on": "create",
+ "off": "destroy",
+ "status": "state"
+ }
+
+def get_virt_host(setting_file):
+ with open(setting_file) as fd:
+ try:
+ settings = yaml.load(fd)
+ return settings['server']
+ except Exception:
+ raise RuntimeError("Can't get server ip from %s" % SETTING)
+
+
+def get_libvit_connection(user, passwd):
+ # def request_cred(credentials, user_data):
+ # for credential in credentials:
+ # if credential[0] == libvirt.VIR_CRED_AUTHNAME:
+ # credential[4] = user
+ # elif credential[0] == libvirt.VIR_CRED_PASSPHRASE:
+ # credential[4] = passwd
+ # return 0
+ # auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_PASSPHRASE],
+ # request_cred, None]
+ server = get_virt_host(SETTING)
+ conn = libvirt.open('qemu+tcp://%s/system' % server)
+ return conn
+
+
+def libvirt_function(domain, action, rc):
+ function = getattr(domain, power_action_map.get(action))
+ state, reason = domain.state()
+ if function.__name__ == "create":
+ if state == libvirt.VIR_DOMAIN_RUNNING:
+ rc.value = 1
+ else:
+ rc.value = function()
+ elif function.__name__ == "destroy":
+ if state == libvirt.VIR_DOMAIN_SHUTOFF:
+ rc.value = 1
+ else:
+ rc.value = function()
+ elif function.__name__ == "state":
+ rc.value = state
+
+
+def power_action(action, hostname, user, passwd):
+ conn = get_libvit_connection(user, passwd)
+ domain = conn.lookupByName(hostname)
+ rc = multiprocessing.Value('i')
+ p = multiprocessing.Process(target=libvirt_function,
+ args=(domain, action, rc,))
+ p.start()
+ p.join()
+ print rc.value
+ return rc.value
+
+
+@click.command()
+@click.option("--action")
+@click.option("--hostname")
+@click.option("--user")
+@click.option("--passwd")
+def cli(action, hostname, user, passwd):
+ power_action(action, hostname, user, passwd)
+
+
+def no_cli():
+ opt = {}
+ for line in sys.stdin.readlines():
+ try:
+ line = line.strip()
+ name, value = line.split("=")
+ opt.update({name: value})
+ except Exception:
+ continue
+ try:
+ if opt["action"] and opt["hostname"]:
+ power_action(opt["action"], opt["hostname"],
+ opt["user"], opt["passwd"])
+ else:
+ raise RuntimeError("Invalid argument, \
+ action: {0}, hostname: {1}, user: {2}, passwd: {3}".format(
+ opt.get("action", None), opt.get("hostname", None),
+ opt.get("user", None), opt.get("action", None)))
+
+
+def main():
+ if len(sys.argv) > 1:
+ cli()
+ else:
+ no_cli()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/compass-cobbler/fence_libvirt.template b/compass-cobbler/fence_libvirt.template
new file mode 100644
index 0000000..2e38628
--- /dev/null
+++ b/compass-cobbler/fence_libvirt.template
@@ -0,0 +1,4 @@
+action=$power_mode
+hostname=$hostname
+user=$power_user
+passwd=$power_pass
diff --git a/compass-deck/apiclient/restful.py b/compass-deck/apiclient/restful.py
index bb82922..f5d4855 100644
--- a/compass-deck/apiclient/restful.py
+++ b/compass-deck/apiclient/restful.py
@@ -231,7 +231,7 @@ class Client(object):
return self._get('/switches/%s/machines-hosts' % switch_id, data=data)
def add_switch_machine(self, switch_id, mac=None, port=None,
- vlans=None, ipmi_credentials=None,
+ vlans=None, power_manage=None,
tag=None, location=None, raw_data=None):
data = {}
if raw_data:
@@ -246,8 +246,8 @@ class Client(object):
if vlans:
data['vlans'] = vlans
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
@@ -258,7 +258,7 @@ class Client(object):
return self._post('/switches/%s/machines' % switch_id, data=data)
def update_switch_machine(self, switch_id, machine_id, port=None,
- vlans=None, ipmi_credentials=None, tag=None,
+ vlans=None, power_manage=None, tag=None,
location=None, raw_data=None):
data = {}
if raw_data:
@@ -270,8 +270,8 @@ class Client(object):
if vlans:
data['vlans'] = vlans
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
@@ -412,14 +412,14 @@ class Client(object):
return self._get('/machines/%s' % machine_id, data=data)
- def update_machine(self, machine_id, ipmi_credentials=None, tag=None,
+ def update_machine(self, machine_id, power_manage=None, tag=None,
location=None, raw_data=None):
data = {}
if raw_data:
data = raw_data
else:
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
@@ -429,15 +429,15 @@ class Client(object):
return self._put('/machines/%s' % machine_id, data=data)
- def patch_machine(self, machine_id, ipmi_credentials=None,
+ def patch_machine(self, machine_id, power_manage=None,
tag=None, location=None,
raw_data=None):
data = {}
if raw_data:
data = raw_data
else:
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
diff --git a/compass-deck/db/api/cluster.py b/compass-deck/db/api/cluster.py
index 9a0b8f0..82bcaab 100644
--- a/compass-deck/db/api/cluster.py
+++ b/compass-deck/db/api/cluster.py
@@ -48,9 +48,9 @@ RESP_CLUSTERHOST_FIELDS = [
'cluster_id', 'clustername', 'location', 'tag',
'networks', 'mac', 'switch_ip', 'port', 'switches',
'os_installed', 'distributed_system_installed',
- 'os_name', 'os_id', 'ip',
- 'reinstall_os', 'reinstall_distributed_system',
- 'owner', 'cluster_id', 'ipmi_credentials',
+ 'os_name', 'os_id', 'ip', 'reinstall_os',
+ 'reinstall_distributed_system', 'owner', 'cluster_id',
+ 'power_type', 'power_manage',
'created_at', 'updated_at',
'patched_roles'
]
diff --git a/compass-deck/db/api/machine.py b/compass-deck/db/api/machine.py
index 4222288..5b3cea0 100644
--- a/compass-deck/db/api/machine.py
+++ b/compass-deck/db/api/machine.py
@@ -29,20 +29,20 @@ from compass.utils import util
MACHINE_PRIMARY_FILEDS = ['mac', 'owner_id']
SUPPORTED_FIELDS = [
- 'mac', 'tag', 'location', 'ipmi_credentials',
- 'machine_attributes', 'owner_id']
+ 'mac', 'tag', 'location', 'power_manage',
+ 'machine_attributes', 'owner_id', 'power_type']
IGNORE_FIELDS = ['id', 'created_at', 'updated_at']
UPDATED_FIELDS = [
- 'ipmi_credentials', 'machine_attributes',
- 'tag', 'location']
+ 'mac', 'tag', 'location', 'power_manage',
+ 'machine_attributes', 'power_type']
PATCHED_FIELDS = [
- 'patched_ipmi_credentials', 'patched_tag',
+ 'patched_power_manage', 'patched_tag',
'patched_location'
]
RESP_FIELDS = [
- 'id', 'mac', 'ipmi_credentials', 'switches', 'switch_ip',
+ 'id', 'mac', 'power_manage', 'switches', 'switch_ip',
'port', 'vlans', 'machine_attributes', 'owner_id',
- 'tag', 'location', 'created_at', 'updated_at'
+ 'tag', 'location', 'power_type', 'created_at', 'updated_at'
]
RESP_DEPLOY_FIELDS = [
'status', 'machine'
@@ -149,7 +149,7 @@ def _update_machine(machine_id, session=None, **kwargs):
optional_support_keys=UPDATED_FIELDS,
ignore_support_keys=IGNORE_FIELDS
)
-@utils.input_validates(ipmi_credentials=utils.check_ipmi_credentials)
+@utils.input_validates(power_manage=utils.check_power_manage)
@database.run_in_session()
@user_api.check_user_permission(
permission.PERMISSION_ADD_MACHINE
@@ -161,11 +161,11 @@ def update_machine(machine_id, user=None, session=None, **kwargs):
)
-# replace [ipmi_credentials, tag, location] to
-# [patched_ipmi_credentials, patched_tag, patched_location]
+# replace [power_manage, tag, location] to
+# [patched_power_manage, patched_tag, patched_location]
# in kwargs. It tells db these fields will be patched.
@utils.replace_filters(
- ipmi_credentials='patched_ipmi_credentials',
+ power_manage='patched_power_manage',
tag='patched_tag',
location='patched_location'
)
@@ -174,7 +174,7 @@ def update_machine(machine_id, user=None, session=None, **kwargs):
ignore_support_keys=IGNORE_FIELDS
)
@database.run_in_session()
-@utils.output_validates(ipmi_credentials=utils.check_ipmi_credentials)
+@utils.output_validates(power_manage=utils.check_power_manage)
@user_api.check_user_permission(
permission.PERMISSION_ADD_MACHINE
)
diff --git a/compass-deck/db/api/switch.py b/compass-deck/db/api/switch.py
index 647eec0..92d7a7f 100644
--- a/compass-deck/db/api/switch.py
+++ b/compass-deck/db/api/switch.py
@@ -58,17 +58,17 @@ UPDATED_FILTERS_FIELDS = ['put_machine_filters']
PATCHED_FILTERS_FIELDS = ['patched_machine_filters']
ADDED_MACHINES_FIELDS = ['mac']
OPTIONAL_ADDED_MACHINES_FIELDS = [
- 'ipmi_credentials', 'tag', 'location', 'owner_id'
+ 'power_manage', 'tag', 'location', 'owner_id'
]
ADDED_SWITCH_MACHINES_FIELDS = ['port']
OPTIONAL_ADDED_SWITCH_MACHINES_FIELDS = ['vlans']
UPDATED_MACHINES_FIELDS = [
- 'ipmi_credentials',
+ 'power_manage',
'tag', 'location'
]
UPDATED_SWITCH_MACHINES_FIELDS = ['port', 'vlans', 'owner_id']
PATCHED_MACHINES_FIELDS = [
- 'patched_ipmi_credentials',
+ 'patched_power_manage',
'patched_tag', 'patched_location'
]
PATCHED_SWITCH_MACHINES_FIELDS = ['patched_vlans']
@@ -85,13 +85,13 @@ RESP_ACTION_FIELDS = [
RESP_MACHINES_FIELDS = [
'id', 'switch_id', 'switch_ip', 'machine_id', 'switch_machine_id',
'port', 'vlans', 'mac', 'owner_id',
- 'ipmi_credentials', 'tag', 'location',
+ 'power_manage', 'tag', 'location',
'created_at', 'updated_at'
]
RESP_MACHINES_HOSTS_FIELDS = [
'id', 'switch_id', 'switch_ip', 'machine_id', 'switch_machine_id',
'port', 'vlans', 'mac',
- 'ipmi_credentials', 'tag', 'location', 'ip',
+ 'power_manage', 'tag', 'location', 'ip',
'name', 'hostname', 'os_name', 'owner',
'os_installer', 'reinstall_os', 'os_installed',
'clusters', 'created_at', 'updated_at'
@@ -988,13 +988,13 @@ def update_switchmachine(switch_machine_id, user=None, session=None, **kwargs):
)
-# replace [vlans, ipmi_credentials, tag, location] to
-# [patched_vlans, patched_ipmi_credentials, patched_tag,
+# replace [vlans, power_manage, tag, location] to
+# [patched_vlans, patched_power_manage, patched_tag,
# patched_location] in kwargs. It tells db these fields will
# be patched.
@utils.replace_filters(
vlans='patched_vlans',
- ipmi_credentials='patched_ipmi_credentials',
+ power_manage='patched_power_manage',
tag='patched_tag',
location='patched_location'
)
@@ -1024,13 +1024,13 @@ def patch_switch_machine(
)
-# replace [vlans, ipmi_credentials, tag, location] to
-# [patched_vlans, patched_ipmi_credentials, patched_tag,
+# replace [vlans, power_manage, tag, location] to
+# [patched_vlans, patched_power_manage, patched_tag,
# patched_location] in kwargs. It tells db these fields will
# be patched.
@utils.replace_filters(
vlans='patched_vlans',
- ipmi_credentials='patched_ipmi_credentials',
+ power_manage='patched_power_manage',
tag='patched_tag',
location='patched_location'
)
diff --git a/compass-deck/db/api/utils.py b/compass-deck/db/api/utils.py
index a44f26e..ef975ef 100644
--- a/compass-deck/db/api/utils.py
+++ b/compass-deck/db/api/utils.py
@@ -1208,42 +1208,41 @@ def check_name(name):
)
-def _check_ipmi_credentials_ip(ip):
+def _check_power_manage_ip(ip):
check_ip(ip)
-def check_ipmi_credentials(ipmi_credentials):
- """Check ipmi credentials format is correct."""
- if not ipmi_credentials:
+def check_power_manage(power_manage):
+ """Check power manage format is correct."""
+ if not power_manage:
return
- if not isinstance(ipmi_credentials, dict):
+ if not isinstance(power_manage, dict):
raise exception.InvalidParameter(
- 'invalid ipmi credentials %s' % ipmi_credentials
-
+ 'invalid power manage %s' % power_manage
)
- for key in ipmi_credentials:
+ for key in power_manage:
if key not in ['ip', 'username', 'password']:
raise exception.InvalidParameter(
- 'unrecognized field %s in ipmi credentials %s' % (
- key, ipmi_credentials
+ 'unrecognized field %s in power manage %s' % (
+ key, power_manage
)
)
for key in ['ip', 'username', 'password']:
- if key not in ipmi_credentials:
+ if key not in power_manage:
raise exception.InvalidParameter(
- 'no field %s in ipmi credentials %s' % (
- key, ipmi_credentials
+ 'no field %s in power manage %s' % (
+ key, power_manage
)
)
- check_ipmi_credential_field = '_check_ipmi_credentials_%s' % key
+ check_power_manage_field = '_check_power_manage_%s' % key
this_module = globals()
- if check_ipmi_credential_field in this_module:
- this_module[check_ipmi_credential_field](
- ipmi_credentials[key]
+ if check_power_manage_field in this_module:
+ this_module[check_power_manage_field](
+ power_manage[key]
)
else:
logging.debug(
- 'function %s is not defined', check_ipmi_credential_field
+ 'function %s is not defined', check_power_manage_field
)
diff --git a/compass-deck/db/models.py b/compass-deck/db/models.py
index 929f4dc..e312f61 100644
--- a/compass-deck/db/models.py
+++ b/compass-deck/db/models.py
@@ -1533,10 +1533,11 @@ class Machine(BASE, HelperMixin, TimestampMixin):
__tablename__ = 'machine'
id = Column(Integer, primary_key=True)
mac = Column(JSONEncoded, nullable=False)
- ipmi_credentials = Column(JSONEncoded, default={})
tag = Column(JSONEncoded, default={})
location = Column(JSONEncoded, default={})
owner_id = Column(Integer, nullable=True)
+ power_type = Column(String(10), default="ipmilan")
+ power_manage = Column(JSONEncoded, default={})
machine_attributes = Column(JSONEncoded, default={})
switch_machines = relationship(
@@ -1572,15 +1573,15 @@ class Machine(BASE, HelperMixin, TimestampMixin):
)
@property
- def patched_ipmi_credentials(self):
- return self.ipmi_credentials
+ def patched_power_manage(self):
+ return self.power_manage
- @patched_ipmi_credentials.setter
- def patched_ipmi_credentials(self, value):
+ @patched_power_manage.setter
+ def patched_power_manage(self, value):
if not value:
return
- ipmi_credentials = copy.deepcopy(self.ipmi_credentials)
- self.ipmi_credentials = util.merge_dict(ipmi_credentials, value)
+ power_manage = copy.deepcopy(self.power_manage)
+ self.power_manage = util.merge_dict(power_manage, value)
@property
def patched_tag(self):
diff --git a/compass-tasks-base/apiclient/restful.py b/compass-tasks-base/apiclient/restful.py
index bb82922..f5d4855 100644
--- a/compass-tasks-base/apiclient/restful.py
+++ b/compass-tasks-base/apiclient/restful.py
@@ -231,7 +231,7 @@ class Client(object):
return self._get('/switches/%s/machines-hosts' % switch_id, data=data)
def add_switch_machine(self, switch_id, mac=None, port=None,
- vlans=None, ipmi_credentials=None,
+ vlans=None, power_manage=None,
tag=None, location=None, raw_data=None):
data = {}
if raw_data:
@@ -246,8 +246,8 @@ class Client(object):
if vlans:
data['vlans'] = vlans
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
@@ -258,7 +258,7 @@ class Client(object):
return self._post('/switches/%s/machines' % switch_id, data=data)
def update_switch_machine(self, switch_id, machine_id, port=None,
- vlans=None, ipmi_credentials=None, tag=None,
+ vlans=None, power_manage=None, tag=None,
location=None, raw_data=None):
data = {}
if raw_data:
@@ -270,8 +270,8 @@ class Client(object):
if vlans:
data['vlans'] = vlans
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
@@ -412,14 +412,14 @@ class Client(object):
return self._get('/machines/%s' % machine_id, data=data)
- def update_machine(self, machine_id, ipmi_credentials=None, tag=None,
+ def update_machine(self, machine_id, power_manage=None, tag=None,
location=None, raw_data=None):
data = {}
if raw_data:
data = raw_data
else:
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
@@ -429,15 +429,15 @@ class Client(object):
return self._put('/machines/%s' % machine_id, data=data)
- def patch_machine(self, machine_id, ipmi_credentials=None,
+ def patch_machine(self, machine_id, power_manage=None,
tag=None, location=None,
raw_data=None):
data = {}
if raw_data:
data = raw_data
else:
- if ipmi_credentials:
- data['ipmi_credentials'] = ipmi_credentials
+ if power_manage:
+ data['power_manage'] = power_manage
if tag:
data['tag'] = tag
diff --git a/compass-tasks-base/db/api/cluster.py b/compass-tasks-base/db/api/cluster.py
index 9a0b8f0..82bcaab 100644
--- a/compass-tasks-base/db/api/cluster.py
+++ b/compass-tasks-base/db/api/cluster.py
@@ -48,9 +48,9 @@ RESP_CLUSTERHOST_FIELDS = [
'cluster_id', 'clustername', 'location', 'tag',
'networks', 'mac', 'switch_ip', 'port', 'switches',
'os_installed', 'distributed_system_installed',
- 'os_name', 'os_id', 'ip',
- 'reinstall_os', 'reinstall_distributed_system',
- 'owner', 'cluster_id', 'ipmi_credentials',
+ 'os_name', 'os_id', 'ip', 'reinstall_os',
+ 'reinstall_distributed_system', 'owner', 'cluster_id',
+ 'power_type', 'power_manage',
'created_at', 'updated_at',
'patched_roles'
]
diff --git a/compass-tasks-base/db/api/machine.py b/compass-tasks-base/db/api/machine.py
index 4222288..5b3cea0 100644
--- a/compass-tasks-base/db/api/machine.py
+++ b/compass-tasks-base/db/api/machine.py
@@ -29,20 +29,20 @@ from compass.utils import util
MACHINE_PRIMARY_FILEDS = ['mac', 'owner_id']
SUPPORTED_FIELDS = [
- 'mac', 'tag', 'location', 'ipmi_credentials',
- 'machine_attributes', 'owner_id']
+ 'mac', 'tag', 'location', 'power_manage',
+ 'machine_attributes', 'owner_id', 'power_type']
IGNORE_FIELDS = ['id', 'created_at', 'updated_at']
UPDATED_FIELDS = [
- 'ipmi_credentials', 'machine_attributes',
- 'tag', 'location']
+ 'mac', 'tag', 'location', 'power_manage',
+ 'machine_attributes', 'power_type']
PATCHED_FIELDS = [
- 'patched_ipmi_credentials', 'patched_tag',
+ 'patched_power_manage', 'patched_tag',
'patched_location'
]
RESP_FIELDS = [
- 'id', 'mac', 'ipmi_credentials', 'switches', 'switch_ip',
+ 'id', 'mac', 'power_manage', 'switches', 'switch_ip',
'port', 'vlans', 'machine_attributes', 'owner_id',
- 'tag', 'location', 'created_at', 'updated_at'
+ 'tag', 'location', 'power_type', 'created_at', 'updated_at'
]
RESP_DEPLOY_FIELDS = [
'status', 'machine'
@@ -149,7 +149,7 @@ def _update_machine(machine_id, session=None, **kwargs):
optional_support_keys=UPDATED_FIELDS,
ignore_support_keys=IGNORE_FIELDS
)
-@utils.input_validates(ipmi_credentials=utils.check_ipmi_credentials)
+@utils.input_validates(power_manage=utils.check_power_manage)
@database.run_in_session()
@user_api.check_user_permission(
permission.PERMISSION_ADD_MACHINE
@@ -161,11 +161,11 @@ def update_machine(machine_id, user=None, session=None, **kwargs):
)
-# replace [ipmi_credentials, tag, location] to
-# [patched_ipmi_credentials, patched_tag, patched_location]
+# replace [power_manage, tag, location] to
+# [patched_power_manage, patched_tag, patched_location]
# in kwargs. It tells db these fields will be patched.
@utils.replace_filters(
- ipmi_credentials='patched_ipmi_credentials',
+ power_manage='patched_power_manage',
tag='patched_tag',
location='patched_location'
)
@@ -174,7 +174,7 @@ def update_machine(machine_id, user=None, session=None, **kwargs):
ignore_support_keys=IGNORE_FIELDS
)
@database.run_in_session()
-@utils.output_validates(ipmi_credentials=utils.check_ipmi_credentials)
+@utils.output_validates(power_manage=utils.check_power_manage)
@user_api.check_user_permission(
permission.PERMISSION_ADD_MACHINE
)
diff --git a/compass-tasks-base/db/api/switch.py b/compass-tasks-base/db/api/switch.py
index 647eec0..92d7a7f 100644
--- a/compass-tasks-base/db/api/switch.py
+++ b/compass-tasks-base/db/api/switch.py
@@ -58,17 +58,17 @@ UPDATED_FILTERS_FIELDS = ['put_machine_filters']
PATCHED_FILTERS_FIELDS = ['patched_machine_filters']
ADDED_MACHINES_FIELDS = ['mac']
OPTIONAL_ADDED_MACHINES_FIELDS = [
- 'ipmi_credentials', 'tag', 'location', 'owner_id'
+ 'power_manage', 'tag', 'location', 'owner_id'
]
ADDED_SWITCH_MACHINES_FIELDS = ['port']
OPTIONAL_ADDED_SWITCH_MACHINES_FIELDS = ['vlans']
UPDATED_MACHINES_FIELDS = [
- 'ipmi_credentials',
+ 'power_manage',
'tag', 'location'
]
UPDATED_SWITCH_MACHINES_FIELDS = ['port', 'vlans', 'owner_id']
PATCHED_MACHINES_FIELDS = [
- 'patched_ipmi_credentials',
+ 'patched_power_manage',
'patched_tag', 'patched_location'
]
PATCHED_SWITCH_MACHINES_FIELDS = ['patched_vlans']
@@ -85,13 +85,13 @@ RESP_ACTION_FIELDS = [
RESP_MACHINES_FIELDS = [
'id', 'switch_id', 'switch_ip', 'machine_id', 'switch_machine_id',
'port', 'vlans', 'mac', 'owner_id',
- 'ipmi_credentials', 'tag', 'location',
+ 'power_manage', 'tag', 'location',
'created_at', 'updated_at'
]
RESP_MACHINES_HOSTS_FIELDS = [
'id', 'switch_id', 'switch_ip', 'machine_id', 'switch_machine_id',
'port', 'vlans', 'mac',
- 'ipmi_credentials', 'tag', 'location', 'ip',
+ 'power_manage', 'tag', 'location', 'ip',
'name', 'hostname', 'os_name', 'owner',
'os_installer', 'reinstall_os', 'os_installed',
'clusters', 'created_at', 'updated_at'
@@ -988,13 +988,13 @@ def update_switchmachine(switch_machine_id, user=None, session=None, **kwargs):
)
-# replace [vlans, ipmi_credentials, tag, location] to
-# [patched_vlans, patched_ipmi_credentials, patched_tag,
+# replace [vlans, power_manage, tag, location] to
+# [patched_vlans, patched_power_manage, patched_tag,
# patched_location] in kwargs. It tells db these fields will
# be patched.
@utils.replace_filters(
vlans='patched_vlans',
- ipmi_credentials='patched_ipmi_credentials',
+ power_manage='patched_power_manage',
tag='patched_tag',
location='patched_location'
)
@@ -1024,13 +1024,13 @@ def patch_switch_machine(
)
-# replace [vlans, ipmi_credentials, tag, location] to
-# [patched_vlans, patched_ipmi_credentials, patched_tag,
+# replace [vlans, power_manage, tag, location] to
+# [patched_vlans, patched_power_manage, patched_tag,
# patched_location] in kwargs. It tells db these fields will
# be patched.
@utils.replace_filters(
vlans='patched_vlans',
- ipmi_credentials='patched_ipmi_credentials',
+ power_manage='patched_power_manage',
tag='patched_tag',
location='patched_location'
)
diff --git a/compass-tasks-base/db/api/utils.py b/compass-tasks-base/db/api/utils.py
index a44f26e..ef975ef 100644
--- a/compass-tasks-base/db/api/utils.py
+++ b/compass-tasks-base/db/api/utils.py
@@ -1208,42 +1208,41 @@ def check_name(name):
)
-def _check_ipmi_credentials_ip(ip):
+def _check_power_manage_ip(ip):
check_ip(ip)
-def check_ipmi_credentials(ipmi_credentials):
- """Check ipmi credentials format is correct."""
- if not ipmi_credentials:
+def check_power_manage(power_manage):
+ """Check power manage format is correct."""
+ if not power_manage:
return
- if not isinstance(ipmi_credentials, dict):
+ if not isinstance(power_manage, dict):
raise exception.InvalidParameter(
- 'invalid ipmi credentials %s' % ipmi_credentials
-
+ 'invalid power manage %s' % power_manage
)
- for key in ipmi_credentials:
+ for key in power_manage:
if key not in ['ip', 'username', 'password']:
raise exception.InvalidParameter(
- 'unrecognized field %s in ipmi credentials %s' % (
- key, ipmi_credentials
+ 'unrecognized field %s in power manage %s' % (
+ key, power_manage
)
)
for key in ['ip', 'username', 'password']:
- if key not in ipmi_credentials:
+ if key not in power_manage:
raise exception.InvalidParameter(
- 'no field %s in ipmi credentials %s' % (
- key, ipmi_credentials
+ 'no field %s in power manage %s' % (
+ key, power_manage
)
)
- check_ipmi_credential_field = '_check_ipmi_credentials_%s' % key
+ check_power_manage_field = '_check_power_manage_%s' % key
this_module = globals()
- if check_ipmi_credential_field in this_module:
- this_module[check_ipmi_credential_field](
- ipmi_credentials[key]
+ if check_power_manage_field in this_module:
+ this_module[check_power_manage_field](
+ power_manage[key]
)
else:
logging.debug(
- 'function %s is not defined', check_ipmi_credential_field
+ 'function %s is not defined', check_power_manage_field
)
diff --git a/compass-tasks-base/db/models.py b/compass-tasks-base/db/models.py
index 929f4dc..e312f61 100644
--- a/compass-tasks-base/db/models.py
+++ b/compass-tasks-base/db/models.py
@@ -1533,10 +1533,11 @@ class Machine(BASE, HelperMixin, TimestampMixin):
__tablename__ = 'machine'
id = Column(Integer, primary_key=True)
mac = Column(JSONEncoded, nullable=False)
- ipmi_credentials = Column(JSONEncoded, default={})
tag = Column(JSONEncoded, default={})
location = Column(JSONEncoded, default={})
owner_id = Column(Integer, nullable=True)
+ power_type = Column(String(10), default="ipmilan")
+ power_manage = Column(JSONEncoded, default={})
machine_attributes = Column(JSONEncoded, default={})
switch_machines = relationship(
@@ -1572,15 +1573,15 @@ class Machine(BASE, HelperMixin, TimestampMixin):
)
@property
- def patched_ipmi_credentials(self):
- return self.ipmi_credentials
+ def patched_power_manage(self):
+ return self.power_manage
- @patched_ipmi_credentials.setter
- def patched_ipmi_credentials(self, value):
+ @patched_power_manage.setter
+ def patched_power_manage(self, value):
if not value:
return
- ipmi_credentials = copy.deepcopy(self.ipmi_credentials)
- self.ipmi_credentials = util.merge_dict(ipmi_credentials, value)
+ power_manage = copy.deepcopy(self.power_manage)
+ self.power_manage = util.merge_dict(power_manage, value)
@property
def patched_tag(self):
diff --git a/compass-tasks-base/deployment/deploy_manager.py b/compass-tasks-base/deployment/deploy_manager.py
index baf7cd6..225c31e 100644
--- a/compass-tasks-base/deployment/deploy_manager.py
+++ b/compass-tasks-base/deployment/deploy_manager.py
@@ -111,7 +111,34 @@ class DeployManager(object):
self.os_installer.set_package_installer_config(pk_installer_config)
# start to deploy OS
- return self.os_installer.deploy()
+ result = self.os_installer.deploy()
+ self.reset_server()
+
+ return result
+
+ def poweron_server(self):
+ if not self.os_installer:
+ return
+
+ host_id_list = self.os_installer.config_manager.get_host_id_list()
+ for host_id in host_id_list:
+ self.os_installer.poweron(host_id)
+
+ def poweroff_server(self):
+ if not self.os_installer:
+ return
+
+ host_id_list = self.os_installer.config_manager.get_host_id_list()
+ for host_id in host_id_list:
+ self.os_installer.poweroff(host_id)
+
+ def reset_server(self):
+ if not self.os_installer:
+ return
+
+ host_id_list = self.os_installer.config_manager.get_host_id_list()
+ for host_id in host_id_list:
+ self.os_installer.reset(host_id)
def deploy_target_system(self):
"""Deploy target system to all hosts in the cluster.
diff --git a/compass-tasks-base/deployment/installers/config_manager.py b/compass-tasks-base/deployment/installers/config_manager.py
index d3b28e0..ebee727 100644
--- a/compass-tasks-base/deployment/installers/config_manager.py
+++ b/compass-tasks-base/deployment/installers/config_manager.py
@@ -169,8 +169,8 @@ class HostInfo(object):
self.package_config = self.host_info.setdefault(const.PK_CONFIG, {})
self.roles = self.host_info.setdefault(const.ROLES, [])
self.patched_roles = self.host_info.setdefault(const.PATCHED_ROLES, [])
- self.ipmi = deepcopy(self.host_info.setdefault(const.IPMI, {}))
- self.ipmi_credentials = deepcopy(self.host_info.setdefault(const.IPMI_CREDS, {}))
+ self.power_type = deepcopy(self.host_info.setdefault(const.POWER_TYPE, {}))
+ self.power_manage = deepcopy(self.host_info.setdefault(const.POWER_MANAGE, {}))
self.reinstall_os_flag = self.host_info.get(const.REINSTALL_OS_FLAG)
self.deployed_os_config = self.host_info.setdefault(
const.DEPLOYED_OS_CONFIG, {}
@@ -276,7 +276,8 @@ class HostInfo(object):
def baseinfo(self):
return {
const.REINSTALL_OS_FLAG: self.reinstall_os_flag,
- const.IPMI_CREDS: self.ipmi_credentials,
+ const.POWER_TYPE: self.power_type,
+ const.POWER_MANAGE: self.power_manage,
const.MAC_ADDR: self.mac,
const.NAME: self.name,
const.HOSTNAME: self.hostname,
@@ -516,14 +517,15 @@ class BaseConfigManager(object):
self.validate_host(host_id)
return self.hosts_info[host_id].roles_mapping
- def get_host_ipmi_info(self, host_id):
+ def get_host_power_info(self, host_id):
self.validate_host(host_id)
- if self.hosts_info[host_id].ipmi:
+ if self.hosts_info[host_id].power_manage:
return (
- self.hosts_info[host_id].ipmi[const.IP_ADDR],
- self.hosts_info[host_id].ipmi
- [const.IPMI_CREDS][const.USERNAME],
- self.hosts_info[host_id].ipmi
- [const.IPMI_CREDS][const.USERNAME])
+ self.hosts_info[host_id].power_manage
+ [const.IP_ADDR],
+ self.hosts_info[host_id].power_manage
+ [const.USERNAME],
+ self.hosts_info[host_id].power_manage
+ [const.PASSWORD])
else:
return (None, None, None)
diff --git a/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py b/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py
index 9c2a935..aa74f68 100644
--- a/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py
+++ b/compass-tasks-base/deployment/installers/os_installers/cobbler/cobbler.py
@@ -397,25 +397,25 @@ class CobblerInstaller(OSInstaller):
return cluster_vas_dict
- def _check_and_set_system_impi(self, host_id, sys_id):
+ def _check_and_set_system_power(self, host_id, sys_id):
if not sys_id:
logging.info("System is None!")
return False
system = self.dump_system_info(host_id)
- if system[self.POWER_TYPE] != 'ipmilan' or not system[self.POWER_USER]:
+ if not system.get(self.POWER_TYPE):
# Set sytem power type to ipmilan if needs and set IPMI info
- ipmi_info = self.config_manager.get_host_ipmi_info(host_id)
- if not ipmi_info:
+ power_info = self.config_manager.get_host_power_info(host_id)
+ if not power_info:
logging.info('No IPMI information found! Failed power on.')
return False
- ipmi_ip, ipmi_user, ipmi_pass = ipmi_info
+ ip, username, password = power_info
power_opts = {}
power_opts[self.POWER_TYPE] = 'ipmilan'
- power_opts[self.POWER_ADDR] = ipmi_ip
- power_opts[self.POWER_USER] = ipmi_user
- power_opts[self.POWER_PASS] = ipmi_pass
+ power_opts[self.POWER_ADDR] = ip
+ power_opts[self.POWER_USER] = username
+ power_opts[self.POWER_PASS] = password
self._update_system_config(sys_id, power_opts)
@@ -424,26 +424,26 @@ class CobblerInstaller(OSInstaller):
def poweron(self, host_id):
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_create_system(hostname)
- if not self._check_and_set_system_impi(sys_id):
+ if not self._check_and_set_system_power(host_id, sys_id):
return
- self.remote.power_system(sys_id, self.token, power='on')
+ self.remote.power_system(sys_id, 'on', self.token)
logging.info("Host with ID=%d starts to power on!" % host_id)
def poweroff(self, host_id):
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_create_system(hostname)
- if not self._check_and_set_system_impi(sys_id):
+ if not self._check_and_set_system_power(host_id, sys_id):
return
- self.remote.power_system(sys_id, self.token, power='off')
+ self.remote.power_system(sys_id, 'off', self.token)
logging.info("Host with ID=%d starts to power off!" % host_id)
def reset(self, host_id):
hostname = self.config_manager.get_hostname(host_id)
sys_id = self._get_create_system(hostname)
- if not self._check_and_set_system_impi(sys_id):
+ if not self._check_and_set_system_power(host_id, sys_id):
return
- self.remote.power_system(sys_id, self.token, power='reboot')
+ self.remote.power_system(sys_id, 'reboot', self.token)
logging.info("Host with ID=%d starts to reboot!" % host_id)
diff --git a/compass-tasks-base/deployment/utils/constants.py b/compass-tasks-base/deployment/utils/constants.py
index e90b1b2..18ee56a 100644
--- a/compass-tasks-base/deployment/utils/constants.py
+++ b/compass-tasks-base/deployment/utils/constants.py
@@ -54,8 +54,8 @@ DOMAIN = 'domain'
HOST_ID = 'host_id'
HOSTNAME = 'hostname'
IP_ADDR = 'ip'
-IPMI = 'ipmi'
-IPMI_CREDS = 'ipmi_credentials'
+POWER_TYPE = 'power_type'
+POWER_MANAGE = 'power_manage'
MAC_ADDR = 'mac'
MGMT_NIC_FLAG = 'is_mgmt'
NETMASK = 'netmask'