mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	rspconfig gard&admin_passwd in python
This commit is contained in:
		| @@ -25,6 +25,9 @@ class BmcConfigInterface(object): | ||||
|     def dump_process(self, task): | ||||
|         return task.run("dump_process") | ||||
|  | ||||
|     def gard_clear(self, task): | ||||
|         return task.run("gard_clear") | ||||
|  | ||||
|     def set_sshcfg(self, task): | ||||
|         return task.run("set_sshcfg") | ||||
|  | ||||
|   | ||||
| @@ -179,6 +179,20 @@ class OpenBMCBmcConfigTask(ParallelNodesCommand): | ||||
|         except SelfServerException as e: | ||||
|             self.callback.info('%s: %s'  % (node, e.message)) | ||||
|  | ||||
|     def gard_clear(self, **kw): | ||||
|  | ||||
|         node = kw['node'] | ||||
|         obmc = openbmc.OpenBMCRest(name=node, nodeinfo=kw['nodeinfo'], messager=self.callback, | ||||
|                                    debugmode=self.debugmode, verbose=self.verbose) | ||||
|  | ||||
|         try: | ||||
|             obmc.login() | ||||
|             obmc.clear_gard() | ||||
|             self.callback.info('%s: GARD cleared' % node) | ||||
|  | ||||
|         except SelfServerException as e: | ||||
|             self.callback.info('%s: %s'  % (node, e.message)) | ||||
|  | ||||
|     def pre_set_sshcfg(self, *arg, **kw): | ||||
|         local_home_dir=os.path.expanduser('~') | ||||
|         self.local_ssh_dir = local_home_dir + "/.ssh/" | ||||
| @@ -271,6 +285,8 @@ rmdir \"/tmp/$userid\" \n") | ||||
|                 netinfo_dict[k] = v | ||||
|             elif k == 'hostname': | ||||
|                 self._set_hostname(v, **kw) | ||||
|             elif k == 'admin_passwd': | ||||
|                 self._set_admin_password(v, **kw) | ||||
|             elif k in openbmc.RSPCONFIG_APIS: | ||||
|                 self._set_apis_values(k, v, **kw) | ||||
|             else: | ||||
| @@ -292,7 +308,26 @@ rmdir \"/tmp/$userid\" \n") | ||||
|         self._set_apis_values("hostname", hostname, **kw) | ||||
|         self._get_netinfo(hostname=True, ntpserver=False, **kw)  | ||||
|         return | ||||
|          | ||||
|  | ||||
|     def _set_admin_password(self, admin_passwd, **kw): | ||||
|         node = kw['node'] | ||||
|         node_info = kw['nodeinfo'] | ||||
|  | ||||
|         origin_passwd, new_passwd = admin_passwd.split(',') | ||||
|  | ||||
|         if origin_passwd != node_info['password']: | ||||
|             self.callback.info('%s: Current BMC password is incorrect, cannot set the new password.' % node) | ||||
|             return | ||||
|  | ||||
|         obmc = openbmc.OpenBMCRest(name=node, nodeinfo=node_info, messager=self.callback, | ||||
|                                    debugmode=self.debugmode, verbose=self.verbose) | ||||
|         try: | ||||
|             obmc.login() | ||||
|             obmc.set_admin_passwd(new_passwd) | ||||
|             self.callback.info("%s: BMC Setting Password..." % node) | ||||
|         except (SelfServerException, SelfClientException) as e: | ||||
|             self.callback.info("%s: %s" % (node, e.message)) | ||||
|  | ||||
|     def _set_apis_values(self, key, value, **kw): | ||||
|         node = kw['node'] | ||||
|         obmc = openbmc.OpenBMCRest(name=node, nodeinfo=kw['nodeinfo'], messager=self.callback, | ||||
|   | ||||
| @@ -46,6 +46,8 @@ DUMP_URLS = { | ||||
|     "list"      : "/dump/enumerate",  | ||||
| } | ||||
|  | ||||
| GARD_CLEAR_URL = "/org/open_power/control/gard/action/Reset" | ||||
|  | ||||
| INVENTORY_URL = "/inventory/enumerate" | ||||
|  | ||||
| LEDS_URL = "/led/physical/enumerate" | ||||
| @@ -166,6 +168,8 @@ RSPCONFIG_NETINFO_URL = { | ||||
|     'ntpserver': "/network/#NIC#/attr/NTPServers", | ||||
| } | ||||
|  | ||||
| PASSWD_URL = '/user/root/action/SetPassword' | ||||
|  | ||||
| RSPCONFIG_APIS = { | ||||
|     'hostname': { | ||||
|         'baseurl': "/network/config/", | ||||
| @@ -571,6 +575,11 @@ class OpenBMCRest(object): | ||||
|             data={"data": attr_info['get_data']} | ||||
|         return self.request(method, get_url, payload=data, cmd="get_%s" % key) | ||||
|  | ||||
|     def set_admin_passwd(self, passwd): | ||||
|  | ||||
|         payload = { "data": [passwd] } | ||||
|         self.request('POST', PASSWD_URL, payload=payload, cmd='set_admin_password') | ||||
|  | ||||
|     def clear_dump(self, clear_arg): | ||||
|  | ||||
|         if clear_arg == 'all': | ||||
| @@ -612,6 +621,12 @@ class OpenBMCRest(object): | ||||
|         path = DUMP_URLS['download'].replace('#ID#', download_id) | ||||
|         self.download('GET', path, file_path, headers=headers, cmd='download_dump') | ||||
|  | ||||
|     def clear_gard(self): | ||||
|  | ||||
|         payload = { "data": [] } | ||||
|         url = HTTP_PROTOCOL + self.bmcip + GARD_CLEAR_URL | ||||
|         return self.request('POST', url, payload=payload, cmd='clear_gard') | ||||
|  | ||||
|     def get_netinfo(self): | ||||
|         data = self.request('GET', RSPCONFIG_NETINFO_URL['get_netinfo'], cmd="get_netinfo") | ||||
|         try: | ||||
|   | ||||
| @@ -91,13 +91,15 @@ RSPCONFIG_SET_OPTIONS = { | ||||
|     'powersupplyredundancy':"^enabled$|^disabled$", | ||||
|     'powerrestorepolicy':"^always_on$|^always_off$|^restore$", | ||||
|     'bootmode':"^regular$|^safe$|^setup$", | ||||
|     'admin_passwd':'.*,.*', | ||||
| } | ||||
| RSPCONFIG_USAGE = """ | ||||
| Handle rspconfig operations. | ||||
|  | ||||
| Usage: | ||||
|        rspconfig -h|--help | ||||
|        rspconfig dump [[-l|--list] | [-g|--generate] | [-c|--clear <arg>] | [-d|--download <arg>]] [-V|--verbose] | ||||
|        rspconfig dump [[-l|--list] | [-g|--generate] | [-c|--clear --id <arg>] | [-d|--download --id <arg>]] [-V|--verbose] | ||||
|        rspconfig gard -c|--clear [-V|--verbose] | ||||
|        rspconfig sshcfg [-V|--verbose] | ||||
|        rspconfig ip=dhcp [-V|--verbose] | ||||
|        rspconfig get [<args>...] [-V|--verbose] | ||||
| @@ -107,8 +109,9 @@ Options: | ||||
|   -V,--verbose        Show verbose message | ||||
|   -l,--list           List are dump files | ||||
|   -g,--generate       Trigger a new dump file | ||||
|   -c,--clear <arg>    The id of file to clear or all if specify 'all' | ||||
|   -d,--download <arg> The id of file to download or all if specify 'all' | ||||
|   -c,--clear          To clear the specified dump file | ||||
|   -d,--download       To download specified dump file | ||||
|   --id <arg>          The dump file id or 'all' | ||||
|  | ||||
| The supported attributes to get are: %s | ||||
|  | ||||
| @@ -724,11 +727,14 @@ class OpenBMCManager(base.BaseManager): | ||||
|             elif opts['--generate']: | ||||
|                 DefaultBmcConfigManager().dump_generate(runner) | ||||
|             elif opts['--clear']: | ||||
|                 DefaultBmcConfigManager().dump_clear(runner, opts['--clear'][0]) | ||||
|                 DefaultBmcConfigManager().dump_clear(runner, opts['--id']) | ||||
|             elif opts['--download']: | ||||
|                 DefaultBmcConfigManager().dump_download(runner, opts['--download'][0]) | ||||
|                 DefaultBmcConfigManager().dump_download(runner, opts['--id']) | ||||
|             else: | ||||
|                 DefaultBmcConfigManager().dump_process(runner) | ||||
|         elif opts['gard']: | ||||
|             if opts['--clear']: | ||||
|                 DefaultBmcConfigManager().gard_clear(runner) | ||||
|         elif opts['sshcfg']: | ||||
|             DefaultBmcConfigManager().set_sshcfg(runner) | ||||
|         elif opts['ip=dhcp']: | ||||
|   | ||||
| @@ -344,13 +344,18 @@ sub refactor_args { | ||||
|     my $extrargs  = $request->{arg};     | ||||
|     if ($command eq "rspconfig") { | ||||
|         my $subcommand = $extrargs->[0]; | ||||
|         if ($subcommand !~ /^dump$|^sshcfg$|^ip=dhcp$/) { | ||||
|         if ($subcommand !~ /^dump$|^sshcfg$|^ip=dhcp$|^gard$/) { | ||||
|             if (grep /=/, @$extrargs) { | ||||
|                 unshift @$extrargs, "set"; | ||||
|             } else { | ||||
|                 unshift @$extrargs, "get"; | ||||
|             } | ||||
|         } | ||||
|         if ($subcommand eq "dump") { | ||||
|             if (defined($extrargs->[1]) and $extrargs->[1] =~ /-c|--clear|-d|--download/){ | ||||
|                 splice(@$extrargs, 2, 0, "--id"); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return 0; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user