Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
 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)
Ejemplo n.º 13
0
 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)
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
    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)
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
    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)
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
    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)
Ejemplo n.º 28
0
    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)
Ejemplo n.º 29
0
    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)
Ejemplo n.º 30
0
    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)