8 sys.path.append(bindir)
14 print (
'Please select from the list of running VMs\n\n'+
'\n'.
join(selectionoption))
15 userin = int(raw_input(prompt))
17 print(
'\nThat was not a number\n\n')
20 print(
'\nInput must be less than or equal to {0}.\n\n'.
format(max_))
22 print(
'\nInput must be greater than or equal to 1\n\n')
39 executable = os.path.join(bindir,
'VBoxManage')
42 runningvms= subprocess.check_output(
'%s list runningvms' %executable,shell=
True).splitlines()
43 if len(runningvms) != 0:
44 for n
in range(0,
len(runningvms)):
45 vmlist.append(
'%s: %s' %(n+1,runningvms[n].rsplit(
' ',1)[0].strip(
'"')))
46 vmdict[n+1]=runningvms[n].rsplit(
' ',1)[-1]
47 usersel=
input_sel(
'\nEnter the number of the VM: ',
len(runningvms),vmlist)
50 print(
'Can not retrieve list of running VMs')
53 vmuuid=vmdict[usersel]
55 offtime = random.randint(60, 90)
56 ontime = random.randint(10, 90)
57 timenow = time.strftime(
"%Y-%m-%d %H:%M:%S", time.gmtime())
58 on = subprocess.call(
'%s controlvm %s setlinkstate1 on' %(executable,vmuuid),
61 print (
'%s: Plug Network cable into VM %s for %ds: %s' % (timenow, runningvms[usersel-1].rsplit(
' ',1)[0].strip(
'"'),ontime, str(status)))
63 timenow = time.strftime(
"%Y-%m-%d %H:%M:%S", time.gmtime())
64 off = subprocess.call(
'%s controlvm %s setlinkstate1 off' %(executable,vmuuid),
67 print (
'%s: Unplug Network cable from VM %s for %ds: %s' % (timenow, runningvms[usersel-1].rsplit(
' ',1)[0].strip(
'"'),offtime, str(status)))
69 except KeyboardInterrupt:
70 sys.exit(
'\nUser Interrupt')
71 except Exception
as e:
72 print(
"Error in %s in function %s: %s" % (__name__, sys._getframe().f_code.co_name, e.message))
73 if __name__ ==
"__main__":
def controlvmnetworkstate()
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
def input_sel(prompt, max_, selectionoption)
void print(std::FILE *f, const S &format_str, Args &&...args)