2e0fc42a251dea19872d80d0f411e3cbfed6b0a7
[csit.git] / resources / tools / testbed-setup / cimc / cimc.py
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2016 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import cimclib
17 import argparse
18
19 parser = argparse.ArgumentParser()
20 parser.add_argument("ip", help="CIMC IP address")
21 parser.add_argument("-u", "--username", help="CIMC username (admin)",
22                     default="admin")
23 parser.add_argument("-p", "--password", help="CIMC password (cisco123)",
24                     default="cisco123")
25 parser.add_argument("-d", "--debug", help="Enable debugging", action="count",
26                     default=0)
27
28 parser.add_argument("-i", "--initialize",
29                     help="Initialize args.ip: Power-Off, reset BIOS defaults, Enable console redir, get LOM MAC addr",
30                     action='store_true')
31 parser.add_argument("-s", "--set",
32                     help="Set specific BIOS settings", action='append')
33 parser.add_argument("--wipe", help="Delete all virtual drives",
34                     action='store_true')
35 parser.add_argument("-r", "--raid", help="Create RAID array",
36                     action='store_true')
37 parser.add_argument("-rl", "--raid-level", help="RAID level", default='10')
38 parser.add_argument("-rs", "--raid-size", help="RAID size", default=3*571250)
39 parser.add_argument("-rd", "--raid-disks",
40                     help="RAID disks ('[1,2][3,4][5,6]')",
41                     default='[1,2][3,4][5,6]')
42 parser.add_argument("-pxe", "--boot-pxe", help="Reboot using PXE",
43                     action='store_true')
44 parser.add_argument("-hdd", "--boot-hdd", help="Boot using HDD on next boot",
45                     action='store_true')
46 parser.add_argument("-poff", "--power-off", help="Power Off",
47                     action='store_true')
48 parser.add_argument("-pon", "--power-on", help="Power On", action='store_true')
49 parser.add_argument("-m", "--mac-table",
50                     help="Show interface MAC address table",
51                     action='store_true')
52
53 args = parser.parse_args()
54
55 cookie = cimclib.login(args.ip, args.username, args.password)
56
57 if args.wipe:
58     cimclib.deleteAllVirtualDrives(args.ip, cookie, args.debug)
59
60 if args.raid:
61     cimclib.createRaid(args.ip, cookie, "raid-virl", args.raid_level, args.raid_size, args.raid_disks, args.debug)
62
63 if args.initialize:
64     cimclib.powerOff(args.ip, cookie)
65     cimclib.restoreBiosDefaultSettings(args.ip, cookie, args.debug)
66     cimclib.enableConsoleRedir(args.ip, cookie, args.debug)
67     cimclib.powerOn(args.ip, cookie, args.debug)
68     cimclib.bootIntoUefi(args.ip, cookie, args.debug)
69     lom_mac = cimclib.getLOMMacAddress(args.ip, cookie, args.debug)
70     print "Host {} LOM MAC address: {}".format(args.ip, lom_mac)
71
72 if args.set:
73     cimclib.setBiosSettings(args.ip, cookie, args.set, args.debug)
74
75 if args.boot_pxe:
76     cimclib.bootPXE(args.ip, cookie, args.debug)
77
78 if args.boot_hdd:
79     cimclib.bootHDDPXE(args.ip, cookie, args.debug)
80
81 if args.power_off:
82     cimclib.powerOff(args.ip, cookie, args.debug)
83
84 if args.power_on:
85     cimclib.powerOn(args.ip, cookie, args.debug)
86
87 if args.mac_table:
88     maclist = cimclib.getMacAddresses(args.ip, cookie, args.debug)
89
90     for k in sorted(maclist.keys()):
91         print "{}:".format(k)
92         for p in sorted(maclist[k].keys()):
93             print "  {} - {}".format(p, maclist[k][p])
94
95 cimclib.logout(args.ip, cookie)