move os related function to pxe/install.py
Change-Id: Ieab65339190e899bcbb4c3decbc3baf4d583a6c5
This commit is contained in:
parent
d4d6db14dd
commit
f9611e01c0
@ -36,7 +36,6 @@ from daisy.api.backends.osinstall import osdriver
|
|||||||
import ConfigParser
|
import ConfigParser
|
||||||
import copy
|
import copy
|
||||||
import fcntl
|
import fcntl
|
||||||
import json
|
|
||||||
|
|
||||||
STR_MASK = '*' * 8
|
STR_MASK = '*' * 8
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -1085,106 +1084,3 @@ def check_bond_or_ether_nic_and_join_network(req,
|
|||||||
LOG.info("add the host %s join the cluster %s and"
|
LOG.info("add the host %s join the cluster %s and"
|
||||||
" assigned_network successful" %
|
" assigned_network successful" %
|
||||||
(host_id, cluster_id))
|
(host_id, cluster_id))
|
||||||
|
|
||||||
|
|
||||||
def build_pxe_server(eth_name, ip_address, build_pxe, net_mask,
|
|
||||||
client_ip_begin, client_ip_end):
|
|
||||||
"""build pxe server."""
|
|
||||||
pxe_dict = dict()
|
|
||||||
pxe_dict['ethname_l'] = eth_name
|
|
||||||
pxe_dict['ip_addr_l'] = ip_address
|
|
||||||
pxe_dict['build_pxe'] = build_pxe
|
|
||||||
pxe_dict['net_mask_l'] = net_mask
|
|
||||||
pxe_dict['client_ip_begin'] = client_ip_begin
|
|
||||||
pxe_dict['client_ip_end'] = client_ip_end
|
|
||||||
LOG.info('pxe_dict=%s' % pxe_dict)
|
|
||||||
with open('/var/log/ironic/pxe.json', 'w') as f:
|
|
||||||
json.dump(pxe_dict, f, indent=2)
|
|
||||||
f.close()
|
|
||||||
_PIPE = subprocess.PIPE
|
|
||||||
cmd = "/usr/bin/pxe_server_install /var/log/ironic/pxe.json && \
|
|
||||||
chmod 755 /tftpboot -R"
|
|
||||||
try:
|
|
||||||
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
|
||||||
stderr=_PIPE, shell=True)
|
|
||||||
obj.communicate()
|
|
||||||
except Exception as e:
|
|
||||||
msg = "build_pxe_server error: %s" % e
|
|
||||||
LOG.error(msg)
|
|
||||||
raise exception.Invalid(msg)
|
|
||||||
|
|
||||||
if obj.returncode:
|
|
||||||
msg = "execute set pxe command failed."
|
|
||||||
LOG.error(msg)
|
|
||||||
raise exception.Invalid(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def set_boot_or_power_state(user, passwd, addr, action):
|
|
||||||
if action in ['on', 'off', 'reset']:
|
|
||||||
device = 'power'
|
|
||||||
elif action in ['pxe', 'disk']:
|
|
||||||
device = 'bootdev'
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
cmd = ['ipmitool', '-I', 'lanplus', '-H', addr, '-U', user,
|
|
||||||
'-P', passwd, 'chassis', device, action]
|
|
||||||
|
|
||||||
if device == 'bootdev':
|
|
||||||
cmd.append('options=persistent')
|
|
||||||
_PIPE = subprocess.PIPE
|
|
||||||
try:
|
|
||||||
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
|
||||||
stderr=_PIPE, shell=False)
|
|
||||||
obj.communicate()
|
|
||||||
except Exception as e:
|
|
||||||
msg = "%s set_boot_or_power_state error: %s" % (addr, e)
|
|
||||||
LOG.error(msg)
|
|
||||||
return -1
|
|
||||||
|
|
||||||
return obj.returncode
|
|
||||||
|
|
||||||
|
|
||||||
def install_os(**kwargs):
|
|
||||||
json_file = "/var/log/ironic/%s.json" % kwargs['dhcp_mac']
|
|
||||||
with open(json_file, 'w') as f:
|
|
||||||
json.dump(kwargs, f, indent=2)
|
|
||||||
f.close()
|
|
||||||
_PIPE = subprocess.PIPE
|
|
||||||
cmd = "/usr/bin/pxe_os_install /var/log/ironic/%s.json && \
|
|
||||||
chmod 755 /tftpboot -R && \
|
|
||||||
chmod 755 /home/install_share -R && \
|
|
||||||
chmod 755 /linuxinstall -R" % kwargs['dhcp_mac']
|
|
||||||
try:
|
|
||||||
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
|
||||||
stderr=_PIPE, shell=True, cwd=None, env=None)
|
|
||||||
out, error = obj.communicate()
|
|
||||||
except Exception as e:
|
|
||||||
msg = "%s install_os error: %s" % (kwargs['dhcp_mac'], e)
|
|
||||||
LOG.error(msg)
|
|
||||||
return -1, msg
|
|
||||||
|
|
||||||
return obj.returncode, error
|
|
||||||
|
|
||||||
|
|
||||||
def get_install_progress(dhcp_mac):
|
|
||||||
_PIPE = subprocess.PIPE
|
|
||||||
cmd = "/usr/bin/pxe_os_install_progress %s" % dhcp_mac
|
|
||||||
|
|
||||||
try:
|
|
||||||
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
|
||||||
stderr=_PIPE, shell=True)
|
|
||||||
out, error = obj.communicate()
|
|
||||||
progress_list = out.split()
|
|
||||||
progress = progress_list.pop(0)
|
|
||||||
info = ' '.join(progress_list)
|
|
||||||
rc = obj.returncode
|
|
||||||
except Exception as e:
|
|
||||||
info = '%s get install progress failed: %s' % (dhcp_mac, e)
|
|
||||||
progress, rc = 0, -1
|
|
||||||
LOG.error(info)
|
|
||||||
|
|
||||||
ret = {'return_code': rc,
|
|
||||||
'progress': progress,
|
|
||||||
'info': info}
|
|
||||||
return ret
|
|
||||||
|
@ -27,6 +27,7 @@ from webob.exc import HTTPBadRequest
|
|||||||
from daisy.api import common
|
from daisy.api import common
|
||||||
import threading
|
import threading
|
||||||
from daisy import i18n
|
from daisy import i18n
|
||||||
|
import json
|
||||||
|
|
||||||
from daisy.common import exception
|
from daisy.common import exception
|
||||||
from daisy.common import utils
|
from daisy.common import utils
|
||||||
@ -67,6 +68,109 @@ LINUX_BOND_MODE = {'balance-rr': '0', 'active-backup': '1',
|
|||||||
'balance-alb': '6'}
|
'balance-alb': '6'}
|
||||||
|
|
||||||
|
|
||||||
|
def build_pxe_server(eth_name, ip_address, build_pxe, net_mask,
|
||||||
|
client_ip_begin, client_ip_end):
|
||||||
|
"""build pxe server."""
|
||||||
|
pxe_dict = dict()
|
||||||
|
pxe_dict['ethname_l'] = eth_name
|
||||||
|
pxe_dict['ip_addr_l'] = ip_address
|
||||||
|
pxe_dict['build_pxe'] = build_pxe
|
||||||
|
pxe_dict['net_mask_l'] = net_mask
|
||||||
|
pxe_dict['client_ip_begin'] = client_ip_begin
|
||||||
|
pxe_dict['client_ip_end'] = client_ip_end
|
||||||
|
LOG.info('pxe_dict=%s' % pxe_dict)
|
||||||
|
with open('/var/log/ironic/pxe.json', 'w') as f:
|
||||||
|
json.dump(pxe_dict, f, indent=2)
|
||||||
|
f.close()
|
||||||
|
_PIPE = subprocess.PIPE
|
||||||
|
cmd = "/usr/bin/pxe_server_install /var/log/ironic/pxe.json && \
|
||||||
|
chmod 755 /tftpboot -R"
|
||||||
|
try:
|
||||||
|
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
||||||
|
stderr=_PIPE, shell=True)
|
||||||
|
obj.communicate()
|
||||||
|
except Exception as e:
|
||||||
|
msg = "build_pxe_server error: %s" % e
|
||||||
|
LOG.error(msg)
|
||||||
|
raise exception.Invalid(msg)
|
||||||
|
|
||||||
|
if obj.returncode:
|
||||||
|
msg = "execute set pxe command failed."
|
||||||
|
LOG.error(msg)
|
||||||
|
raise exception.Invalid(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def set_boot_or_power_state(user, passwd, addr, action):
|
||||||
|
if action in ['on', 'off', 'reset']:
|
||||||
|
device = 'power'
|
||||||
|
elif action in ['pxe', 'disk']:
|
||||||
|
device = 'bootdev'
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
cmd = ['ipmitool', '-I', 'lanplus', '-H', addr, '-U', user,
|
||||||
|
'-P', passwd, 'chassis', device, action]
|
||||||
|
|
||||||
|
if device == 'bootdev':
|
||||||
|
cmd.append('options=persistent')
|
||||||
|
_PIPE = subprocess.PIPE
|
||||||
|
try:
|
||||||
|
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
||||||
|
stderr=_PIPE, shell=False)
|
||||||
|
obj.communicate()
|
||||||
|
except Exception as e:
|
||||||
|
msg = "%s set_boot_or_power_state error: %s" % (addr, e)
|
||||||
|
LOG.error(msg)
|
||||||
|
return -1
|
||||||
|
|
||||||
|
return obj.returncode
|
||||||
|
|
||||||
|
|
||||||
|
def install_os(**kwargs):
|
||||||
|
json_file = "/var/log/ironic/%s.json" % kwargs['dhcp_mac']
|
||||||
|
with open(json_file, 'w') as f:
|
||||||
|
json.dump(kwargs, f, indent=2)
|
||||||
|
f.close()
|
||||||
|
_PIPE = subprocess.PIPE
|
||||||
|
cmd = "/usr/bin/pxe_os_install /var/log/ironic/%s.json && \
|
||||||
|
chmod 755 /tftpboot -R && \
|
||||||
|
chmod 755 /home/install_share -R && \
|
||||||
|
chmod 755 /linuxinstall -R" % kwargs['dhcp_mac']
|
||||||
|
try:
|
||||||
|
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
||||||
|
stderr=_PIPE, shell=True, cwd=None, env=None)
|
||||||
|
out, error = obj.communicate()
|
||||||
|
except Exception as e:
|
||||||
|
msg = "%s install_os error: %s" % (kwargs['dhcp_mac'], e)
|
||||||
|
LOG.error(msg)
|
||||||
|
return -1, msg
|
||||||
|
|
||||||
|
return obj.returncode, error
|
||||||
|
|
||||||
|
|
||||||
|
def get_install_progress(dhcp_mac):
|
||||||
|
_PIPE = subprocess.PIPE
|
||||||
|
cmd = "/usr/bin/pxe_os_install_progress %s" % dhcp_mac
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj = subprocess.Popen(cmd, stdin=_PIPE, stdout=_PIPE,
|
||||||
|
stderr=_PIPE, shell=True)
|
||||||
|
out, error = obj.communicate()
|
||||||
|
progress_list = out.split()
|
||||||
|
progress = progress_list.pop(0)
|
||||||
|
info = ' '.join(progress_list)
|
||||||
|
rc = obj.returncode
|
||||||
|
except Exception as e:
|
||||||
|
info = '%s get install progress failed: %s' % (dhcp_mac, e)
|
||||||
|
progress, rc = 0, -1
|
||||||
|
LOG.error(info)
|
||||||
|
|
||||||
|
ret = {'return_code': rc,
|
||||||
|
'progress': progress,
|
||||||
|
'info': info}
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def check_discover_state(req, host_meta, is_detail=False):
|
def check_discover_state(req, host_meta, is_detail=False):
|
||||||
if host_meta.get("hwm_id"):
|
if host_meta.get("hwm_id"):
|
||||||
daisy_cmn.check_discover_state_with_hwm(req,
|
daisy_cmn.check_discover_state_with_hwm(req,
|
||||||
@ -144,7 +248,7 @@ def pxe_server_build(req, install_meta):
|
|||||||
'net_mask': net_mask,
|
'net_mask': net_mask,
|
||||||
'client_ip_begin': client_ip_begin,
|
'client_ip_begin': client_ip_begin,
|
||||||
'client_ip_end': client_ip_end}
|
'client_ip_end': client_ip_end}
|
||||||
daisy_cmn.build_pxe_server(**args)
|
build_pxe_server(**args)
|
||||||
except exception.Invalid as e:
|
except exception.Invalid as e:
|
||||||
msg = "build pxe server failed"
|
msg = "build pxe server failed"
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
@ -405,7 +509,7 @@ class OSInstall():
|
|||||||
ipmi_result_flag = True
|
ipmi_result_flag = True
|
||||||
stop_flag = False
|
stop_flag = False
|
||||||
while count < repeat_times:
|
while count < repeat_times:
|
||||||
rc = daisy_cmn.set_boot_or_power_state(user, passwd, addr, action)
|
rc = set_boot_or_power_state(user, passwd, addr, action)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
LOG.info(
|
LOG.info(
|
||||||
_("Set %s to '%s' successfully for %s times by ironic" % (
|
_("Set %s to '%s' successfully for %s times by ironic" % (
|
||||||
@ -427,7 +531,7 @@ class OSInstall():
|
|||||||
# mode in German site. If we have a method to confirm,
|
# mode in German site. If we have a method to confirm,
|
||||||
# this can be deleted.
|
# this can be deleted.
|
||||||
if action == 'pxe' or action == 'disk':
|
if action == 'pxe' or action == 'disk':
|
||||||
daisy_cmn.set_boot_or_power_state(user, passwd, addr,
|
set_boot_or_power_state(user, passwd, addr,
|
||||||
action)
|
action)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -632,7 +736,7 @@ class OSInstall():
|
|||||||
else:
|
else:
|
||||||
kwargs['nova_lv_size'] = 0
|
kwargs['nova_lv_size'] = 0
|
||||||
if host_detail.get('hwm_id') or ipmi_result_flag:
|
if host_detail.get('hwm_id') or ipmi_result_flag:
|
||||||
rc, error = daisy_cmn.install_os(**kwargs)
|
rc, error = install_os(**kwargs)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
install_os_description = error
|
install_os_description = error
|
||||||
LOG.info(
|
LOG.info(
|
||||||
@ -710,7 +814,7 @@ class OSInstall():
|
|||||||
|
|
||||||
def _query_host_progress(self, host_detail, host_status, host_last_status):
|
def _query_host_progress(self, host_detail, host_status, host_last_status):
|
||||||
host_id = host_detail['id']
|
host_id = host_detail['id']
|
||||||
install_result = daisy_cmn.get_install_progress(
|
install_result = get_install_progress(
|
||||||
host_detail['dhcp_mac'])
|
host_detail['dhcp_mac'])
|
||||||
rc = int(install_result['return_code'])
|
rc = int(install_result['return_code'])
|
||||||
host_status['os_progress'] = int(install_result['progress'])
|
host_status['os_progress'] = int(install_result['progress'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user