From: kasar Date: Wed, 30 May 2018 14:47:08 +0000 (-0700) Subject: Removing vmware ovf converter tool from RO. Moved to Devops in ChangeID# 6238 X-Git-Tag: v4.0.1~3 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=4b41f1ed35d27d5611bd7b6607a3948c436453b4;p=osm%2FRO.git Removing vmware ovf converter tool from RO. Moved to Devops in ChangeID# 6238 Change-Id: I5f40f9209b3d636390af7b95d03fdd4f55f63077 Signed-off-by: kasar --- diff --git a/osm_ro/vmware_utils/OVF_converter/config/disk_controller.yaml b/osm_ro/vmware_utils/OVF_converter/config/disk_controller.yaml deleted file mode 100644 index b0902326..00000000 --- a/osm_ro/vmware_utils/OVF_converter/config/disk_controller.yaml +++ /dev/null @@ -1,30 +0,0 @@ -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - ---- -SATA Controller: - ResourceType: 20 - ResourceSubTypes: ["vmware.sata.ahci"] -IDE Controller: - ResourceType: 5 -SCSI Controller: - ResourceType: 6 - ResourceSubTypes: ["VirtualSCSI", "lsilogic", "buslogic", "lsilogicsas"] \ No newline at end of file diff --git a/osm_ro/vmware_utils/OVF_converter/config/os_type.yaml b/osm_ro/vmware_utils/OVF_converter/config/os_type.yaml deleted file mode 100644 index 385cd7be..00000000 --- a/osm_ro/vmware_utils/OVF_converter/config/os_type.yaml +++ /dev/null @@ -1,138 +0,0 @@ -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - ---- -'0': Unknown -'1': Other (32-bit) -'2': MACOS -'3': ATTUNIX -'4': DGUX -'5': DECNT -'6': Tru64 UNIX -'7': OpenVMS -'8': HPUX -'9': AIX -'10': MVS -'11': OS400 -'12': OS/2 -'13': JavaVM -'14': MSDOS -'15': WIN3x -'16': WIN95 -'17': WIN98 -'18': WINNT -'19': WINCE -'20': NCR3000 -'21': NetWare -'22': OSF -'23': DC/OS -'24': Reliant UNIX -'25': SCO UnixWare -'26': SCO OpenServer -'27': Sequent -'28': IRIX -'29': Solaris -'30': SunOS -'31': U6000 -'32': ASERIES -'33': HP NonStop OS -'34': HP NonStop OSS -'35': BS2000 -'36': LINUX -'37': Lynx -'38': XENIX -'39': VM -'40': Interactive UNIX -'41': BSDUNIX -'42': FreeBSD -'43': NetBSD -'44': GNU Hurd -'45': OS9 -'46': MACH Kernel -'47': Inferno -'48': QNX -'49': EPOC -'50': IxWorks -'51': VxWorks -'52': MiNT -'53': BeOS -'54': HP MPE -'55': NextStep -'56': PalmPilot -'57': Rhapsody -'58': Windows 2000 -'59': Dedicated -'60': OS/390 -'61': VSE -'62': TPF -'63': Windows (R) Me -'64': Caldera Open UNIX -'65': OpenBSD -'66': Not Applicable -'67': Windows XP -'68': z/OS -'69': Microsoft Windows Server 2003 -'70': Microsoft Windows Server 2003 64-Bit -'71': Windows XP 64-Bit -'72': Windows XP Embedded -'73': Windows Vista -'74': Windows Vista 64-Bit -'75': Windows Embedded for Point of Service -'76': Microsoft Windows Server 2008 -'77': Microsoft Windows Server 2008 64-Bit -'78': FreeBSD 64-Bit -'79': RedHat Enterprise Linux -'80': RedHat Enterprise Linux 64-Bit -'81': Solaris 64-Bit -'82': SUSE -'83': SUSE 64-Bit -'84': SLES -'85': SLES 64-Bit -'86': Novell OES -'87': Novell Linux Desktop -'88': Sun Java Desktop System -'89': Mandriva -'90': Mandriva 64-Bit -'91': TurboLinux -'92': TurboLinux 64-Bit -'93': Ubuntu -'94': Ubuntu 64-Bit -'95': Debian -'96': Debian 64-Bit -'97': Linux 2.4.x -'98': Linux 2.4.x 64-Bit -'99': Linux 2.6.x -'100': Linux 2.6.x 64-Bit -'101': Linux 64-Bit -'102': Other 64-Bit -'103': Microsoft Windows Server 2008 R2 -'104': VMware ESXi -'105': Microsoft Windows 7 -'106': CentOS 32-bit -'107': CentOS 64-bit -'108': Oracle Linux 32-bit -'109': Oracle Linux 64-bit -'110': eComStation 32-bitx -'111': Microsoft Windows Server 2011 -'113': Microsoft Windows Server 2012 -'114': Microsoft Windows 8 -'115': Microsoft Windows 8 64-bit -'116': Microsoft Windows Server 2012 R2 diff --git a/osm_ro/vmware_utils/OVF_converter/format_converter/__init__.py b/osm_ro/vmware_utils/OVF_converter/format_converter/__init__.py deleted file mode 100644 index db9e016c..00000000 --- a/osm_ro/vmware_utils/OVF_converter/format_converter/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## diff --git a/osm_ro/vmware_utils/OVF_converter/format_converter/command_progress.py b/osm_ro/vmware_utils/OVF_converter/format_converter/command_progress.py deleted file mode 100644 index cbfb7378..00000000 --- a/osm_ro/vmware_utils/OVF_converter/format_converter/command_progress.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - -import threading -import sys - -class RepeatingTimer(threading._Timer): - """ Class to run thread parally """ - def run(self): - """ Method to run thread """ - while True: - self.finished.wait(self.interval) - if self.finished.is_set(): - return - else: - self.function(*self.args, **self.kwargs) - - -class CommandProgressbar(object): - """ Class to show progressbar while waiting fro command output """ - - def __init__(self): - self.timer = None - - def __show_progressbar(self): - """ - Private method to show progressbar while waiting for command to complete - Args : None - Return : None - """ - print '\b.', - sys.stdout.flush() - - def start_progressbar(self): - """ - Method to start progressbar thread - Args : None - Return : None - """ - self.timer = RepeatingTimer(1.0, self.__show_progressbar) - self.timer.daemon = True # Allows program to exit if only the thread is alive - self.timer.start() - - def stop_progressbar(self): - """ - Method to stop progressbar thread - Args : None - Return : None - """ - self.timer.cancel() diff --git a/osm_ro/vmware_utils/OVF_converter/format_converter/converter.py b/osm_ro/vmware_utils/OVF_converter/format_converter/converter.py deleted file mode 100644 index 3c647a9b..00000000 --- a/osm_ro/vmware_utils/OVF_converter/format_converter/converter.py +++ /dev/null @@ -1,569 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - -import logging -import os -import subprocess -import yaml -from lxml import etree as ET -from command_progress import CommandProgressbar - -#file paths -MODULE_DIR = os.path.dirname(__file__) -OVF_TEMPLATE_PATH = os.path.join(os.path.dirname(MODULE_DIR), - "ovf_template/template.xml") -OS_INFO_FILE_PATH = os.path.join(os.path.dirname(MODULE_DIR), - "config/os_type.yaml") -DISK_CONTROLLER_INFO_FILE_PATH = os.path.join(os.path.dirname(MODULE_DIR), - "config/disk_controller.yaml") - - -#Set logger -LOG_FILE = os.path.join(os.path.dirname(MODULE_DIR),"logs/ovf_converter.log") -logger = logging.getLogger(__name__) -hdlr = logging.FileHandler(LOG_FILE) -formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') -hdlr.setFormatter(formatter) -logger.addHandler(hdlr) -logger.setLevel(10) - -__version__ = "1.0" -__description__ = "initial Release" - -def get_version(*args, **kwargs): - """ get version of this application""" - version = str(__version__ ) +" - "+ str( __description__ ) - return version - -#converter class -class OVFConverter(object): - """ Class to convert input image into OVF format """ - - def __init__(self, source_img_path, output_location=None, output_ovf_name=None, - memory=None, cpu=None, disk=None, os_type=None, - disk_controller=None, - options={'subformat':'streamOptimized'}): - """ - Constructor to initialize object of class OVFConverter - Args: - source_img_path - absolute path to source image which will get convert into ovf - output_location - location where created OVF will be kept. This location - should have write access. If not given file will get - created at source location (optional) - output_ovf_name - name of output ovf.If not given source image name will - be used (optional) - memory - required memory for VM in MB (optional) - cpu - required number of virtual cpus for VM (optional) - disk - required size of disk for VM in GB (optional) - os_type- required operating system type as specified in user document - (default os type other 32 bit) (optional) - disk_controller - required disk controller type - (default controller SCSI with lsilogicsas) - (SATA, IDE, Paravirtual, Buslogic, Lsilogic, Lsilogicsas) (optional) - options - subformat option for OVF (optional) - - Returns: - Nothing. - """ - self.logger = logger - self.ovf_template_path = OVF_TEMPLATE_PATH - - self.source_img_path = source_img_path - file_location, file_extension = os.path.splitext(self.source_img_path) - self.source_img_location = os.path.dirname(self.source_img_path) - self.source_format = file_extension[1:] - self.source_img_filename = os.path.basename(self.source_img_path).split('.')[0] - - self.output_format = "ovf" - self.output_ovf_name = output_ovf_name.split('.')[0] if output_ovf_name else self.source_img_filename - self.output_location = output_location if output_location else self.source_img_location - self.output_ovf_name_ext = self.output_ovf_name + "." + self.output_format - self.output_path = os.path.join(self.output_location , self.output_ovf_name_ext ) - - self.output_diskimage_format = "vmdk" - self.output_diskimage_name = self.source_img_filename + "."+ self.output_diskimage_format - self.output_diskimage_path = os.path.join(self.output_location, self.output_diskimage_name) - - - self.logger.info("Input parameters to Converter: \n ovf_template_path = {}, \n source_img_path = {}, \n"\ - "source_img_location ={} , \n source_format = {}, \n source_img_filename = {}".format( - self.ovf_template_path, - self.source_img_path, self.source_img_location, - self.source_format, self.source_img_filename )) - - self.logger.info("Output parameters to Converter: \n output_format = {}, \n output_ovf_name = {}, \n"\ - "output_location ={} , \n output_path = {}, \n output_diskimage_name = {} , \n"\ - " output_diskimage_path = {} ".format(self.output_format, self.output_ovf_name, - self.output_location, self.output_path, - self.output_diskimage_name,self.output_diskimage_path )) - - - self.disk_capacity = 1 - self.disk_populated_size = 0 - - self.vm_name = self.output_ovf_name - self.memory = str(memory) if memory is not None else None - self.cpu = str(cpu) if cpu is not None else None - self.os_type=str(os_type).strip() if os_type else None - - if self.os_type: - self.osID , self.osType = self.__get_osType() - if self.osID is None or self.osType is None: - error_msg = "ERROR: Invalid input can not find OS type {} ".format(self.os_type) - self.__raise_exception(error_msg) - - self.disk_controller = str(disk_controller).strip() if disk_controller else None - - if self.disk_controller: - self.disk_controller_info = self.__get_diskcontroller() - - if not self.disk_controller_info: - error_msg = "ERROR: Invalid input can not find Disk Controller {} ".format(self.disk_controller) - self.__raise_exception(error_msg) - - if disk is not None: - #convert disk size from GB to bytes - self.disk_size = int(disk) * 1024 * 1024 * 1024 - else: - self.disk_size = None - - self.logger.info("Other input parameters to Converter: \n vm_name = {}, \n memory = {}, \n"\ - "disk_size ={} \n os type = {} \n disk controller = {}".format( - self.vm_name, self.memory, self.disk_size, self.os_type, self.disk_controller - )) - - #check access for read input location and write output location return none if no access - if not os.access(self.source_img_path, os.F_OK): - error_msg = "ERROR: Source image file {} not present".format(self.source_img_path) - self.__raise_exception(error_msg, exception_type="IO") - - elif not os.access(self.source_img_path, os.R_OK): - error_msg = "ERROR: Cannot read source image file {}".format(self.source_img_path) - self.__raise_exception(error_msg, exception_type="IO") - - if not os.access(self.output_location, os.W_OK): - error_msg = "ERROR: Not have write access to location {} to write output OVF ".format(self.source_img_path) - self.__raise_exception(error_msg, exception_type="IO") - - def __get_image_info(self): - """ - Private method to get information about source imager. - Args : None - Return : True on success else False - """ - try: - print("Getting source image information") - command = "qemu-img info \t " + self.source_img_path - output, error, returncode= self.__execute_command(command) - - if error or returncode: - self.logger.error("ERROR: Error occurred while getting information about source image : {} \n "\ - "return code : {} ".format(error, returncode)) - return False - - elif output: - self.logger.info("Get Image Info Output : {} \n ".format(output)) - split_output = output.split("\n") - for line in split_output: - line = line.strip() - if "virtual size" in line: - virtual_size_info = line.split(":")[1].split() - if len(virtual_size_info) == 3 and virtual_size_info[2].strip(")") == "bytes": - self.disk_capacity = int(virtual_size_info[1].strip("(")) - else: - self.disk_capacity = self.__convert_size(virtual_size_info[0]) - - elif "disk size" in line: - size = line.split(":")[1].split()[0] - self.disk_populated_size = self.__convert_size(size) - elif "file format" in line: - self.source_format = line.split(":")[1] - - self.logger.info("Updated source image virtual disk capacity : {} ,"\ - "Updated source image populated size: {}".format(self.disk_capacity, - self.disk_populated_size)) - return True - except Exception as exp: - error_msg = "ERROR: Error occurred while getting information about source image : {}".format(exp) - self.logger.error(error_msg) - print(error_msg) - return False - - def __convert_image(self): - """ - Private method to convert source disk image into .vmdk disk image. - Args : None - Return : True on success else False - """ - - print("Converting source disk image to .vmdk ") - - progress = CommandProgressbar() - progress.start_progressbar() - - command = "qemu-img convert -f "+ self.source_format +" -O " + self.output_diskimage_format + \ - " -o subformat=streamOptimized " + self.source_img_path + "\t" + self.output_diskimage_path - - output, error , returncode = self.__execute_command(command) - - progress.stop_progressbar() - - if error or returncode : - error_msg = "ERROR: Error occurred while converting source disk image into vmdk : {} \n "\ - "return code : {} ".format(error, returncode) - self.logger.error(error_msg) - print(error_msg) - return False - else: - if os.path.isfile(self.output_diskimage_path): - self.logger.info("Successfully converted source image {} into {} \n "\ - "return code : {} ".format(self.source_img_path, - self.output_diskimage_path, - returncode)) - result = self.__make_image_bootable() - if result: - self.logger.info("Made {} bootable".format(self.output_diskimage_path)) - return True - else: - self.logger.error("Cannot make {} bootable".format(self.output_diskimage_path)) - print("ERROR: Fail to convert source image into .vmdk") - return False - else: - self.logger.error("Converted vmdk disk file {} is not present \n ".format( - self.output_diskimage_path)) - print("Fail to convert source image into .vmdk") - return False - - def __make_image_bootable(self): - """ - Private method to make source disk image bootable. - Args : None - Return : True on success else False - """ - command = "printf '\x03' | dd conv=notrunc of="+ self.output_diskimage_path + "\t bs=1 seek=$((0x4))" - output, error, returncode = self.__execute_command(command) - - if error and returncode : - error_msg = "ERROR:Error occurred while making source disk image bootable : {} \n "\ - "return code : {} ".format(error, returncode) - self.logger.error(error_msg) - print(error_msg) - return False - else: - self.logger.info("Make Image Bootable Output : {} ".format(output)) - return True - - - def __edit_ovf_template(self): - """ - Private method to create new OVF file by editing OVF template - Args : None - Return : True on success else False - """ - try: - print("\nCreating OVF") - #Read OVF template file - OVF_tree = ET.parse(self.ovf_template_path) - root = OVF_tree.getroot() - - #Collect namespaces - nsmap = {k:v for k,v in root.nsmap.iteritems() if k} - nsmap["xmlns"]= "http://schemas.dmtf.org/ovf/envelope/1" - - #Edit OVF template - references = root.find('xmlns:References',nsmap) - if references is not None: - file_tag = references.find('xmlns:File', nsmap) - if file_tag is not None: - file_tag.attrib['{'+nsmap['ovf']+'}href'] = self.output_diskimage_name - - disksection = root.find('xmlns:DiskSection',nsmap) - if disksection is not None: - diak_tag = disksection.find('xmlns:Disk', nsmap) - if diak_tag is not None: - if self.disk_size and self.disk_size > self.disk_capacity: - self.disk_capacity = self.disk_size - - diak_tag.attrib['{'+nsmap['ovf']+'}capacity'] = str(self.disk_capacity) - diak_tag.attrib['{'+nsmap['ovf']+'}populatedSize'] = str(self.disk_populated_size) - - virtuasystem = root.find('xmlns:VirtualSystem',nsmap) - if virtuasystem is not None: - name_tag = virtuasystem.find('xmlns:Name', nsmap) - if name_tag is not None: - name_tag.text = self.vm_name - - if self.os_type is not None: - operatingSystemSection = virtuasystem.find('xmlns:OperatingSystemSection', nsmap) - if self.osID and self.osType: - operatingSystemSection.attrib['{'+nsmap['ovf']+'}id'] = self.osID - os_discription_tag = operatingSystemSection.find('xmlns:Description', nsmap) - os_discription_tag.text = self.osType - - virtualHardwareSection = virtuasystem.find('xmlns:VirtualHardwareSection', nsmap) - system = virtualHardwareSection.find('xmlns:System', nsmap) - virtualSystemIdentifier = system.find('vssd:VirtualSystemIdentifier', nsmap) - if virtualSystemIdentifier is not None: - virtualSystemIdentifier.text = self.vm_name - - if self.memory is not None or self.cpu is not None or self.disk_controller is not None: - for item in virtualHardwareSection.iterfind('xmlns:Item',nsmap): - description = item.find("rasd:Description",nsmap) - - if self.cpu is not None: - if description is not None and description.text == "Number of Virtual CPUs": - cpu_item = item.find("rasd:VirtualQuantity", nsmap) - name_item = item.find("rasd:ElementName", nsmap) - if cpu_item is not None: - cpu_item.text = self.cpu - name_item.text = self.cpu+" virtual CPU(s)" - - if self.memory is not None: - if description is not None and description.text == "Memory Size": - mem_item = item.find("rasd:VirtualQuantity", nsmap) - name_item = item.find("rasd:ElementName", nsmap) - if mem_item is not None: - mem_item.text = self.memory - name_item.text = self.memory + " MB of memory" - - if self.disk_controller is not None: - if description is not None and description.text == "SCSI Controller": - if self.disk_controller_info is not None: - name_item = item.find("rasd:ElementName", nsmap) - name_item.text = str(self.disk_controller_info["controllerName"])+"0" - - resource_type = item.find("rasd:ResourceType", nsmap) - resource_type.text = self.disk_controller_info["resourceType"] - - description.text = self.disk_controller_info["controllerName"] - resource_subtype = item.find("rasd:ResourceSubType", nsmap) - if self.disk_controller_info["controllerName"] == "IDE Controller": - #Remove resource subtype item - resource_subtype.getparent().remove(resource_subtype) - if "resourceSubType" in self.disk_controller_info: - resource_subtype.text = self.disk_controller_info["resourceSubType"] - - #Save output OVF - OVF_tree.write(self.output_path, xml_declaration=True,encoding='utf-8', - method="xml" ) - - if os.path.isfile(self.output_path): - logger.info("Successfully written output OVF at {}".format(self.output_path)) - print("Output OVF is at : {}".format(self.output_path)) - return self.output_path - else: - error_msg = "ERROR: Error occurred while creating OVF file" - print(error_msg) - return False - - except Exception as exp: - error_msg = "ERROR: Error occurred while editing OVF template : {}".format(exp) - self.logger.error(error_msg) - print(error_msg) - return False - - - def __convert_size(self,size): - """ - Private method to convert disk size from GB,MB to bytes. - Args : - size : disk size with prefix 'G' for GB and 'M' for MB - Return : disk size in bytes - """ - byte_size= 0 - try: - if not size: - self.logger.error("No size {} to convert in bytes".format(size)) - else: - size = str(size) - disk_size = float(size[:-1]) - input_type = size[-1].strip() - - self.logger.info("Disk size : {} , size type : {} ".format(disk_size,input_type)) - - if input_type == "G": - byte_size = disk_size * 1024 * 1024 *1024 - elif input_type == "M": - byte_size = disk_size * 1024 * 1024 - - self.logger.info("Disk size in bytes: {} ".format(byte_size)) - - return int(byte_size) - - except Exception as exp: - error_msg = "ERROR:Error occurred while converting disk size in bytes : {}".format(exp) - self.logger.error(error_msg) - print(error_msg) - return False - - def __get_osType(self): - """ - Private method to get OS ID and Type - Args : - None - Return : - osID : OS ID - osType: OS Type - """ - osID = None - osType = None - os_info = self.__read_yaml_file(OS_INFO_FILE_PATH) - try: - if self.os_type and os_info: - for os_id , os_type in os_info.iteritems(): - if self.os_type.lower() == os_type.lower(): - osID = os_id - osType = os_type - break - except Exception as exp: - error_msg = "ERROR:Error occurred while getting OS details : {}".format(exp) - self.logger.error(error_msg) - print(error_msg) - - return osID, osType - - - def __get_diskcontroller(self): - """ - Private method to get details of Disk Controller - Args : - None - Return : - disk_controller : dict with details of Disk Controller - """ - disk_controller = {} - scsi_subtype = None - if self.disk_controller.lower() in ["paravirtual", "lsilogic", "buslogic", "lsilogicsas"]: - scsi_subtype = self.disk_controller - self.disk_controller = "SCSI" - - disk_controller_info = self.__read_yaml_file(DISK_CONTROLLER_INFO_FILE_PATH) - try: - if self.disk_controller and disk_controller_info: - for key , value in disk_controller_info.iteritems(): - if self.disk_controller.lower() in key.lower(): - disk_controller['controllerName'] = key - disk_controller['resourceType'] = str(value["ResourceType"]) - resourceSubTypes = value["ResourceSubTypes"] if "ResourceSubTypes" in value else None - if key == "SATA Controller": - disk_controller["resourceSubType"] = resourceSubTypes[0] - elif key == "SCSI Controller": - if scsi_subtype: - if scsi_subtype.lower() == "paravirtual": - scsi_subtype = "VirtualSCSI" - for subtype in resourceSubTypes: - if scsi_subtype.lower() == subtype.lower(): - disk_controller["resourceSubType"] = subtype - break - else: - error_msg = "ERROR: Invalid inputs can not "\ - "find SCSI subtype {}".format(scsi_subtype) - self.__raise_exception(error_msg) - - except KeyError as exp: - error_msg = "ERROR:Error occurred while getting Disk Controller details : {}".format(exp) - self.logger.error(error_msg) - print(error_msg) - - return disk_controller - - def __read_yaml_file(self, file_path): - """ - Private method to execute command - Args : - command : command to execute - Return : - Dict of yaml data - """ - with open(file_path) as data_file: - data = yaml.load(data_file) - return data - - def __raise_exception(self, error_msg , exception_type="Generic"): - """ - Private method to execute command - Args : - command : command to execute - Return : - None - """ - if error_msg: - self.logger.debug(error_msg) - print(error_msg) - if exception_type == "Generic": - raise Exception(error_msg) - elif exception_type == "IO": - raise Exception(error_msg) - - def __execute_command(self, command): - """ - Private method to execute command - Args : - command : command to execute - Return : - stdout : output of command - stderr: error occurred while executing command if any - returncode : return code of command execution - """ - try: - self.logger.info("Execute command: {} ".format(command)) - - proc = subprocess.Popen(command , stdout = subprocess.PIPE, stdin = subprocess.PIPE, - stderr = subprocess.PIPE,shell=True) - stdout, stderr = proc.communicate() - returncode = proc.returncode - - except Exception as exp: - self.logger.error("Error {} occurred while executing command {} ".format(exp,command)) - - return stdout, stderr , returncode - - - def create_ovf(self): - """ - Method to convert source image into OVF - Args : None - Return : True on success else False - """ - #check output format - if self.source_format == self.output_format: - self.logger.info("Source format is OVF. No need to convert: {} ") - return self.source_img_path - - #Get source img properties - img_info = self.__get_image_info() - if img_info: - - #Create vmdk disk image - disk_img = self.__convert_image() - if disk_img: - - #Edit OVF tempalte - ovf_path = self.__edit_ovf_template() - return ovf_path - else: - self.logger.error("Error in getting image information cannot convert image") - raise Exception("Error in getting image information cannot convert image") - return False - diff --git a/osm_ro/vmware_utils/OVF_converter/format_converter/ovf_converter_cli.py b/osm_ro/vmware_utils/OVF_converter/format_converter/ovf_converter_cli.py deleted file mode 100644 index 209c05d9..00000000 --- a/osm_ro/vmware_utils/OVF_converter/format_converter/ovf_converter_cli.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - -import argparse -from converter import OVFConverter , get_version - -def execute_cli(): - - """ - Method to parse CLI arguments and execute commands accordingly - Args : None - Return : None - """ - parser = argparse.ArgumentParser(description='OVF converter to convert .qcow2 or raw image into OVF') - - parser.add_argument("-v","--version", action="version", version=str(get_version()), - help="shows version of OVF Converter tool") - - parser.add_argument("path", action="store", - help=" absolute path to source image which will get convert into ovf") - - parser.add_argument("-o", "--output_location", action="store", - help="location where created OVF will be kept. This location "\ - "should have write access. If not given file will get "\ - "created at source location (optional)") - - parser.add_argument("-n","--ovf_name", action="store", - help="name of output ovf file. If not given source image name will "\ - " be used (optional)") - - parser.add_argument("-m","--memory", action="store", - help="required memory for VM in MB (default 1 GB)(optional)") - - parser.add_argument("-c","--cpu", action="store", - help="required number of virtual cpus for VM (default 1 cpu) (optional)") - - parser.add_argument("-d","--disk", action="store", - help="required size of disk for VM in GB "\ - "(default as in source disk img) (optional)") - - parser.add_argument("-s","--osType", action="store", - help="required operating system type as specified "\ - "in user document (default os type other 32 bit) (optional)") - - parser.add_argument("-dc","--disk_Controller", action="store", - help="required disk controller type "\ - " (default controller SCSI with lsilogicsas) "\ - "(SATA, IDE, Paravirtual, Buslogic, Lsilogic, Lsilogicsas) (optional)") - - args = parser.parse_args() - - if args.path: - con = OVFConverter(args.path, - output_location=args.output_location, - output_ovf_name=args.ovf_name, - memory=args.memory, - cpu=args.cpu, - disk=args.disk, - os_type=args.osType, - disk_controller=args.disk_Controller, - ) - - print("#### Start OVF conversion ####") - con.create_ovf() - print("#### Completed OVF conversion ####") - - -if __name__ == "__main__": - execute_cli() - diff --git a/osm_ro/vmware_utils/OVF_converter/install.sh b/osm_ro/vmware_utils/OVF_converter/install.sh deleted file mode 100755 index 7b184c80..00000000 --- a/osm_ro/vmware_utils/OVF_converter/install.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash - -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - -echo ' - ################################################################# - ##### Installing Require Packages ##### - #################################################################' - -# Paths to copy application files -Install_dir="/usr/local/bin" -App_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -App_CLI_path="${App_dir}/format_converter/ovf_converter_cli.py" -Install_CLI_path="${Install_dir}/OVF_converter/format_converter/ovf_converter_cli.py" -Logs_Folder="${Install_dir}/OVF_converter/logs" -Log_Path="${Install_dir}/OVF_converter/logs/ovf_converter.log" - -#Function to install packages using apt-get -function install_packages(){ - [ -x /usr/bin/apt-get ] && apt-get install -y $* - - #check properly installed - for PACKAGE in $* - do - PACKAGE_INSTALLED="no" - [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes" - if [ "$PACKAGE_INSTALLED" = "no" ] - then - echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" >&2 - exit 1 - fi - done - } - -apt-get update # To get the latest package lists -install_packages "libxml2-dev libxslt-dev python-dev python-pip python-lxml python-yaml" -install_packages "qemu-utils" - -#apt-get install -y - -#Move OVF Converter to usr/bin -cp -R "${App_dir}" "${Install_dir}" - -#Create logs folder and file -mkdir "${Logs_Folder}" -touch "${Log_Path}" - -#Change permission -chmod -R 777 $Install_CLI_path -chmod -R 777 $Log_Path - -touch "${Install_dir}/ovf_converter" -echo "#!/bin/sh" > "${Install_dir}/ovf_converter" -echo "python ${Install_CLI_path} \"\$@\"" >> "${Install_dir}/ovf_converter" -chmod a+x "${Install_dir}/ovf_converter" - -echo ' - ################################################################# - ##### Done ##### - #################################################################' diff --git a/osm_ro/vmware_utils/OVF_converter/ovf_template/template.xml b/osm_ro/vmware_utils/OVF_converter/ovf_template/template.xml deleted file mode 100644 index 5cbb3280..00000000 --- a/osm_ro/vmware_utils/OVF_converter/ovf_template/template.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - Virtual disk information - - - - - List of logical networks used in the package - - - - A virtual machine - Virtual machine name - - - The kind of installed guest operating system - Other (32-bit) - - - - Virtual hardware requirements - - Virtual Hardware Family - 0 - Test1 - vmx-7 - - - - hertz * 10^6 - Number of Virtual CPUs - 1 virtual CPU(s) - 1 - 3 - 1 - - - byte * 2^20 - Memory Size - 1GB of memory - 2 - 4 - 1024 - - - 0 - SCSI Controller - scsiController0 - 3 - lsilogicsas - 6 - - - 0 - disk0 - ovf:/disk/vmdisk1 - 4 - 3 - 17 - - - false - video - 5 - 24 - - - false - vmci - 6 - vmware.vmci - 1 - - - - - - - - - - - \ No newline at end of file diff --git a/osm_ro/vmware_utils/OVF_converter/readme.txt b/osm_ro/vmware_utils/OVF_converter/readme.txt deleted file mode 100644 index 0e6117b9..00000000 --- a/osm_ro/vmware_utils/OVF_converter/readme.txt +++ /dev/null @@ -1,181 +0,0 @@ -## -# Copyright 2016-2017 VMware Inc. -# This file is part of ETSI OSM -# All Rights Reserved. -# -# 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. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact: osslegalrouting@vmware.com -## - -This README file explains how to use OVF Converter Tool to generate OVF file from .qcow2, .img (raw) disk images. - -CONTENTS OF THIS FILE -===================== -This readme file contains the following sections: - -o Introduction -o Tool Requirements -o Installation -o Usage -o Trouble shooting -o Release History - - -Introduction -================== -OVF Converter Tool is a Command Line Interface (CLI) basically designed to generate OVF files from disk image such as .qcow2, and .img (raw format) which are other than .vmdk. -Given a path to .qcow2 image this tool can generate .vmdk and .ovf files. -User can optionally specify name and location of ovf file. Also, one can use command line options to give disk size (GB), memory (MB), number of cpus, OS type, disk controller required for VM which will get deployed using generated OVF. -Generated OVF file can be used to deploy VM in Vmware vSphere or vCloud Director. - -Note- Currently this tool supports only Ubuntu platform. - - -Tool Requirements -================== - -This tool requires the following software package: -o apt-get package manager -o qemu-utils -o python 2.7 -o python-lxml -o libxml2-dev -o libxslt-dev -o python-dev -o python-pip - -Install.sh script in this folder will install all of these -software packages. - - -Installation -================== -User needs root privileges to install OVF Generator Tool. -Follow below setups for installation of OVF Converter Tool. -1. Make install.sh script in this folder executable by running below command - chmod a+x install.sh -2. Run install.sh script as: - ./install.sh - - Sample output - - ################################################################# - ##### Installing Require Packages ##### - ################################################################# - Hit:1 http://us.archive.ubuntu.com/ubuntu xenial InRelease - Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB] - Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] - Get:4 http://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB] - Fetched 306 kB in 1s (286 kB/s) - Reading package lists... Done - Reading package lists... Done - Building dependency tree - Reading state information... Done - Note, selecting 'libxslt1-dev' instead of 'libxslt-dev' - libxslt1-dev is already the newest version (1.1.28-2.1). - python-dev is already the newest version (2.7.11-1). - python-lxml is already the newest version (3.5.0-1build1). - libxml2-dev is already the newest version (2.9.3+dfsg1-1ubuntu0.1). - - t version (1:2.5+dfsg-5ubuntu10.6). - 0 upgraded, 0 newly installed, 0 to remove and 72 not upgraded. - - ################################################################# - ##### Done ##### - ################################################################# - root@ubuntu:/home/vmware/OVF_converter# - root@ubuntu:/home/vmware/OVF_converter# - -3. Now tool is installed at /usr/local/bin and available for all users -4. User can access commands of OVF Generator Tool as: - ovf_converter path [output location] [ovf name][memory][cpu][disk][ostype][disk_controller] - - -Usage -=================== -o Get version of tool as: - - Command - ovf_converter -v - Sample output - - root@ubuntu:/home/vmware/OVF_converter# ovf_converter -v - 1.0 - Initial Realse - root@ubuntu:/home/vmware/OVF_converter# - -o See all command line options of tool as: - Command - ovf_converter -h - Sample output - - root@ubuntu:/home/vmware/OVF_converter# - root@ubuntu:/home/vmware/OVF_converter# ovf_converter -h - Usage: ovf_converter_cli.py [-h] [-v] [-o OUTPUT_LOCATION] [-n OVF_NAME] - [-m MEMORY] [-c CPU] [-d DISK] [-s OSTYPE] - [-dc DISK_CONTROLLER] - path - - OVF converter to convert .qcow2 or raw image into OVF - - positional arguments: - path absolute path to source image which will get convert - into ovf - - optional arguments: - -h, --help show this help message and exit - -v, --version shows version of OVF Converter tool - -o OUTPUT_LOCATION, --output_location OUTPUT_LOCATION - location where created OVF will be kept. This location - should have write access. If not given file will get - created at source location (optional) - -n OVF_NAME, --ovf_name OVF_NAME - name of output ovf file. If not given source image - name will be used (optional) - -m MEMORY, --memory MEMORY - required memory for VM in MB (default 1 GB)(optional) - -c CPU, --cpu CPU required number of virtual cpus for VM (default 1 cpu) - (optional) - -d DISK, --disk DISK required size of disk for VM in GB (default as - in source disk img) (optional) - -s OSTYPE, --osType OSTYPE - required operating system type as specified in user - document (default os type other 32 bit) (optional) - -dc DISK_CONTROLLER, --disk_Controller DISK_CONTROLLER - required disk controller type (default controller SCSI - with lsilogicsas) (SATA, IDE, Paravirtual, Buslogic, - lsilogic, lsilogicsas) (optional) - - -o Create OVF file from qcow2 or raw disk image as: - Command - ovf_converter /home/vmware/centos_ovf/CentOS-7-x86_64-GenericCloud-1503.qcow2 -n centos_qcow2.ovf -m 2048 -c 4 -d 10 -s "Centos 32-bit" -dc "SATA" - Sample output - - root@ubuntu:/home/vmware/OVF_converter# ovf_converter /home/vmware/centos_ovf/CentOS-7-x86_64-GenericCloud-1503.qcow2 -n centos_qcow2.ovf -m 2048 -c 4 -d 10 - #### Start OVF conversion #### - Getting source image information - Converting source disk image to .vmdk - ..................................................... - Creating OVF - Output OVF is at: /home/vmware/centos_ovf/centos_qcow2.ovf - #### Completed OVF conversion #### - - -Trouble shooting -================== -After installation of tool logs will get created at /usr/local/bin/OVF_converter/logs/ovf_converter.log file. -User can use these logs for debugging or trouble shooting. - - -Release History -=============== - -Version 1.0 -------------- - -Initial release