Commit 1c769cee by Heechul Kim

added machine service network settings

parent 9e5e350c
......@@ -22,6 +22,7 @@ from porch.database import etcdc
from porch.utils import get_port
from porch.config import TFTP_FAI_DIR
from porch.config import FAI_DIR
from porch.config import PXELINUXCFG
from porch.config import PRIKEY_DIR
from porch.config import PUBKEY_DIR
......@@ -143,6 +144,26 @@ def provision_machine(name):
s_msg = 'Fail to create pxelinuxcfg file: {}.'.format(s_pxelinuxcfg)
return (False, s_msg)
# Create service network config file svc-interface if svc_nic exists.
svc_iface_file = ''
if 'svc_nic' in d and d.get('svc_nic'):
# check if template exists.
s_tmpl = 'svc-interface-{}.j2'.format(d['os'])
if not os.path.isfile(APP_ROOT + '/templates/{}'.format(s_tmpl)):
s_msg = 'Cannot find template {}'.format(s_tmpl)
log.error(s_msg)
return (False, s_msg)
s_out = render_template(s_tmpl, d=d)
svc_iface_file = FAI_DIR + '/config/svc-interface-{}'.format(d['name'])
try:
with open(svc_iface_file, 'w') as f:
f.write(s_out)
except:
s_msg = 'Fail to create svc iface file: {}'.format(svc_iface_file)
log.error(s_msg)
return (False, s_msg)
# Create ssh private/public keys
key = rsa.generate_private_key(backend=default_backend(), \
public_exponent=65537, key_size=2048)
......@@ -187,6 +208,8 @@ def provision_machine(name):
# add pubkeys/<ip> into tarfile.
with tarfile.open(s_dst, 'a') as o_tar:
o_tar.add(s_pubkey_file, arcname='pubkeys/{}'.format(d['ip']))
if svc_iface_file:
o_tar.add(svc_iface_file, arcname='svc-interface')
# finally update machine state = provisioned
update_machine(name, {'state': 'Provisioned'})
......@@ -309,7 +332,7 @@ def install_machine(data):
continue
# skip if there is no ipmi_ip.
if 'ipmi_ip' in d:
if 'ipmi_ip' in d and d['ipmi_ip']:
# set pxeboot
s_cmd = "{} -I lanplus -H {} -U {} -f {} chassis bootdev pxe"\
.format(IPMITOOL, d['ipmi_ip'], IPMIUSER, s_tmp)
......@@ -318,9 +341,7 @@ def install_machine(data):
# update machine state to 'Installing'
d['state'] = 'Installing'
(b_ret, s_msg) = update_machine(d['name'], d)
if not b_ret:
continue
update_machine(d['name'], d)
l_ipmi.append(d['ipmi_ip'])
# delete s_tmp
......
......@@ -14,6 +14,10 @@ machineSerializer = api.model('ListMachine', {
'mac': fields.String(required=True, description='machine mac'),
'ip': fields.String(required=True, description='machine ip address'),
'ipmi_ip': fields.String(required=False, description='machine ipmi ip'),
'svc_nic': fields.String(required=False, description='machine svc nic'),
'svc_ip': fields.String(required=False, description='machine svc ip'),
'svc_netmask': fields.String(required=False, description='machine netmask'),
'svc_gateway': fields.String(required=False, description='machine gateway'),
'state': fields.String(required=True, default='Created',
description='state: Created, Provisioned'),
'is_installed': fields.Boolean(required=True, default=False,
......@@ -32,6 +36,10 @@ machinePostSerializer = api.model('RegisterMachine', {
'mac': fields.String(required=True, description='machine mac'),
'ip': fields.String(required=True, description='machine ip address'),
'ipmi_ip': fields.String(required=False, description='machine ipmi ip'),
'svc_nic': fields.String(required=False, description='machine svc nic'),
'svc_ip': fields.String(required=False, description='machine svc ip'),
'svc_netmask': fields.String(required=False, description='machine netmask'),
'svc_gateway': fields.String(required=False, description='machine gateway'),
})
machinePatchSerializer = api.model('ModifyMachine', {
......@@ -41,6 +49,10 @@ machinePatchSerializer = api.model('ModifyMachine', {
description='the section machine belongs to'),
'os': fields.String(required=False, description='machine os'),
'ipmi_ip': fields.String(required=False, description='machine ipmi ip'),
'svc_nic': fields.String(required=False, description='machine svc nic'),
'svc_ip': fields.String(required=False, description='machine svc ip'),
'svc_netmask': fields.String(required=False, description='machine netmask'),
'svc_gateway': fields.String(required=False, description='machine gateway'),
'preseed': fields.String(required=False, description='machine preseed'),
'mac': fields.String(required=False, description='machine mac'),
'ip': fields.String(required=False, description='machine ip address'),
......
DEVICE={{ d['svc_nic'] }}
BOOTPROTO=static
ONBOOT=yes
IPADDR={{ d['svc_ip'] }}
NETMASK={{ d['svc_netmask'] }}
GATEWAY={{ d['svc_gateway'] }}
auto {{ d['svc_nic'] }}
iface {{ d['svc_nic'] }} inet static
address {{ d['svc_ip'] }}
netmask {{ d['svc_netmask'] }}
gateway {{ d['svc_gateway'] }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment