예제 #1
0
 def add(self, token, args):
     """
     Create a token.
     @param token: A security token.
     @type token: string
     @param args: A dictionary of token attributes.
         - token
         - profile_id (optional)
         - uses_remaining
     @type args: dict
     @raise SQLException: On database error
     """
     required = []
     optional = ['profile_id', 'uses_remaining', 'token']
     validator = FieldValidator(args)
     validator.verify_required(required)
     validator.verify_int(['uses_remaining'])
     session = db.open_session()
     try:
         regtoken = db.RegToken()
         regtoken.update(args)
         session.save(regtoken)
         session.flush()
         return success(regtoken.id)
     finally:
         session.close()
예제 #2
0
 def validate(self, args, required):
     vdr = FieldValidator(args)
     vdr.verify_required(required)
     # this code doesn't work, so commenting out for now -- MPD
     # vdr.verify_enum('architecture', codes.VALID_ARCHS)
     # vdr.verify_int(['processor_speed', 'processor_count', 'memory'])
     vdr.verify_printable(
         "kernel_options", "kickstart_metadata", "list_group", "list_group", "puppet_node_diff", "tags"
     )
예제 #3
0
 def add_by_tag(self, token, args):
     """
     Create a task by tag. A separate task will be added
     for each deployment with this tag
     @param token: A security token.
     @type token: string
     @param args: A dictionary of task attributes.
         - user_id
         - action_type
         - tag
         - state
     @type args: dict
     @raise SQLException: On database error
     """
     optional = ()
     required = ('user_id', 'action_type', 'tag', 'state')
     validator = FieldValidator(args)
     validator.verify_required(required)
     validator.verify_enum('state', VALID_TASK_STATES)
     validator.verify_enum('action_type', VALID_TASK_OPERATIONS)
     deployments = deployment.Deployment().get_by_tag(None, args)
     if deployments.error_code != 0:
         return deployments
     
     result = []
     for deployment in deployments.data:
         args["deployment_id"]=deployment["id"]
         args["machine_id"]=deployment["machine_id"]
         id = self.add(None, args)
         if id.error_code != 0:
             return id
         result.append(id.data)
     return success(id)
예제 #4
0
 def add(self, token, args):
     """
     Create a task.
     @param token: A security token.
     @type token: string
     @param args: A dictionary of task attributes.
         - user_id
         - action_type
         - machine_id
         - deployment_id
         - state
     @type args: dict
     @raise SQLException: On database error
     """
     optional = ()
     required = ('user_id', 'action_type', 'machine_id', 'deployment_id', 'state')
     validator = FieldValidator(args)
     validator.verify_required(required)
     validator.verify_enum('state', VALID_TASK_STATES)
     validator.verify_enum('action_type', VALID_TASK_OPERATIONS)
     session = db.open_session()
     try:
         task = db.Task()
         task.update(args)
         session.save(task)
         session.flush()
         return success(task.id)
     finally:
         session.close()
예제 #5
0
 def edit(self, token, args):
     """
     Edit a task.
     @param token: A security token.
     @type token: string
     @param args: A dictionary of task attributes.
         - id
         - state  (optional)
     @type args: dict
     @raise SQLException: On database error
     @raise NoSuchObjectException: On object not found.
     """
     required = ('id',)
     optional = ('state',)
     filter_fields = ('id', 'user_id', 'action_type', 'machine_id', 'deployment_id')
     validator = FieldValidator(args)
     validator.verify_required(required)
     validator.verify_enum('state', VALID_TASK_STATES)
     validator.verify_enum('action_type', VALID_TASK_STATES)
     session = db.open_session()
     try:
         task = db.Task.get(session, args['id'])
         task.update(args, filter_fields)
         session.save(task)
         session.flush()
         return success()
     finally:
         session.close()
예제 #6
0
    def edit(self, token, args):
        """
        Edit a deployment.
        @param token: A security token.
        @type token: string
        @param args: A dictionary of deployment arguments.
        @type args: dict
        @raise SQLException: On database error
        @raise NoSuchObjectException: On object not found.
        """
        mac = None
        profilename = None
        required = ('id',)
        optional = ('machine_id', 'state', 'display_name',
                    'hostname', 'ip_address', 'registration_token',
                    'mac_address', 'netboot_enabled', 'puppet_node_diff',
                    'is_locked', 'last_heartbeat','auto_start', 'tag_ids')
        filter = ('id', 'profile_id')
        validator = FieldValidator(args)
        validator.verify_required(required)
        validator.verify_printable('puppet_node_diff', 'tags')

        if args.has_key("machine_id"):
            try:
                machine_obj = machine.Machine()
                result = machine_obj.get(token, { "id" : args["machine_id"]})
                mac = result.data["mac_address"]
            except VirtFactoryException:
                raise InvalidArgumentsException(invalid_fields={"machine_id":REASON_ID})

        if args.has_key("profile_id"):
            try:
                profile_obj = profile.Profile()
                result = profile_obj.get(token, { "id" : args["profile_id"] })
                profilename = result.data["name"]
            except VirtFactoryException:
                raise InvalidArgumentsException(invalid_fields={"machine_id":REASON_ID})

        args["netboot_enabled"] = 0 # never PXE's

        session = db.open_session()
        try:
            deployment = db.Deployment.get(session, args['id'])
            if args.has_key("machine_id") or args.has_key("profile_id"):
                if not args.has_key("machine_id"):
                    mac = deployment["machine"]["mac_address"]
                if not args.has_key("profile_id"):
                    profilename=deployment["profile"]["name"]
                display_name = mac + "/" + profilename
                args["display_name"] = display_name
                
                
            deployment.update(args, filter)
            session.save(deployment)
            if args.has_key('tag_ids'):
                setattr(deployment, "tags", tag.Tag().tags_from_ids(session,
                                                                 args['tag_ids']))
            session.flush()
            self.cobbler_sync(deployment.get_hash())
            return success()
        finally:
            session.close()
예제 #7
0
    def add(self, token, args):
        """
        Create a deployment.
        @param token: A security token.
        @type token: string
        @param args: A dictionary of deployment arguments.
        @type args: dict
        @raise SQLException: On database error
        """
        mac = None
        profilename = None
        required = ('machine_id', 'profile_id')
        optional = ('hostname',
                    'ip_address',
                    'registration_token',
                    'mac_address',
                    'netboot_enabled',
                    'puppet_node_diff',
                    'is_locked',
                    'auto_start',
                    'last_heartbeat',
                    'tag_ids')
        self.logger.info(args)
        validator = FieldValidator(args)
        validator.verify_required(required)
        validator.verify_printable('puppet_node_diff')
        
        # find highest deployment id
        all_deployments = self.list(token, {})

        try:
            machine_obj = machine.Machine()
            machine_result = machine_obj.get(token, { "id" : args["machine_id"]})
            mac = machine_result.data["mac_address"]
        except VirtFactoryException:
            raise OrphanedObjectException(invalid_fields={'machine_id':REASON_ID})

        try:
            profile_obj = profile.Profile()
            result = profile_obj.get(token, { "id" : args["profile_id"]})
            profilename = result.data["name"]
        except VirtFactoryException:
            raise OrphanedObjectException(invalid_fields={'profile_id':REASON_ID})

        display_name = mac + " / " + profilename
        
        args["display_name"] = display_name
        args["netboot_enabled"] = 0
        args["mac_address"] = self.generate_mac_address(all_deployments.data[-1]["id"])
        args["state"] = DEPLOYMENT_STATE_CREATING
        args["netboot_enabled"] = 0 # never PXE's
        args["registration_token"] = regtoken.RegToken().generate(token)

        if not args.has_key("auto_start"):
            args["auto_start"] = 1 
       
        # cobbler sync must run with a filled in item in the database, so we must commit
        # prior to running cobbler sync
         
        session = db.open_session()
        try:
            deployment = db.Deployment()
            deployment.update(args)
            session.save(deployment)
            if args.has_key('tag_ids'):
                setattr(deployment, "tags", tag.Tag().tags_from_ids(session,
                                                                 args['tag_ids']))
            session.flush()
            self.cobbler_sync(deployment.get_hash())
            args["id"] = deployment.id
            self.__queue_operation(token, args, TASK_OPERATION_INSTALL_VIRT) 
            return success(deployment.id)
        finally:
            session.close()
예제 #8
0
 def validate(self, args, required):
     vdr = FieldValidator(args)
     vdr.verify_required(required)
     vdr.verify_printable('name', 'version', 'kernel_options', 'puppet_classes', 'virt_type')
     vdr.verify_int(['virt_storage_size', 'virt_ram'])
     vdr.verify_enum('valid_targets', VALID_TARGETS)
     vdr.verify_enum('is_container', VALID_CONTAINERS)
예제 #9
0
 def validate(self, args, required):
     vdr = FieldValidator(args)
     vdr.verify_required(required)
     vdr.verify_file('kernel', 'initrd')
     vdr.verify_printable('name', 'kernel_options')
     vdr.verify_enum('architecture', VALID_ARCHS)