-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathiaas_launch.py
executable file
·192 lines (167 loc) · 7.69 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
# 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 logging
import sys
import os
from snaps_openstack.common.utils import file_utils
from snaps_openstack.provision.openstack.deployment import deploy_infra
sys.path.append("common/utils")
__author__ = '_ARICENT'
logger = logging.getLogger('launch_provisioning')
ARG_NOT_SET = "argument not set"
def __installation_logs(level_value):
"""
This will set the logging levels for the openstack installation based on
inputes received from the CLI
"""
from snaps_openstack.common.consts import consts
log_level = logging.INFO
logFileName = consts.OPENSTACK_INSTALLATION_LOGS
if level_value.upper() == 'INFO':
log_level = logging.INFO
elif level_value.upper() == 'ERROR':
log_level = logging.ERROR
elif level_value.upper() == 'DEBUG':
log_level = logging.DEBUG
elif level_value.upper() == 'WARNING':
log_level = logging.WARNING
elif level_value.upper() == 'CRITICAL':
log_level = logging.CRITICAL
else:
print "Incorrect log level " + level_value + " received as input from user"
exit()
logging.basicConfig(format='%(asctime)s %(levelname)s [%(filename)s:%(lineno)s - \
%(funcName)2s() ] %(message)s ', datefmt='%b %d %H:%M',
filename=logFileName, filemode='w', level=log_level)
logging.getLogger().addHandler(logging.StreamHandler())
def __manage_operation(config, operation):
"""
This will launch the provisioning of openstack setup on the cluster node
which are defined in the conf/openstack/devstack/deployment.yaml.
:param config: This configuration data extracted from the provided yaml
file.
"""
if config:
config_dict = {}
if config.get('openstack'):
logger.info(
"########################### Yaml Configuration##############")
logger.info(config)
logger.info(
"############################################################")
logger.info("Read & Validate functionality for Kolla OpenStack")
deploy_infra(config, operation)
else:
logger.error("Configuration Error ")
def main(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: the command line arguments
:return: To the OS
"""
__installation_logs(arguments.log_level)
dir_path = os.path.dirname(os.path.realpath(__file__))
export_path = dir_path + "/"
os.environ['CWD_IAAS'] = export_path
# Functions to read yml for IaaS Openstack environment
config = file_utils.read_yaml(arguments.config)
logger.info('Read configuration file - ' + arguments.config)
if arguments.upgradecluster is not ARG_NOT_SET:
if arguments.upgradecluster == 'queens':
__manage_operation(config, "upgrade")
else:
logger.info("Cannot start upgrade operation. Only support upgrade from pike to queens")
exit(1)
if arguments.downgradecluster is not ARG_NOT_SET:
if arguments.downgradecluster == 'pike':
__manage_operation(config, "downgrade")
else:
logger.info("Cannot start downgrade operation. Only support downgrade from queens to pike")
exit(1)
if arguments.deploy is not ARG_NOT_SET:
__manage_operation(config, "deploy")
if arguments.dreg is not ARG_NOT_SET:
__manage_operation(config, "deployregistry")
if arguments.dregclean is not ARG_NOT_SET:
logger.info("Cleaning up along with registry")
logger.info(arguments.dregclean)
__manage_operation(config, "cleanregistry")
if arguments.clean is not ARG_NOT_SET:
__manage_operation(config, "clean")
logger.info('Completed operation successfully')
if __name__ == '__main__':
# To ensure any files referenced via a relative path will begin from the
# directory in which this file resides
os.chdir(os.path.dirname(os.path.realpath(__file__)))
parser = argparse.ArgumentParser()
parser_group = parser.add_mutually_exclusive_group()
parser.add_argument(
'-f', '--file', dest='config', required=True,
help='The configuration file in YAML format - REQUIRED',
metavar="FILE")
parser_group.add_argument(
'-d', '--deploy', dest='deploy', nargs='?', default=ARG_NOT_SET,
help='When used, deployment and provisioning of openstack will be '
'started')
parser_group.add_argument(
'-c', '--clean', dest='clean', nargs='?', default=ARG_NOT_SET,
help='When used, the openstack environment will be removed')
parser_group.add_argument(
'-drs', '--dreg', dest='dreg', nargs='?', default=ARG_NOT_SET,
help='When used, kolla registry is set up along with deployment')
parser_group.add_argument(
'-drc', '--dregc', dest='dregclean', nargs='?', default=ARG_NOT_SET,
help='When used, Openstack deployment is cleaned up along with the '
'kolla registry')
parser_group.add_argument(
'-upgrade', '--upgradecluster', dest='upgradecluster', nargs='?', default=ARG_NOT_SET,
help='When used, Openstack cluster is upgraded to the defined release'
)
parser_group.add_argument(
'-downgrade', '--downgradecluster', dest='downgradecluster', nargs='?', default=ARG_NOT_SET,
help='When used, Openstack cluster is downgraded to the defined release'
)
parser.add_argument(
'-l', '--log-level', dest='log_level', default='INFO',
help='Logging Level ( DEBUG | INFO | WARNING | ERROR | CRITICAL)')
args = parser.parse_args()
if (args.dreg is ARG_NOT_SET and args.dregclean is ARG_NOT_SET
and args.deploy is ARG_NOT_SET and args.clean is ARG_NOT_SET
and args.upgradecluster is ARG_NOT_SET and args.downgradecluster is ARG_NOT_SET):
logger.info(
'Must enter either -d for deploy IaaS or -c for cleaning up and '
'environment or -drc to cleanup registry or -drs to setup '
'registry or -upgrade for upgrade the openstack cluster or -downgrade for downgrade the openstack cluster.')
exit(1)
if args.deploy is not ARG_NOT_SET and args.clean is not ARG_NOT_SET:
logger.info('Cannot enter both options -d/--deploy and -c/--clean')
exit(1)
if args.deploy is not ARG_NOT_SET and args.config is ARG_NOT_SET:
logger.info(
'Cannot start deploy operation without configuration. '
'Choose the option -f/--file')
exit(1)
if args.deploy is ARG_NOT_SET and args.config is ARG_NOT_SET:
logger.info(
'Cannot start any deploy iaas operation without both -d/--deploy '
'and -f/--file')
exit(1)
main(args)