Пример #1
0
    def newScaleOut(self, cores, ram):
        if not cores > 0:
            raise InvalidParameterException('Cores should be higher than 0')
        elif not ram > 0:
            raise InvalidParameterException('Ram should be higher than 0')

        return ScaleOut(cores, ram)
Пример #2
0
    def newDeployVms(self, names, profile, cores, ram):
        """ Generates a new DeployVms command

        :param names: A list of names
        :type names: list

        :param profile: the vm profile to be used
        :type profile: string

        :param cores: the number of cores per vm
        :type cores: int

        :param ram: the amount of ram per vm in GiB
        :type ram: int

        :returns: A DeployVms command object
        :rtype: DeployVms
        """

        if not isinstance(names, list) or len(names) <= 0:
            raise InvalidParameterException('names is inavlid')

        if not isinstance(cores, int) or cores <= 0:
            raise InvalidParameterException('cores is inavlid')

        if not isinstance(ram, int) or ram <= 0:
            raise InvalidParameterException('ram is invalid')

        if len(profile) <= 0:
            raise InvalidParameterException('profile is invalid')

        return DeployVms(names, profile, cores, ram)
Пример #3
0
    def newJobFinishedEvent(self, job_id, ret, retcode):
        if not isinstance(job_id, basestring) or len(job_id.strip()) == 0:
            raise InvalidParameterException('job_id is invalid')
        elif not isinstance(ret, basestring) or len(ret.strip()) == 0:
            raise InvalidParameterException('ret is invalid')
        elif not isinstance(retcode, int):
            raise InvalidParameterException('retcode is invalid')

        return JobFinished(job_id, ret, retcode)
Пример #4
0
    def newVmNewEvent(self, job_id, cores, ram):
        if not isinstance(job_id, basestring) or len(job_id.strip()) == 0:
            raise InvalidParameterException('job_id not valid')
        elif not isinstance(cores, int) or cores <= 0:
            raise InvalidParameterException('cores not valid')
        elif not isinstance(ram, int) or cores <= 0:
            raise InvalidParameterException('ram not valid')

        return VmNew(job_id, cores, ram)
Пример #5
0
    def new_add_secret(self, key, value):
        if len(key) == 0:
            raise InvalidParameterException('key len must be > 0')
        elif not isinstance(key, basestring):
            raise InvalidParameterException('key must be string type')

        if len(value) == 0:
            raise InvalidParameterException('value len must be > 0')
        elif not isinstance(value, basestring):
            raise InvalidParameterException('value must be string type')

        return AddSecret(key, value)
Пример #6
0
    def newIsValidUserQuery(self, username, password):
        """ Generates a new IsValidUser query

        :returns: An IsValidUser query object
        :rtype: IsValidUser
        """
        if username == None or len(username) == 0 or len(username.strip()) == 0:
            raise InvalidParameterException('Username is invalid')

        if password == None or len(password) == 0:
            raise InvalidParameterException('Password is invalid')

        return IsValidUser(username, password)
Пример #7
0
    def newRequestVms(self, states):
        """ Generates a new RequestVms query
        :returns: A RequestVms query object
        :rtype: RequestVmsByState
        """
        if not isinstance(states, list):
            raise InvalidParameterException("states invalid")

        for state in states:
            if state not in VmState:
                raise InvalidParameterException(
                    "{} is not a valid VmState".format(state))

        return RequestVmsByState(states)
Пример #8
0
    def newStartJobOnVm(self, vm_id, job_id):
        """ Generates a new StartJobOnVm command

        :param vm_id: the node name
        :type vm_id: string
        :param job_id: the taskid to be started
        :type job_id: string

        :returns: A StartJobOnVm command object
        :rtype: StartJobOnVm
        """
        if not len(vm_id) > 0:
            raise InvalidParameterException('node is invalid')
        elif not len(job_id) > 0:
            raise InvalidParameterException('taskid is invalid')

        return StartJobOnVm(vm_id=vm_id, job_id=job_id)
Пример #9
0
    def newLoadConfig(self, environment):
        """ generates a new loadconfig command

        :param environment: the environment that should be loaded
        :type environment: string

        :returns: a loadconfig command object
        :rtype: loadconfig
        """
        if not len(environment) > 0:
            raise InvalidParameterException('environment is invalid')
        return LoadConfig(environment)
Пример #10
0
    def newVmCreated(self, vm_id):
        """ Generates a new VmCreated command

        :param vm_id: An identifier token for the job
        :type vm_id: string

        :returns: A VmCreated command object
        :rtype: VmCreated
        """
        if not isinstance(vm_id, basestring) or len(vm_id.strip()) == 0:
            raise InvalidParameterException('vm_id is invalid')
        return VmCreated(vm_id)
Пример #11
0
    def newRetrieveGrant(self, client_id, code):
        """ Generates a new RetrieveGrant query

        :param client_id: the client id
        :type client_id: string

        :param code: the code
        :type code: string

        :returns: A RetrieveGrant query object
        :rtype: RetrieveGrant
        """
        client_id = client_id.strip()
        if not len(client_id) > 0:
            raise InvalidParameterException('Client id is invalid'.format(cmd))

        code = code.strip()
        if not len(code) > 0:
            raise InvalidParameterException('Code is invalid'.format(cmd))

        return RetrieveGrant(client_id=client_id, code=code)
Пример #12
0
    def newDestroyVms(self, names):
        """ Generates a new DestroyVm command

        :param name: The name of the VM to be destroyed
        :type name: string

        :returns: A DestroyVm command object
        :rtype: DestroyVm
        """
        if not isinstance(names, list) or len(names) <= 0:
            raise InvalidParameterException('names is invalid')

        return DestroyVms(names=names)
Пример #13
0
    def newVmNew(self, vm_id, cores, ram):
        """ Generates a new VmNew command

        :param vm_id: An identifier token for the job
        :type vm_id: string

        :param cores: the amount of cores assigned to the vm
        :type cores: int

        :param ram: the amount of ram in GiB assigned to the vm
        :type ram: int

        :returns: A VmNew command object
        :rtype: VmNew
        """
        if not isinstance(vm_id, basestring) or len(vm_id.strip()) == 0:
            raise InvalidParameterException('vm_id is invalid')
        elif not isinstance(cores, int) or cores <= 0:
            raise InvalidParameterException('cores is invalid')
        elif not isinstance(ram, int) or ram <= 0:
            raise InvalidParameterException('ram is invalid')

        return VmNew(vm_id, cores, ram)
Пример #14
0
    def newJobFinished(self, job_id, ret, retcode):
        """ Generates a new JobFinished command

        :param job_id: An identifier token for the job
        :type job_id: string

        :param ret: Usually the stdout of the job
        :type ret: string

        :param retcode: The exit code of the job
        :type ret: int

        :returns: A JobFinished command object
        :rtype: JobFinished
        """
        if not isinstance(job_id, basestring) or len(job_id.strip()) == 0:
            raise InvalidParameterException('jid is invalid')
        elif not isinstance(ret, basestring) or len(ret.strip()) == 0:
            raise InvalidParameterException('ret is invalid')
        elif not isinstance(retcode, int):
            raise InvalidParameterException('retcode is invalid')

        return JobFinished(job_id, ret, retcode)
Пример #15
0
    def newRetrieveTokenByRefreshToken(self, refresh_token):
        """ Generates a new RetrieveTokenByRefreshToken query

        :param refresh_token: the refresh token
        :type refresh_token: string

        :returns: A RetrieveTokenByRefreshToken query object
        :rtype: RetrieveTokenByRefreshToken
        """
        client_id = client_id.strip()
        if not len(client_id) > 0:
            raise InvalidParameterException('Client id is invalid'.format(cmd))

        return RetrieveTokenByRefreshToken(refresh_token)
Пример #16
0
    def newAppendGrant(client_id, code, redirect_uri, scope, user_id, expires):
        """ Generates a new AppendGrant command

        :param client_id: the client id
        :type client_id: string

        :param code: the code
        :type code: string

        :param redirect_uri: the redirect uri
        :type redirect_uri: string

        :param scope: the scope
        :type scope: string

        :param user_id: the user_id
        :type user_id: string

        :param expires: when should the grant expire?
        :type expires: int

        :returns: An AppendGrant command object
        :rtype: AppendGrant
        """
        client_id = client_id.strip()
        if not len(client_id) > 0:
            raise InvalidParameterException('Client id is invalid'.format(cmd))

        code = code.strip()
        if not len(code) > 0:
            raise InvalidParameterException('Code is invalid'.format(cmd))

        redirect_uri = redirect_uri.strip()
        if not len(redirect_uri) > 0:
            raise InvalidParameterException(
                'Redirect uri is invalid'.format(cmd))

        scope = scope.strip()
        if not len(scope) > 0:
            raise InvalidParameterException('Scope is invalid'.format(cmd))

        user_id = user_id.strip()
        if not len(user_id) > 0:
            raise InvalidParameterException('User id is invalid'.format(cmd))

        if not expires >= 0:
            raise InvalidParameterException('Expires is invalid'.format(cmd))

        return AppendGrant(client_id, code, redirect_uri, scope, user_id,
                           expires)
Пример #17
0
    def newScheduleJobCommand(self, image, script, job_id, scratch, cores,
                              memory, secrets):
        """ Generates a new ScheduleTask command

        :param image: the docker image used for running the job
        :type image: string

        :param script: a list of strings with shellcode
        :type script: list

        :param job_id: the jobs id (max 32 characters)
        :type job_id: string

        :param scratch: should a scratch volume be mounted?
        :type scratch: bool

        :param cores: The amount of cores in the VM
        :type cores: int

        :param ram: The amount of RAM in GiB in the VM
        :type ram: int

        :param secrets: List of keys of secrets that should be injected into the process
        :type secrets: list

        :returns: A ScheduleJob command object
        :rtype: ScheduleJob
        """

        if not len(image) > 0:
            raise InvalidParameterException('image is invalid')
        elif not len(script) > 0:
            raise InvalidParameterException('script is invalid')
        elif not len(job_id) > 0:
            raise InvalidParameterException('job_id is invalid')
        elif cores <= 0:
            raise InvalidParameterException('cores is invalid')
        elif memory <= 0:
            raise InvalidParameterException('memory is invalid')
        elif not isinstance(secrets, list):
            raise InvalidParameterException('List of secrets is invalid')

        return ScheduleJob(image=image,
                           script=script,
                           job_id=job_id,
                           scratch=scratch,
                           cores=cores,
                           memory=memory,
                           secrets=secrets)
Пример #18
0
    def newRunJob(self, host, image, script, job_id, scratch, cores, memory):
        """ Generates a new RunShellCode command

        :param host: where host where te command should be ran
        :type host: string
        :param image: the docker image the script should run under
        :type image: string
        :param script: array of strings, the shellcode to be ran in the docker container
        :type script: list
        :param job_id: the name of the job to be used
        :type job_id: string
        :param scratch: should a scratch be mounted?
        :type scratch: bool
        :param cores: how many cores for this job?
        :type cores: int
        :param memory: how much memory for this job?
        :type memory: int

        :returns: A new RunJob command object
        :rtype: RunJob
        """

        if not len(host) > 0:
            raise InvalidParameterException('host is invalid')
        elif not len(image) > 0:
            raise InvalidParameterException('image is invalid')
        elif not len(script) > 0:
            raise InvalidParameterException('script is invalid')
        elif not len(job_id) > 0:
            raise InvalidParameterException('job_id is invalid')
        elif cores <= 0:
            raise InvalidParameterException('cores is invalid')
        elif memory <= 0:
            raise InvalidParameterException('memory is invalid')

        return RunJob(host=host, image=image, script=script, job_id=job_id, scratch=scratch, cores=cores, memory=memory)
Пример #19
0
    def new_remove_secret(self, key):
        if len(key) == 0:
            raise InvalidParameterException('key len must be > 0')

        return RemoveSecret(key)
Пример #20
0
    def newVmCreatedEvent(self, job_id):
        if not isinstance(job_id, basestring) or len(job_id.strip()) == 0:
            raise InvalidParameterException('job_id not valid')

        return VmCreated(job_id)