Fixes OVF converter and upload
[osm/devops.git] / tools / OVF_converter / ovf_converter_cli.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 ##
5 # Copyright 2016-2017 VMware Inc.
6 # This file is part of ETSI OSM
7 # All Rights Reserved.
8 #
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
12 #
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
19 # under the License.
20 #
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: osslegalrouting@vmware.com
23 ##
24
25 import argparse
26 import yaml
27
28 from converter import OVFConverter, get_version, OS_INFO_FILE_PATH
29
30
31 def execute_cli():
32
33 """
34 Method to parse CLI arguments and execute commands accordingly
35 Args : None
36 Return : None
37 """
38
39 with open(OS_INFO_FILE_PATH) as data_file:
40 os_info = yaml.load(data_file, Loader=yaml.SafeLoader)
41
42 valid_os_strings = "Valid values for osType are:\n"
43 for os_name in os_info.values():
44 valid_os_strings += os_name + ", "
45
46 valid_os_strings = valid_os_strings[:-2]
47
48 parser = argparse.ArgumentParser(description='OVF converter to convert .qcow2 or raw image into OVF')
49
50 parser.add_argument("-v", "--version", action="version", version=str(get_version()),
51 help="shows version of OVF Converter tool")
52
53 parser.add_argument("path", action="store",
54 help="absolute path to source image which will get converted into ovf")
55
56 parser.add_argument("-o", "--output_location", action="store",
57 help="location where created OVF will be kept. This location "
58 "should have write access. If not given file will get "
59 "created at source location (optional)")
60
61 parser.add_argument("-n", "--ovf_name", action="store",
62 help="name of output ovf file. If not given source image name will "
63 " be used (optional)")
64
65 parser.add_argument("-m", "--memory", action="store",
66 help="required memory for VM in MB (default 1 GB)(optional)")
67
68 parser.add_argument("-c", "--cpu", action="store",
69 help="required number of virtual cpus for VM (default 1 cpu) (optional)")
70
71 parser.add_argument("-d", "--disk", action="store",
72 help="required size of disk for VM in GB "
73 "(default as in source disk img) (optional)")
74
75 parser.add_argument("-s", "--osType", action="store",
76 help="required operating system type as specified "
77 "in user document (default os type other 32 bit) (optional) " + valid_os_strings)
78
79 parser.add_argument("-dc", "--disk_Controller", action="store",
80 help="required disk controller type "
81 "(default controller SCSI with lsilogicsas) "
82 "(SATA, IDE, Paravirtual, Buslogic, Lsilogic, Lsilogicsas) (optional)")
83
84 parser.add_argument("--cdrom", action="store_true", default=True,
85 help="whether to include a cd/dvd device (optional)")
86
87 parser.add_argument("-hw", "--hwversion", action="store", default=14,
88 help="Virtual hardware version (default 14)")
89
90 args = parser.parse_args()
91
92 if args.path:
93 con = OVFConverter(args.path,
94 output_location=args.output_location,
95 output_ovf_name=args.ovf_name,
96 memory=args.memory,
97 cpu=args.cpu,
98 disk=args.disk,
99 os_type=args.osType,
100 disk_controller=args.disk_Controller,
101 cdrom=args.cdrom,
102 hwversion=args.hwversion,
103 )
104
105 con.create_ovf()
106
107
108 if __name__ == "__main__":
109 execute_cli()