def getSoftwareProfileById(self, swProfileId, optionDict=None): """ Get software profile information Returns: softwareProfile Throws: SoftwareProfileNotFound TortugaException """ url = 'v1/softwareProfiles/id/%s' % (swProfileId) postdata = json.dumps(optionDict or {}) try: _, responseDict = self.sendSessionRequest(url, data=postdata) return SoftwareProfile.getFromDict( responseDict.get('softwareprofile')) # except HttpErrorException as exc: except urllib.error.HTTPError as exc: if exc.code == 404: raise SoftwareProfileNotFound( 'Software profile ID [%s] not found' % (swProfileId)) except TortugaException: raise except Exception as ex: raise TortugaException(exception=ex)
def getSoftwareProfile(self, softwareProfileName, optionDict=None): """ Get software profile information Returns: softwareProfile Throws: SoftwareProfileNotFound TortugaException """ url = 'v1/softwareProfiles/%s' % (softwareProfileName) postdata = json.dumps({'optionDict': optionDict or {}}) try: _, responseDict = self.sendSessionRequest( url, method='POST', data=postdata) return SoftwareProfile.getFromDict( responseDict.get('softwareprofile')) except TortugaException as ex: raise except Exception as ex: raise TortugaException(exception=ex)
def updateSoftwareProfile(self, softwareProfileId): ''' Handle put to softwareprofiles/:(softwareProfileId) ''' response = None try: postdata = cherrypy.request.json swProfile = SoftwareProfile.getFromDict(postdata) # Make sure the id is synced swProfile.setId(softwareProfileId) self._softwareProfileManager.updateSoftwareProfile(swProfile) except Exception as ex: self.getLogger().exception( 'software profile WS API updateSoftwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def createSoftwareProfile(self): """Create software profile""" response = None postdata = cherrypy.request.json if 'softwareProfile' not in postdata: raise Exception('Malformed request') settingsDict = postdata['settingsDict'] \ if 'settingsDict' in postdata else {} self.getLogger().debug( '[%s] createSoftwareProfile(): softwareProfile=[%s]' % ( self.__module__, postdata['softwareProfile'])) swProfileSpec = SoftwareProfile.getFromDict( postdata['softwareProfile']) try: SoftwareProfileApi().createSoftwareProfile( swProfileSpec, settingsDict=settingsDict) except Exception as ex: self.getLogger().exception( 'software profile WS API createSoftwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def getSoftwareProfileById(self, swProfileId, optionDict: Optional[Dict[str, bool]] = None): """ Get software profile information Returns: softwareProfile Throws: SoftwareProfileNotFound TortugaException """ url = 'softwareprofiles/%d' % (swProfileId) if optionDict: for key, value in optionDict.items(): if not value: continue url += '&include={}'.format(key) try: responseDict = self.get(url) return SoftwareProfile.getFromDict( responseDict.get('softwareprofile')) except urllib.error.HTTPError as exc: if exc.code == 404: raise SoftwareProfileNotFound( 'Software profile ID [%s] not found' % (swProfileId)) except TortugaException: raise except Exception as ex: raise TortugaException(exception=ex)
def runCommand(self): self.parseArgs(_('Create software profile')) if self.getArgs().name and self.getArgs().deprecated_name: self.getParser().error( 'argument name: not allowed with argument --name') name = self.getArgs().name \ if self.getArgs().name else self.getArgs().deprecated_name # load template if specified with '--template', otherwise build # template tmpl_dict = {} if not self.getArgs().jsonTemplatePath else \ self.load_software_profile_template( self.getArgs().jsonTemplatePath) if name: tmpl_dict['name'] = name if self.getArgs().description: tmpl_dict['description'] = self.getArgs().description if self.getArgs().profileType: tmpl_dict['type'] = self.getArgs().profileType elif 'type' not in tmpl_dict: tmpl_dict['type'] = 'compute' if self.getArgs().tags: tmpl_dict['tags'] = parse_tags(self.getArgs().tags) if hasattr(self.getArgs(), 'osInfo'): tmpl_dict['os'] = { 'name': getattr(self.getArgs(), 'osInfo').getName(), 'version': getattr(self.getArgs(), 'osInfo').getVersion(), 'arch': getattr(self.getArgs(), 'osInfo').getArch(), } if self.getArgs().dataRoot: tmpl_dict['dataRoot'] = self.getArgs().dataRoot if self.getArgs().dataRsync: tmpl_dict['dataRsync'] = self.getArgs().dataRsync sw_profile_spec = SoftwareProfile.getFromDict(tmpl_dict) api = SoftwareProfileWsApi(username=self.getUsername(), password=self.getPassword(), baseurl=self.getUrl(), verify=self._verify) # Populate 'settings_dict' from command-line arguments settings_dict = { 'bOsMediaRequired': self.getArgs().bOsMediaRequired, 'unmanagedProfile': self.getArgs().unmanaged, } api.createSoftwareProfile(sw_profile_spec, settings_dict)
def updateSoftwareProfile(self, softwareProfileObject): """ Update the given Software Profile by calling WS API """ url = 'softwareprofiles/%s' % (softwareProfileObject.getId()) postdata = softwareProfileObject.getCleanDict() test = SoftwareProfile.getFromDict(postdata) try: self.put(url, postdata) except Exception as ex: raise TortugaException(exception=ex)