add cdpxe command
This commit is contained in:
BIN
data/sunhpc.db
BIN
data/sunhpc.db
Binary file not shown.
@@ -12,7 +12,10 @@ class RollHandler(object):
|
|||||||
self.cmd = cmd
|
self.cmd = cmd
|
||||||
self.clean = clean
|
self.clean = clean
|
||||||
self.mntdir = mnt
|
self.mntdir = mnt
|
||||||
|
self.repodirs = ''
|
||||||
self.rinfo = None
|
self.rinfo = None
|
||||||
|
self.isoname = 'unknown'
|
||||||
|
self.foreign = False
|
||||||
|
|
||||||
def is_mounted(self):
|
def is_mounted(self):
|
||||||
cmd = 'mount |grep %s' % self.mntdir
|
cmd = 'mount |grep %s' % self.mntdir
|
||||||
@@ -22,6 +25,7 @@ class RollHandler(object):
|
|||||||
|
|
||||||
def mount_iso(self, iso):
|
def mount_iso(self, iso):
|
||||||
subprocess.run('mount -r %s %s' % (iso, self.mntdir), shell=True, check=True)
|
subprocess.run('mount -r %s %s' % (iso, self.mntdir), shell=True, check=True)
|
||||||
|
self.isoname = iso
|
||||||
|
|
||||||
def umount_iso(self):
|
def umount_iso(self):
|
||||||
subprocess.run('umount %s' % self.mntdir, shell=True)
|
subprocess.run('umount %s' % self.mntdir, shell=True)
|
||||||
@@ -36,7 +40,25 @@ class RollHandler(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def foreign_roll(self):
|
def foreign_roll(self):
|
||||||
self.cmd.msg('This ISO file cannot be recognized.This ISO was not produced by sunhpc created.', 'w')
|
self.cmd.msg('The "%s" was not produced by sunhpc created.' % self.isoname, 'w')
|
||||||
|
# check iso .discinfo file
|
||||||
|
discinfo = os.path.join(self.mntdir, '.discinfo')
|
||||||
|
if not os.path.exists(discinfo):
|
||||||
|
self.cmd.msg('The %s is not exists.' % discinfo, 'a')
|
||||||
|
|
||||||
|
info = []
|
||||||
|
with open(discinfo, 'r') as fn:
|
||||||
|
info = fn.readlines()
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.foreign = True
|
||||||
|
self.rinfo = sunhpc.core.utils.Struct()
|
||||||
|
self.rinfo.name = info[1].split()[0].strip()
|
||||||
|
self.rinfo.version = info[1].split()[-1].strip()
|
||||||
|
self.rinfo.arch = info[2].strip()
|
||||||
|
except IndexError:
|
||||||
|
self.foreign = False
|
||||||
|
|
||||||
|
|
||||||
def copy_iso(self):
|
def copy_iso(self):
|
||||||
self.read_iso()
|
self.read_iso()
|
||||||
@@ -47,11 +69,20 @@ class RollHandler(object):
|
|||||||
|
|
||||||
def copy_roll(self):
|
def copy_roll(self):
|
||||||
# self.rinfo是经过file.RollInfoFile处理过的,返回相应的类对象.
|
# self.rinfo是经过file.RollInfoFile处理过的,返回相应的类对象.
|
||||||
|
if self.foreign:
|
||||||
|
roll_name = self.rinfo.name
|
||||||
|
roll_vers = self.rinfo.version
|
||||||
|
roll_arch = self.rinfo.arch
|
||||||
|
roll_os = self.cmd.os
|
||||||
|
roll_boot = None
|
||||||
|
roll_path = self.mntdir
|
||||||
|
else:
|
||||||
roll_name = self.rinfo.getRollName()
|
roll_name = self.rinfo.getRollName()
|
||||||
roll_vers = self.rinfo.getRollVersion()
|
roll_vers = self.rinfo.getRollVersion()
|
||||||
roll_arch = self.rinfo.getRollArch()
|
roll_arch = self.rinfo.getRollArch()
|
||||||
roll_os = self.rinfo.getRollOS()
|
roll_os = self.rinfo.getRollOS()
|
||||||
roll_boot = self.rinfo.isBootable()
|
roll_boot = self.rinfo.isBootable()
|
||||||
|
roll_path = os.path.join(self.mntdir, roll_name)
|
||||||
|
|
||||||
# 获取rolls存放位置
|
# 获取rolls存放位置
|
||||||
cmd = '/opt/sunhpc/bin/sunhpc report distro'
|
cmd = '/opt/sunhpc/bin/sunhpc report distro'
|
||||||
@@ -59,9 +90,15 @@ class RollHandler(object):
|
|||||||
distro = line[:-1]
|
distro = line[:-1]
|
||||||
|
|
||||||
# /export/sunhpc/install/rolls
|
# /export/sunhpc/install/rolls
|
||||||
|
if self.foreign:
|
||||||
|
rolls_dir = '%s/repos' % (distro)
|
||||||
|
else:
|
||||||
rolls_dir = '%s/rolls' % (distro)
|
rolls_dir = '%s/rolls' % (distro)
|
||||||
|
|
||||||
# /export/sunhpc/install/rolls/kernel......
|
# /export/sunhpc/install/rolls/kernel......
|
||||||
|
if self.foreign:
|
||||||
|
roll_dir = os.path.join(rolls_dir, roll_name, roll_vers, roll_arch)
|
||||||
|
else:
|
||||||
roll_dir = os.path.join(rolls_dir, roll_name)
|
roll_dir = os.path.join(rolls_dir, roll_name)
|
||||||
|
|
||||||
if self.clean:
|
if self.clean:
|
||||||
@@ -75,7 +112,7 @@ class RollHandler(object):
|
|||||||
os.makedirs(specific_roll_dir)
|
os.makedirs(specific_roll_dir)
|
||||||
|
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
os.chdir(os.path.join(self.mntdir, roll_name))
|
os.chdir(roll_path)
|
||||||
|
|
||||||
# 计算一下大小
|
# 计算一下大小
|
||||||
cmd = 'du -sh %s' % self.mntdir
|
cmd = 'du -sh %s' % self.mntdir
|
||||||
@@ -122,6 +159,7 @@ class RollHandler(object):
|
|||||||
# 如果是引导roll,需要使用软件Kylins create distro重新部署.
|
# 如果是引导roll,需要使用软件Kylins create distro重新部署.
|
||||||
# 重新创建images,stage2,和相关连接相关任务.
|
# 重新创建images,stage2,和相关连接相关任务.
|
||||||
self.cmd.msg('Copy the %s finished.' % roll_name)
|
self.cmd.msg('Copy the %s finished.' % roll_name)
|
||||||
|
self.repodirs = roll_dir
|
||||||
|
|
||||||
def clean_dirs(self, dirs):
|
def clean_dirs(self, dirs):
|
||||||
for root, dirs, files in os.walk(dirs, topdown=False):
|
for root, dirs, files in os.walk(dirs, topdown=False):
|
||||||
@@ -202,6 +240,28 @@ class Command(command):
|
|||||||
roll_handler.copy_iso()
|
roll_handler.copy_iso()
|
||||||
roll_handler.umount_iso()
|
roll_handler.umount_iso()
|
||||||
|
|
||||||
|
if roll_handler.foreign:
|
||||||
|
local_repos = '/etc/yum.repos.d/Rocky-Local.repo'
|
||||||
|
with open(local_repos, 'w') as fn:
|
||||||
|
fn.write('#\n# Rocky-Local.repo\n# Generate by sunhpc\n#\n\n')
|
||||||
|
fn.write('[local-baseos]\n')
|
||||||
|
fn.write('name=Rocky Linux $releasever - Local - BaseOS\n')
|
||||||
|
fn.write('baseurl=file:///%s/BaseOS\n' % roll_handler.repodirs)
|
||||||
|
fn.write('gpgcheck=1\n')
|
||||||
|
fn.write('enabled=1\n')
|
||||||
|
fn.write('gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial\n\n')
|
||||||
|
|
||||||
|
fn.write('[local-appstream]\n')
|
||||||
|
fn.write('name=Rocky Linux $releasever - Local - AppStream\n')
|
||||||
|
fn.write('baseurl=file:///%s/AppStream\n' % roll_handler.repodirs)
|
||||||
|
fn.write('gpgcheck=1\n')
|
||||||
|
fn.write('enabled=1\n')
|
||||||
|
fn.write('gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial\n\n')
|
||||||
|
|
||||||
|
self.msg('Add %s to %s' % (roll_handler.repodirs, local_repos))
|
||||||
|
self.msg(' Use the command: yum/dnf repolist all')
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if pxesrv:
|
if pxesrv:
|
||||||
self.configSRV(q)
|
self.configSRV(q)
|
||||||
else:
|
else:
|
||||||
|
|||||||
90
lib/sunhpc/commands/pxelinux/build/cdpxe/__init__.py
Normal file
90
lib/sunhpc/commands/pxelinux/build/cdpxe/__init__.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#coding:utf-8
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import sunhpc
|
||||||
|
import shutil
|
||||||
|
import textwrap
|
||||||
|
import subprocess
|
||||||
|
class Command(sunhpc.commands.pxelinux.build.command):
|
||||||
|
"""
|
||||||
|
Build the iso pxe (dhcpd, tftpd, httpd service for the sunhpc cluster.
|
||||||
|
|
||||||
|
<param type='Bool' name='Quiet'>
|
||||||
|
Whether to output detailed information, default: no
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<param type='name' name='dev'>
|
||||||
|
supply an network device name,e.g,, eth0,eth1...
|
||||||
|
</param>
|
||||||
|
|
||||||
|
<example cmd='pxelinux build cdpxe'>
|
||||||
|
In local build the iso pxe dhcpd, tftpd, httpd services.
|
||||||
|
</example>
|
||||||
|
|
||||||
|
<example cmd='pxelinux build cdpxe'>
|
||||||
|
Build the iso pxe dhcpd, tftpd, httpd service.
|
||||||
|
</example>
|
||||||
|
"""
|
||||||
|
def run(self, params, args):
|
||||||
|
|
||||||
|
(quiet, devices) = self.fillParams([('quiet', 'no'), ('dev', None)])
|
||||||
|
|
||||||
|
q = self.str2bool(quiet)
|
||||||
|
self.msg('Starting build the dhcpd service...', q=q)
|
||||||
|
|
||||||
|
if devices is None:
|
||||||
|
self.msg('Must supply an network dev name,e.g,, eth0/eth1...', 'a')
|
||||||
|
|
||||||
|
# install dhcp server
|
||||||
|
self.installDhcpd(q, devices)
|
||||||
|
|
||||||
|
def installDhcpd(self, q, devices):
|
||||||
|
config = '/etc/dhcp/dhcpd.conf'
|
||||||
|
|
||||||
|
# The dhcpd is not installed.
|
||||||
|
if not os.path.exists(config):
|
||||||
|
self.shcmd('yum install -y dhcp-server')
|
||||||
|
|
||||||
|
with open(config, 'w') as f:
|
||||||
|
f.write(textwrap.dedent("""\
|
||||||
|
#
|
||||||
|
# dhcpd.conf
|
||||||
|
#
|
||||||
|
subnet 172.16.2.0 netmask 255.255.255.0 {
|
||||||
|
range 172.16.2.10 172.16.2.200;
|
||||||
|
option domain-name "hpc.com";
|
||||||
|
option domain-name-servers 8.8.8.8;
|
||||||
|
option routers 172.16.2.1;
|
||||||
|
default-lease-time 600;
|
||||||
|
max-lease-time 7200;
|
||||||
|
}
|
||||||
|
"""))
|
||||||
|
|
||||||
|
dhcpd_srv_conf = '/usr/lib/systemd/system/dhcpd.service'
|
||||||
|
with open(dhcpd_srv_conf, 'w') as f:
|
||||||
|
f.write(textwrap.dedent("""\
|
||||||
|
[Unit]
|
||||||
|
Description=DHCPv4 Server Daemon
|
||||||
|
Documentation=man:dhcpd(8) man:dhcpd.conf(5)
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
After=time-sync.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid %s
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
""" % devices))
|
||||||
|
|
||||||
|
self.fw.addports(['67'], ['udp'])
|
||||||
|
self.fw.addports(['68'], ['udp'])
|
||||||
|
self.shcmd('systemctl daemon-reload')
|
||||||
|
self.shcmd('systemctl stop dhcpd')
|
||||||
|
self.shcmd('systemctl start dhcpd')
|
||||||
|
self.shcmd('systemctl enable dhcpd')
|
||||||
|
os.system('systemctl status dhcpd')
|
||||||
|
|
||||||
|
RollName = "base"
|
||||||
Reference in New Issue
Block a user