-
Notifications
You must be signed in to change notification settings - Fork 11
/
iaas_launch.py
executable file
·208 lines (183 loc) · 7.02 KB
/
iaas_launch.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# Copyright 2017 ARICENT HOLDINGS LUXEMBOURG SARL and Cable Television
# Laboratories, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script is responsible for deploying Aricent_Iaas environments and
# Openstack Services
import argparse
import getpass
import logging
import os
import sys
from drp_python.network_layer.http_session import HttpSession
from snaps_common.file import file_utils
from snaps_boot.provision import pxe_utils, rebar_utils, ipmi_utils
logger = logging.getLogger('iaas_launch')
ARG_NOT_SET = "argument not set"
def __run(arguments):
"""
This will launch the provisioning of Bare metat & IaaS.
There is pxe based configuration defined to provision the bare metal.
For IaaS provisioning different deployment models are supported.
Relevant conf files related to PXE based Hw provisioning & Openstack based
IaaS must be present in ./conf folder.
:param arguments: This expects command line options to be entered by user
for relavant operations.
:return: To the OS
"""
log_level = logging.INFO
if arguments.log_level != 'INFO':
log_level = logging.DEBUG
logging.basicConfig(stream=sys.stdout, level=log_level)
logger.info('Launching Operation Starts ........')
user = getpass.getuser()
logger.info('Running as user %s', user)
config_filepath = os.path.expanduser(arguments.config)
logger.info('Reading configuration file [%s]', config_filepath)
config = file_utils.read_yaml(config_filepath)
prv_config = config.get('PROVISION')
if not prv_config:
raise Exception('Missing top-level config member PROVISION')
logger.debug('PROVISION configuration %s', prv_config)
# TODO/FIXME - Hardcoding of user/pass should be configurable
drp_config = prv_config.get('digitalRebar')
if drp_config:
logger.info('Rebar configuration %s', drp_config)
user = drp_config.get('user', 'rocketskates')
password = drp_config.get('password', 'r0cketsk8ts')
else:
user = 'rocketskates'
password = 'r0cketsk8ts'
# TODO/FIXME - DRP host and port should be configurable
rebar_session = HttpSession(
'https://localhost:8092', user, password)
if arguments.hardware is not ARG_NOT_SET:
rebar_utils.install_config_drp(rebar_session, config)
if arguments.provisionClean is not ARG_NOT_SET:
rebar_utils.cleanup_drp(rebar_session, config)
if arguments.staticIPCleanup is not ARG_NOT_SET:
# Do we really need to support this function?
pxe_utils.static_ip_cleanup(config)
if arguments.staticIPConfigure is not ARG_NOT_SET:
# Is this something that we should do with cloud-init or other means
# immediately after the OS is laid down?
pxe_utils.static_ip_configure(config)
if arguments.boot is not ARG_NOT_SET:
ipmi_utils.reboot_pxe(config)
if arguments.bootd is not ARG_NOT_SET:
# This power cycles the nodes
ipmi_utils.reboot_disk(config)
if arguments.setIsolCpus is not ARG_NOT_SET:
# This operation is unclear
pxe_utils.set_isol_cpus(config)
if arguments.delIsolCpus is not ARG_NOT_SET:
# This operation is unclear
pxe_utils.del_isol_cpus(config)
logger.info('Completed operation successfully')
if __name__ == '__main__':
# To ensure any files referenced via a relative path will begin from the
# diectory in which this file resides
os.chdir(os.path.dirname(os.path.realpath(__file__)))
parser = argparse.ArgumentParser()
parser.add_argument(
'-p',
'--provision',
dest='hardware',
nargs='?',
default=ARG_NOT_SET,
help='When used, setting up of pxe server and '
'provisioning of PXE clients will be started')
parser.add_argument(
'-f',
'--file',
dest='config',
required=True,
help='The configuration file in YAML format'
' - REQUIRED',
metavar="FILE")
parser.add_argument(
'-l',
'--log-level',
dest='log_level',
default='INFO',
help='Logging Level (INFO|DEBUG)')
parser.add_argument(
'-b',
'--boot',
dest='boot',
nargs='?',
default=ARG_NOT_SET,
help='When used, to boot the system via pxe')
parser.add_argument(
'-bd',
'--bootd',
dest='bootd',
nargs='?',
default=ARG_NOT_SET,
# TODO/FIXME - Does this operation really do anything differently
# CI just calls -b in other contexts and those machines are booting
# from the internal storage
help='When used, to boot the system via hdd')
parser.add_argument(
'-pc',
'--provisionClean',
dest='provisionClean',
nargs='?',
default=ARG_NOT_SET,
help='Cleanup boot environment')
parser.add_argument(
'-s',
'--staticIPConfigure',
dest='staticIPConfigure',
nargs='?',
default=ARG_NOT_SET,
help='Configure static IPs on boot nodes')
parser.add_argument(
'-sc',
'--staticIPCleanup',
dest='staticIPCleanup',
nargs='?',
default=ARG_NOT_SET,
help='Cleans up static IPs on nodes')
parser.add_argument(
'-i',
'--setIsolCpus',
dest='setIsolCpus',
nargs='?',
default=ARG_NOT_SET,
# TODO/FIXME - Description is incorrect
help='When used, the pxe server environment will be removed')
parser.add_argument(
'-ic',
'--cleanIsolCpus',
dest='delIsolCpus',
nargs='?',
default=ARG_NOT_SET,
# TODO/FIXME - Description is incorrect
help='When used, the pxe server environment will be removed')
args = parser.parse_args()
if (args.hardware is ARG_NOT_SET and args.boot is ARG_NOT_SET and
args.bootd is ARG_NOT_SET and
args.provisionClean is ARG_NOT_SET and
args.setIsolCpus is ARG_NOT_SET and
args.delIsolCpus is ARG_NOT_SET and
args.staticIPConfigure is ARG_NOT_SET and
args.staticIPCleanup is ARG_NOT_SET):
print 'Must enter either -p for provision hardware or -pc for clean ' \
'provision hardware or -b for boot or -i for isolate cpu ' \
'provision or -bd for boot from disk'
exit(1)
if args.hardware is ARG_NOT_SET and args.config is ARG_NOT_SET:
print 'Cannot start any deploy iaas operation without -p/--provision' \
' and -f/--file'
exit(1)
__run(args)