def updateHardwareProfile(self, hardwareProfileId): """ Handle PUT to "hardwareprofiles/:(hardwareProfileId)" """ response = None try: postdata = cherrypy.request.json hw_profile = HardwareProfile.getFromDict(postdata) hw_profile.setId(hardwareProfileId) hp_mgr = HardwareProfileManager() hp_mgr.updateHardwareProfile(cherrypy.request.db, hw_profile) except HardwareProfileNotFound as ex: self.handleException(ex) code = self.getTortugaStatusCode(ex) response = self.notFoundErrorResponse(str(ex), code) except Exception as ex: self._logger.exception( 'hardware profile WS API updateHardwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def updateHardwareProfile(self, hardwareProfileId): ''' Handle PUT to "hardwareprofiles/:(hardwareProfileId)" ''' response = None try: postdata = cherrypy.request.json hwProfile = HardwareProfile.getFromDict(postdata) # Make sure the id is synced hwProfile.setId(hardwareProfileId) hpMgr = HardwareProfileManager() hpMgr.updateHardwareProfile(hwProfile) except HardwareProfileNotFound as ex: self.handleException(ex) code = self.getTortugaStatusCode(ex) response = self.notFoundErrorResponse(str(ex), code) except Exception as ex: self.getLogger().exception( 'hardware profile WS API updateHardwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def copyHardwareProfile(self, srcHardwareProfileName): response = None postdata = cherrypy.request.json try: if 'dstHardwareProfileName' not in postdata: raise HardwareProfileNotFound( 'Missing destination hardware profile parameter') dstHardwareProfileName = postdata['dstHardwareProfileName'] hpMgr = HardwareProfileManager() hpMgr.copyHardwareProfile(srcHardwareProfileName, dstHardwareProfileName) except HardwareProfileNotFound as ex: self.handleException(ex) code = self.getTortugaStatusCode(ex) response = self.notFoundErrorResponse(str(ex), code) except Exception as ex: self.getLogger().exception( 'hardware profile WS API copyHardwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def getHardwareProfiles(self, **kwargs): tagspec = [] if 'tag' in kwargs and kwargs['tag']: tagspec.extend(parse_tag_query_string(kwargs['tag'])) try: if 'name' in kwargs and kwargs['name']: options = make_options_from_query_string( kwargs['include'] if 'include' in kwargs else None, ['resourceadapter']) hardwareProfiles = TortugaObjectList([ HardwareProfileManager().getHardwareProfile( cherrypy.request.db, kwargs['name'], optionDict=options) ]) else: hardwareProfiles = \ HardwareProfileManager().getHardwareProfileList( cherrypy.request.db, tags=tagspec) response = { 'hardwareprofiles': hardwareProfiles.getCleanDict(), } except Exception as ex: # pylint: disable=broad-except self.getLogger().exception( 'hardware profile WS API getHardwareProfiles() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def __checkUser(self, hardwareProfileName): hpMgr = HardwareProfileManager() admins = hpMgr.getHardwareProfile(hardwareProfileName, { 'admins': True, }).getAdmins() self.getLogger().debug('Checking %s against %s' % (cherrypy.request.login, admins)) for admin in admins: if admin.getUsername() == cherrypy.request.login: return raise UserNotAuthorized('User %s is not a manager of %s' % (cherrypy.request.login, hardwareProfileName))
def createHardwareProfile(self): """ Create hardware profile """ response = None postdata = cherrypy.request.json hwProfileDict = postdata['hardwareProfile'] settingsDict = postdata['settingsDict'] \ if 'settingsDict' in postdata else {} if 'osInfo' in settingsDict and settingsDict['osInfo']: settingsDict['osInfo'] = OsInfo.getFromDict(settingsDict['osInfo']) hwProfile = HardwareProfile.getFromDict(hwProfileDict) try: HardwareProfileManager().createHardwareProfile( cherrypy.request.db, hwProfile, settingsDict=settingsDict) except Exception as ex: self.getLogger().exception( 'hardware profile WS API createHardwareProfile() failed') self.getLogger().exception(ex) self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def getNodeList(self, hardware_profile_name): try: HardwareProfileManager().getNodeList(hardware_profile_name) except TortugaException as exc: raise except Exception as exc: self.getLogger().exception('%s' % (exc)) raise TortugaException(exception=exc)
def getNodeList(self, session: Session, hardware_profile_name): try: HardwareProfileManager().getNodeList(session, hardware_profile_name) except TortugaException: raise except Exception as exc: self._logger.exception(str(exc)) raise TortugaException(exception=exc)
def deleteAdmin(self, hardwareProfileName, adminUsername): response = None hpMgr = HardwareProfileManager() try: self.__checkUser(hardwareProfileName) hpMgr.deleteAdmin(hardwareProfileName, adminUsername) except Exception as ex: self.getLogger().exception( 'hardware profile WS API deleteAdmin() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def getProvisioningNicForNetwork(self, session: Session, network, netmask): try: HardwareProfileManager().getProvisioningNicForNetwork( session, network, netmask) except TortugaException: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def addAdmin(self, hardwareProfileName, adminUsername): response = None hpMgr = HardwareProfileManager() try: self.__checkUser(hardwareProfileName) hpMgr.addAdmin( cherrypy.request.db, hardwareProfileName, adminUsername) except Exception as ex: self._logger.exception( 'hardware profile WS API addAdmin() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def copyHardwareProfile(self, session: Session, srcHardwareProfileName, dstHardwareProfileName): try: return HardwareProfileManager().copyHardwareProfile( session, srcHardwareProfileName, dstHardwareProfileName) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def setIdleSoftwareProfile(self, hardware_profile_name, software_profile_name=None): try: HardwareProfileManager().\ setIdleSoftwareProfile(hardware_profile_name, software_profile_name) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def copyHardwareProfile(self, session: Session, srcHardwareProfileName, dstHardwareProfileName): try: HardwareProfileManager().copyHardwareProfile( session, srcHardwareProfileName, dstHardwareProfileName) except TortugaException: raise except Exception as ex: self._logger.exception(str(ex)) raise TortugaException(exception=ex)
def getHardwareProfiles(self, **kwargs): tagspec = [] if 'tag' in kwargs and kwargs['tag']: tagspec.extend(parse_tag_query_string(kwargs['tag'])) try: hardwareProfiles = HardwareProfileManager().\ getHardwareProfileList(tags=tagspec) response = { 'hardwareprofiles': hardwareProfiles.getCleanDict(), } except Exception as ex: self.getLogger().exception( 'hardware profile WS API getHardwareProfiles() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def copyHardwareProfile(self, srcHardwareProfileName, dstHardwareProfileName): response = None try: hpMgr = HardwareProfileManager() hpMgr.copyHardwareProfile( cherrypy.request.db, srcHardwareProfileName, dstHardwareProfileName) except HardwareProfileNotFound as ex: self.handleException(ex) code = self.getTortugaStatusCode(ex) response = self.notFoundErrorResponse(str(ex), code) except Exception as ex: self._logger.exception( 'hardware profile WS API copyHardwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def getHypervisorNodes(self, hardwareProfileName): # self.getLogger().debug( # 'getHypervisorNodes: hardwareProfileName [%s]' % ( # hardwareProfileName)) hpMgr = HardwareProfileManager() try: nodes = hpMgr.getHypervisorNodes(hardwareProfileName) # self.getLogger().debug('Number of nodes: %s' % len(nodes)) response = nodes.getCleanDict() except Exception as ex: self.getLogger().exception( 'hardware profile WS API getHypervisorNodes() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def setProvisioningNic(self, session: Session, hardwareProfileName, nicId): """ Mark nic as a provisioning interface in the specified hardware profile Throws: TortugaException HardwareProfileNotFound """ try: HardwareProfileManager().setProvisioningNic( session, hardwareProfileName, nicId) except TortugaException: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def createHardwareProfile(self, hwProfileSpec, settingsDict=None): """ Create hardware profile from template Returns: None Throws: TortugaException """ try: HardwareProfileManager().createHardwareProfile( hwProfileSpec, settingsDict=settingsDict or {}) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def deleteHardwareProfile(self, session: Session, hardwareProfileName): """ Delete hardware profile Returns: N/A Throws: HardwareProfileNotFound TortugaException """ try: HardwareProfileManager().deleteHardwareProfile( session, hardwareProfileName) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def getHardwareProfileById(self, session: Session, id_, optionDict=None): """ Get node group information Returns: hardwareProfile Throws: HardwareProfileNotFound TortugaException """ try: return HardwareProfileManager().getHardwareProfileById( session, id_, optionDict or {}) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def getHypervisorNodes(self, hardwareProfileName): """ Get list of hypervisors for a given hardare profile. Returns: [node] Throws: HardwareProfileNotFound TortugaException """ try: return HardwareProfileManager().\ getHypervisorNodes(hardwareProfileName) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def addAdmin(self, session: Session, hardwareProfileName, adminUsername): """ Add an admin as an authorized user. Returns: None Throws: TortugaException AdminNotFound HardwareProfileNotFound """ try: HardwareProfileManager().addAdmin(session, hardwareProfileName, adminUsername) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def deleteAdmin(self, hardwareProfileName, adminUsername): """ Remove an admin as an authorized user. Returns: None Throws: TortugaException AdminNotFound HardwareProfileNotFound """ try: HardwareProfileManager().\ deleteAdmin(hardwareProfileName, adminUsername) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def getHardwareProfileList(self, optionDict=None, tags=None): """ Get list of hardware profiles Returns: [hardwareProfile] Throws: HardwareProfileNotFound TortugaException """ try: return HardwareProfileManager().\ getHardwareProfileList(optionDict=optionDict, tags=tags) except TortugaException: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def deleteHardwareProfile(self, hardwareProfileName): """Delete hardware profile""" response = None try: HardwareProfileManager().deleteHardwareProfile(hardwareProfileName) except HardwareProfileNotFound as ex: self.handleException(ex) code = self.getTortugaStatusCode(ex) response = self.notFoundErrorResponse(str(ex), code) except Exception as ex: self.getLogger().exception( 'hardware profile WS API deleteHardwareProfile() failed') self.handleException(ex) response = self.errorResponse(str(ex)) return self.formatResponse(response)
def createHardwareProfile(self, session: Session, hwProfileSpec: HardwareProfile, settingsDict: Optional[dict] = None) \ -> None: """ Create hardware profile from template Returns: None Throws: TortugaException """ try: HardwareProfileManager().createHardwareProfile( session, hwProfileSpec, settingsDict=settingsDict) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def deleteAdmin(self, session: Session, hardwareProfileName, adminUsername): """ Remove an admin as an authorized user. Returns: None Throws: TortugaException AdminNotFound HardwareProfileNotFound """ try: HardwareProfileManager().deleteAdmin(session, hardwareProfileName, adminUsername) except TortugaException as ex: raise except Exception as ex: self._logger.exception(str(ex)) raise TortugaException(exception=ex)
def updateHardwareProfile(self, session: Session, hardwareProfileObject): """ Update a hardware profile in the database that matches the passed in hardware profile object. The ID is used as the primary matching criteria. Returns: None Throws: TortugaException HardwareProfileNotFound """ try: HardwareProfileManager().updateHardwareProfile( session, hardwareProfileObject) except TortugaException as ex: raise except Exception as ex: self.getLogger().exception('%s' % ex) raise TortugaException(exception=ex)
def getHardwareProfile(self, session: Session, hardwareProfileName, optionDict=None): """ Get node group information Returns: hardwareProfile Throws: HardwareProfileNotFound TortugaException """ try: return HardwareProfileManager().getHardwareProfile( session, hardwareProfileName, optionDict or {}) except TortugaException as ex: raise except Exception as ex: self._logger.exception(str(ex)) raise TortugaException(exception=ex)