1 # Copyright 2019 Whitestack, LLC
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
15 # For those usages not covered by the Apache License, Version 2.0 please
16 # contact: esousa@whitestack.com or glavado@whitestack.com
25 from datetime
import datetime
27 from .generators
.ansible_generator
import AnsibleGenerator
30 def configure_logger(args
):
32 logger
= logging
.getLogger()
35 logger
.setLevel(logging
.DEBUG
)
37 logger
.setLevel(logging
.INFO
)
39 handler
= logging
.StreamHandler(sys
.stdout
)
42 handler
.setLevel(logging
.DEBUG
)
44 handler
.setLevel(logging
.INFO
)
46 formatter
= logging
.Formatter('[%(levelname)s] %(message)s')
47 handler
.setFormatter(formatter
)
48 logger
.addHandler(handler
)
51 def verify_environment(args
):
55 def input_processing():
56 parser
= argparse
.ArgumentParser(description
='Charm generator for OSM VNFs')
58 # Setting logger from INFO to DEBUG
59 parser
.add_argument('-v', '--verbose', required
=False, action
='store_true',
60 help='increase output verbosity')
63 backend_parser
= parser
.add_mutually_exclusive_group(required
=True)
65 backend_parser
.add_argument('--ansible', action
='store_true',
66 help='generate an Ansible charm')
67 backend_parser
.add_argument('--http', action
='store_true',
68 help='generate a HTTP charm')
69 backend_parser
.add_argument('--sol002', action
='store_true',
70 help='generate a SOL002 charm')
71 backend_parser
.add_argument('--scripts', action
='store_true',
72 help='generate a Scripts charm')
75 metadata_parser
= parser
.add_argument_group('metadata')
77 metadata_parser
.add_argument('--summary', required
=False, action
='store',
78 help='summary to be included in the metadata.yaml')
79 metadata_parser
.add_argument('--maintainer', required
=False, action
='store',
80 help='maintainer information to be included in the metadata.yaml')
81 metadata_parser
.add_argument('--description', required
=False, action
='store',
82 help='description to be included in the metadata.yaml')
84 # License header inputs
85 license_header_group
= parser
.add_argument_group('license_header')
87 license_header_group
.add_argument('--company', required
=False, action
='store',
88 help='company name to be included in the license headers')
89 license_header_group
.add_argument('--email', required
=False, action
='store',
90 help='email to be included in the license headers')
92 return parser
.parse_args()
95 def process_args(args
):
96 # Metadata information for metadata.yaml
100 metadata
['summary'] = args
.summary
102 metadata
['maintainer'] = args
.maintainer
104 metadata
['description'] = args
.description
106 # Information for license headers
108 'year': datetime
.now().year
112 license
['company'] = args
.company
114 license
['email'] = args
.email
116 # Options to configure the backends
122 options
['backend'] = 'ansible'
124 options
['backend'] = 'http'
126 options
['backend'] = 'sol002'
128 options
['backend'] = 'scripts'
130 return metadata
, license
, options
134 # getting the input from the user
135 args
= input_processing()
137 # configure the logger
138 configure_logger(args
)
140 logger
.info('Starting generation process...')
142 # verify if the environment is correct and the args are valid
143 verify_environment(args
)
145 # process data to input in generator
146 metadata
, license
, options
= process_args(args
)
148 logger
.debug('Metadata: %s', metadata
)
149 logger
.debug('License: %s', license
)
150 logger
.debug('Options: %s', options
)
152 if options
['backend'] == 'ansible':
153 generator
= AnsibleGenerator(metadata
=metadata
, license
=license
, options
=options
)
154 elif options
['backend'] == 'http':
155 logger
.error('HTTP backend not yet available. Available backends are: ansible')
157 elif options
['backend'] == 'sol002':
158 logger
.error('SOL002 backend not yet available. Available backends are: ansible')
160 elif options
['backend'] == 'scripts':
161 logger
.error('Scripts backend not yet available. Available backends are: ansible')
164 logger
.error('Undefined backend for generator. Available backends are: ansible')
169 logger
.info('Generation process complete.')