def generate_definition(self, context, address, port): """ Generates the tempalte definition object """ try: definition = TemplateDefinition.builder(context.getApiContext()) \ .name(self.__values['name']) \ .description(self.__values['description']) \ .url("http://%s:%s/ovf.ovf" % (address, port)) \ .loginUser(self.__values['user']) \ .loginPassword(self.__values['password']) \ .osType(OSType.fromCode(self.__values['ostype'])) \ .diskFormatType(self.__values['diskformat']) \ .ethernetDriverType(EthernetDriverType.valueOf( self.__values['ethernetdriver'])) \ .diskFileSize(self.__values['diskfilesize']) \ .osVersion(self.__values['osversion']) \ .productName(self.__values['name']) \ .productUrl("") \ .productVersion("") \ .productVendor("") \ .build() if self.__values['diskcontroller'] == 5: definition.setDiskControllerType(DiskControllerType.IDE) else: definition.setDiskControllerType(DiskControllerType.SCSI) except KeyError, ex: print "Missing configuration value: %s" % ex raise ex
def _parse_template_values(self): """ Parses the special template values """ disk_info = self._read_disk_file() file_size = os.path.getsize(self.__disk) file_name, extension = os.path.splitext(self.__disk) virtual_size = self.__get_hd_in_bytes(disk_info) disk_format_type = self.__get_disk_format_type(disk_info, file_size, virtual_size, extension) diskcontroller = self.__values['diskcontroller'] self.__values['diskcontroller'] = 5 if diskcontroller == 'IDE' else 6 self.__values['diskfilesize'] = file_size self.__values['hdinbytes'] = virtual_size self.__values['diskformat'] = disk_format_type.name() self.__values['diskformaturl'] = disk_format_type.getUri() self.__values['diskfilepath'] = os.path.basename(self.__disk) ostype = self.__values['ostype'] self.__values['ostype'] = OSType.valueOf(ostype).getCode()