-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec_util.py
More file actions
81 lines (64 loc) · 2.67 KB
/
spec_util.py
File metadata and controls
81 lines (64 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import argparse
import re
import json
import os
SPEC_DIR = '/tmp/specs'
BRINGUP_SPEC_PREFIX = 'bringup'
ADD_HOST_SPEC_PREFIX = 'add-host'
REMOVE_HOST_SPEC_PREFIX = 'remove-host'
ADD_CLUSTER_SPEC_PREFIX = 'add-cluster'
REMOVE_CLUSTER_SPEC_PREFIX = 'remove-cluster'
ESX_IP_START = 4
def generate_bringup_spec(ip_start, esx_count = 3):
"""
Return bringup spec file path
:param ip_start: ESXi IP start value. eg if ip_start=4 and esx_count=3, then esxi IPs will be x.x.x.4, x.x.x.5 and x.x.x.6
:param esx_count: Number of ESXi hosts for bringup operation
"""
spec_path = os.path.join(SPEC_DIR, BRINGUP_SPEC_PREFIX + '-%s-host.json' % esx_count)
try:
with open
except IOError as err:
raise err
except Exception as e:
raise e
return spec_path
def generate_add_host_spec(ip_start, esx_count = 3):
"""
Return add-host spec file path
:param ip_start: ESXi IP start value. eg if ip_start=4 and esx_count=3, then esxi IPs will be x.x.x.4, x.x.x.5 and x.x.x.6
:param esx_count: Number of ESXi hosts for add-host operation
"""
def generate_remove_host_spec():
pass
def generate_add_cluster_spec():
pass
def generate_remove_cluster_spec():
pass
def generate_spec(args):
"""
Returns dictionary of spec file paths
:param args: command-line args from main
"""
spec = dict()
spec["bringup_spec"] = generate_bringup_spec(ip_start=ESX_IP_START, esx_count=args.bringup_host_count)
if args.add_host:
spec["add_host_spec"] = generate_add_host_spec(ip_start=ESX_IP_START + args.bringup_host_count, esx_count=args.add_host_count)
elif args.remove_host:
spec["remove_host_spec"] = generate_remove_host_spec()
elif args.add_cluster:
spec["add_cluster_spec"] = generate_add_cluster_spec()
elif args.remove_cluster:
spec["remove_cluster_spec"] = generate_remove_cluster_spec()
return spec
if __name__ == '__main__':
parser = argparse.ArgumentParser("Spec util")
parser.add()
parser.add_argument('-n', '--bringup-host-count', action='store', default=3, help="Number of ESXi hosts to generate the bringup spec for. Default is 3 hosts")
parser.add_argument('-N', '--add-host-count', action='store', default=3, help="Number of ESXi hosts to generate the add-host spec for. Default is 3 hosts")
parser.add_argument('-a', '--add-host', action='store_true', default=False, help="Generate add-host spec")
parser.add_argument('-r', '--remove-host', action='store_true', default=False, help="Generate remove-cluster spec")
parser.add_argument('-A', '--add-cluster', action='store_true', default=False, help="Generate add-cluster spec")
parser.add_argument('-R', '--remove-cluster', action='store_true', default=False, help="Generate remove-cluster spec")
args = parser.parse_args()
generate_spec(args)