Ejemplo n.º 1
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)
Ejemplo n.º 2
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()
Ejemplo n.º 3
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)
Ejemplo n.º 4
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()
Ejemplo n.º 5
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)