11 from __future__
import print_function
12 from ProvisionMTTStage
import *
35 ProvisionMTTStage.__init__(self)
37 self.
options[
'target'] = (
None,
"List of remote host names or LAN interfaces to be provisioned")
38 self.
options[
'image'] = (
None,
"Name of image to be instantiated")
39 self.
options[
'bootstrap'] = (
None,
"Name of bootstrap to be used")
40 self.
options[
'controller'] = (
None,
"List of IP addresses of remote node controllers/BMCs")
41 self.
options[
'username'] = (
None,
"Remote controller username")
42 self.
options[
'password'] = (
None,
"Remote controller password")
43 self.
options[
'pwfile'] = (
None,
"File containing remote controller password")
44 self.
options[
'sudo'] = (
False,
"Use sudo to execute privileged commands")
45 self.
options[
'allocate_cmd'] = (
None,
"Command to use for allocating nodes from the resource manager")
46 self.
options[
'deallocate_cmd'] = (
None,
"Command to use for deallocating nodes from the resource manager")
56 IPlugin.activate(self)
61 IPlugin.deactivate(self)
70 lines = testDef.printOptions(self.
options)
77 if cmds[
'allocate_cmd']
is not None and cmds[
'deallocate_cmd']
is not None:
78 allocate_cmdargs = shlex.split(cmds[
'allocate_cmd'])
79 status,stdout,stderr,time = testDef.execmd.execute(cmds, allocate_cmdargs, testDef)
81 log[
'status'] = status
83 log[
'stderr'].extend(stderr)
85 log[
'stderr'] = stderr
91 if cmds[
'allocate_cmd']
is not None and cmds[
'deallocate_cmd']
is not None and self.
allocated ==
True:
92 deallocate_cmdargs = shlex.split(cmds[
'deallocate_cmd'])
93 status,stdout,stderr,time = testDef.execmd.execute(cmds, deallocate_cmdargs, testDef)
95 log[
'status'] = status
97 log[
'stderr'].extend(stderr)
99 log[
'stderr'] = stderr
105 testDef.logger.verbose_print(
"Warewulf 3 Provisioner")
108 testDef.parseOptions(log, self.
options, keyvals, cmds)
112 mylog[
'target'] = cmds[
'target']
114 mylog[
'image'] = cmds[
'image']
115 if cmds[
'controller']:
116 mylog[
'controller'] = cmds[
'controller']
117 if cmds[
'bootstrap']:
118 mylog[
'bootstrap'] = cmds[
'bootstrap']
119 log[
'provisioning'] = mylog
123 if cmds[
'target']
is None:
125 log[
'stderr'] =
"No target hosts identified"
129 targets = cmds[
'target'].split(
',')
132 log[
'stderr'] =
"No target hosts identified"
135 if cmds[
'controller']
is None:
137 log[
'stderr'] =
"No target controllers identified"
141 controllers = cmds[
'controller'].split(
',')
144 log[
'stderr'] =
"No target controllers identified"
148 if cmds[
'image']
is None:
150 log[
'stderr'] =
"No image specified"
154 log[
'stderr'] =
"No image specified"
159 wwcmd = [
"wwsh",
"node",
"list"]
161 wwcmd.insert(0,
"sudo")
162 status,stdout,stderr,_ = testDef.execmd.execute(cmds, wwcmd, testDef)
163 if 0 != status
or stdout
is None:
164 log[
'status'] = status
165 log[
'stderr'] =
"Node list was not obtained"
173 nodes.append(line[0:line.find(
' ')])
184 log[
'stderr'] =
"Target " + tgt +
" is not included in Warewulf node table"
188 if False == self.
allocate(log, cmds, testDef):
195 wwcmd = [
"wwsh",
"provision",
"set"]
197 wwcmd.insert(0,
"sudo")
199 wwcmd.append(
"--vnfs=" + cmds[
'image'])
200 if cmds[
'bootstrap']:
201 wwcmd.append(
"--bootstrap=" + cmds[
'bootstrap'])
203 status,stdout,stderr,_ = testDef.execmd.execute(cmds, wwcmd, testDef)
205 log[
'status'] = status
206 log[
'stderr'] = stderr
213 ipmicmd[
'command'] = [
"power",
"cycle"]
214 ipmicmd[
'target'] = cmds[
'target']
215 ipmicmd[
'controller'] = cmds[
'controller']
216 ipmicmd[
'username'] = cmds[
'username']
217 ipmicmd[
'password'] = cmds[
'password']
218 ipmicmd[
'pwfile'] = cmds[
'pwfile']
219 ipmicmd[
'sudo'] = cmds[
'sudo']
222 ipmitool = testDef.selectPlugin(
"IPMITool",
"tool")
225 log[
'stderr'] =
"IPMITool was not found"
230 ipmitool.execute(ipmilog, ipmicmd, testDef)
233 log[
'status'] = ipmilog[
'status']
234 if ipmilog[
'stdout']
is not None:
235 log[
'stdout'] = ipmilog[
'stdout']
236 if ipmilog[
'stderr']
is not None:
237 log[
'stderr'] = ipmilog[
'stderr']