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)
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" )
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()
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()
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)