2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-06-13 09:50:19 +00:00

rspconfig ntpservers

This commit is contained in:
XuWei
2018-02-27 01:42:35 -05:00
parent 29f6fa75cf
commit d914a4a09c
4 changed files with 60 additions and 11 deletions

View File

@ -23,7 +23,7 @@ from scp import SCPClient
import logging
logger = logging.getLogger('xcatagent')
RSPCONFIG_GET_NETINFO=['ip', 'netmask', 'gateway', 'vlan', 'ipsrc', 'hostname']
RSPCONFIG_GET_NETINFO=['ip', 'netmask', 'gateway', 'vlan', 'ipsrc', 'hostname', 'ntpservers']
RSPCONFIG_SET_NETINFO=['ip', 'netmask', 'gateway', 'vlan']
XCAT_LOG_DUMP_DIR = "/var/log/xcat/dump/"
@ -275,7 +275,8 @@ rmdir \"/tmp/$userid\" \n")
if len(netinfo_dict):
self._get_netinfo(ip=netinfo_dict.get('ip', False), ipsrc=netinfo_dict.get('ipsrc', False), netmask=netinfo_dict.get('netmask', False),
gateway=netinfo_dict.get('gateway', False),vlan= netinfo_dict.get('vlan', False),
hostname=netinfo_dict.get('hostname', False), **kw)
hostname=netinfo_dict.get('hostname', False),
ntpservers=netinfo_dict.get('ntpservers', False), **kw)
def set_attributes(self, attributes, **kw):
netinfo_dict={'vlan':False}
@ -287,6 +288,8 @@ rmdir \"/tmp/$userid\" \n")
self._set_hostname(v, **kw)
elif k == 'admin_passwd':
self._set_admin_password(v, **kw)
elif k == 'ntpservers':
self._set_ntp_servers(v, **kw)
elif k in openbmc.RSPCONFIG_APIS:
self._set_apis_values(k, v, **kw)
else:
@ -309,6 +312,40 @@ rmdir \"/tmp/$userid\" \n")
self._get_netinfo(hostname=True, ntpserver=False, **kw)
return
def _set_ntp_servers(self, servers, **kw):
node = kw['node']
node_info = kw['nodeinfo']
obmc = openbmc.OpenBMCRest(name=node, nodeinfo=node_info, messager=self.callback,
debugmode=self.debugmode, verbose=self.verbose)
try:
obmc.login()
netinfo = obmc.get_netinfo()
except (SelfServerException, SelfClientException) as e:
self.callback.info('%s: %s' % (node, e.message))
return
if not netinfo:
return self.callback.error("%s: No network information get" % node)
nic = None
for k,v in netinfo.items():
if 'ip' in v and v['ip'] == node_info['bmcip']:
nic = k
try:
obmc.set_ntp_servers(nic, servers)
self.callback.info('%s: BMC Setting NTPServers...' % node)
netinfo = obmc.get_netinfo()
except (SelfServerException, SelfClientException) as e:
self.callback.info('%s: %s' % (node, e.message))
return
ntpservers = None
if nic in netinfo:
ntpservers = netinfo[nic]['ntpservers']
self.callback.info('%s: BMC NTP Servers: %s' % (node, ntpservers))
def _set_admin_password(self, admin_passwd, **kw):
node = kw['node']
node_info = kw['nodeinfo']
@ -362,7 +399,7 @@ rmdir \"/tmp/$userid\" \n")
result = "set net(%s, %s, %s) for eth0" % (ip, netmask, gateway)
return self.callback.info("set_netinfo %s" % result)
def _get_netinfo(self, ip=False, ipsrc=False, netmask=False, gateway=False, vlan=False, hostname=False, ntpserver=True, **kw):
def _get_netinfo(self, ip=False, ipsrc=False, netmask=False, gateway=False, vlan=False, hostname=False, ntpservers=False, **kw):
node = kw['node']
obmc = openbmc.OpenBMCRest(name=node, nodeinfo=kw['nodeinfo'], messager=self.callback,
debugmode=self.debugmode, verbose=self.verbose)
@ -387,7 +424,7 @@ rmdir \"/tmp/$userid\" \n")
self.callback.info("%s: BMC Hostname: %s" %(node, bmchostname))
dic_length = len(netinfo)
netinfodict = {'ip':[], 'netmask':[], 'gateway':[],
'vlan':[], 'ipsrc':[], 'ntpserver':[]}
'vlan':[], 'ipsrc':[], 'ntpservers':[]}
for nic,attrs in netinfo.items():
addon_string = ''
if dic_length > 1:
@ -397,7 +434,7 @@ rmdir \"/tmp/$userid\" \n")
netinfodict['gateway'].append("BMC Gateway"+addon_string+": %s (default: %s)" % (attrs["gateway"], defaultgateway))
netinfodict['vlan'].append("BMC VLAN ID"+addon_string+": %s" % attrs["vlanid"])
netinfodict['ipsrc'].append("BMC IP Source"+addon_string+": %s" % attrs["ipsrc"])
netinfodict['ntpserver'].append("BMC NTP Servers"+addon_string+": %s" % attrs["ntpservers"])
netinfodict['ntpservers'].append("BMC NTP Servers"+addon_string+": %s" % attrs["ntpservers"])
if ip:
for i in netinfodict['ip']:
self.callback.info("%s: %s" % (node, i))
@ -413,7 +450,7 @@ rmdir \"/tmp/$userid\" \n")
if vlan:
for i in netinfodict['vlan']:
self.callback.info("%s: %s" % (node, i))
if ntpserver:
for i in netinfodict['netserver']:
if ntpservers:
for i in netinfodict['ntpservers']:
self.callback.info("%s: %s" % (node, i))
return netinfo

View File

@ -165,7 +165,7 @@ RSPCONFIG_NETINFO_URL = {
'nic_ip': "/network/#NIC#/action/IP",
'vlan': "/network/action/VLAN",
'ipdhcp': "/network/action/Reset",
'ntpserver': "/network/#NIC#/attr/NTPServers",
'ntpservers': "/network/#NIC#/attr/NTPServers",
}
PASSWD_URL = '/user/root/action/SetPassword'
@ -580,6 +580,12 @@ class OpenBMCRest(object):
payload = { "data": [passwd] }
self.request('POST', PASSWD_URL, payload=payload, cmd='set_admin_password')
def set_ntp_servers(self, nic, servers):
payload = { "data": [servers] }
url = RSPCONFIG_NETINFO_URL['ntpservers'].replace('#NIC#', nic)
self.request('PUT', url, payload=payload, cmd='set_ntp_servers')
def clear_dump(self, clear_arg):
if clear_arg == 'all':
@ -659,7 +665,11 @@ class OpenBMCRest(object):
info = data[dev]
utils.update2Ddict(netinfo, nicid, "vlanid", info.get("Id", "Disable"))
utils.update2Ddict(netinfo, nicid, "mac", info["MACAddress"])
utils.update2Ddict(netinfo, nicid, "ntpservers", info["NTPServers"])
ntpservers = None
tmp_ntpservers = ''.join(info["NTPServers"])
if tmp_ntpservers:
ntpservers = tmp_ntpservers
utils.update2Ddict(netinfo, nicid, "ntpservers", ntpservers)
return netinfo
except KeyError:
error = 'Error: Received wrong format response: %s' % data

View File

@ -80,13 +80,14 @@ RFLASH_URLS = {
}
}
RSPCONFIG_GET_OPTIONS = ['ip','ipsrc','netmask','gateway','vlan','hostname','bootmode','autoreboot','powersupplyredundancy','powerrestorepolicy']
RSPCONFIG_GET_OPTIONS = ['ip','ipsrc','netmask','gateway','vlan','ntpservers','hostname','bootmode','autoreboot','powersupplyredundancy','powerrestorepolicy']
RSPCONFIG_SET_OPTIONS = {
'ip':'.*',
'netmask':'.*',
'gateway':'.*',
'vlan':'\d+',
'hostname':"\*|.*",
'ntpservers':'.*',
'autoreboot':"^0|1$",
'powersupplyredundancy':"^enabled$|^disabled$",
'powerrestorepolicy':"^always_on$|^always_off$|^restore$",

View File

@ -342,8 +342,9 @@ sub refactor_args {
my $request = shift;
my $command = $request->{command}->[0];
my $extrargs = $request->{arg};
my $subcommand;
if ($command eq "rspconfig") {
my $subcommand = $extrargs->[0];
$subcommand = $extrargs->[0];
if ($subcommand !~ /^dump$|^sshcfg$|^ip=dhcp$|^gard$/) {
if (grep /=/, @$extrargs) {
unshift @$extrargs, "set";