def add_profile(data, user, id=0): logger.debug("profile id = %d", id) if id: # update of an existing profile; fetch it profile = get_profile(id) logger.debug("password stored in db " + str(profile.image_server_password)) if not profile.image_server_password == data[IMAGE_SERVER_PASSWORD]: password = encrypt_data(data[IMAGE_SERVER_PASSWORD]) logger.debug("change in password, new encoded password " + str(password)) profile.image_server_password = str(password) profile.is_encrypted = True else: # create new profile profile = ImageProfile() password = encrypt_data(data[IMAGE_SERVER_PASSWORD]) profile.image_server_password = str(password) profile.is_encrypted = True profile.profile_name = data[PROFILE_NAME] profile.system_image = data[SYSTEM_IMAGE] profile.epld_image = data[EPLD_IMAGE] profile.kickstart_image = data[KICKSTART_IMAGE] profile.image_server_ip = data[IMAGE_SERVER_IP] profile.image_server_username = data[IMAGE_SERVER_USERNAME] profile.access_protocol = data[ACCESS_PROTOCOL] profile.updated_by = user if profile.system_image is None and profile.epld_image is None and profile.kickstart_image is None: raise IgniteException(ERR_IMG_PRO_IMAGE_PATH_EMPTY) profile.save() return profile
def run_single_job(jid, time): print 'celery worker got a job with id ' + str(jid) + ' and time ' + str( time) jb = Job.objects.get(id=jid) jb.status = 'RUNNING' jb.save() tasks = [] count = 0 break_flag = False try: for task in jb.tasks: get_task_parameters(task) try: status = run_single_sequence(task, break_flag) except Exception as e: status = 'EXCEPTION' print "exception while running task" print e if status == 'SUCCESS': count = count + 1 elif task['failure_action_grp'] != 'continue': break_flag = True tasks.append(task) if count == len(tasks): jb.status = 'SUCCESS' else: jb.status = 'FAILURE' # encrypt passwords for task in tasks: if task['type'] != "custom": print "in ceelry tasks", task['task_params']['image'][ 'image_server_password'] if task['task_params']['image']['is_encrypted']: password = encrypt_data( task['task_params']['image']['image_server_password']) task['task_params']['image'][ 'image_server_password'] = password if task['group']['is_encrypted']: task['group']['password'] = encrypt_data( task['group']['password']) fill_image_details(task, decrypt=False) jb.tasks = tasks except Exception as e: print e jb.status = 'EXCEPTION' ref_count_delete(jb) ctime = str(datetime.datetime.utcnow()) ctime = datetime.datetime.strptime(ctime, '%Y-%m-%d %H:%M:%S.%f') ctime = timezone.make_aware(ctime, pytz.timezone('UTC')) jb.ctime = ctime print tasks jb.save()
def run_single_job(jid, time): print 'celery worker got a job with id ' + str(jid) + ' and time ' + str(time) jb = Job.objects.get(id=jid) jb.status = 'RUNNING' jb.save() tasks = [] count = 0 break_flag = False try: for task in jb.tasks: get_task_parameters(task) try: status = run_single_sequence(task, break_flag) except Exception as e: status = 'EXCEPTION' print "exception while running task" print e if status == 'SUCCESS': count = count + 1 elif task['failure_action_grp'] != 'continue': break_flag = True tasks.append(task) if count == len(tasks): jb.status = 'SUCCESS' else: jb.status = 'FAILURE' # encrypt passwords for task in tasks: if task['type'] != "custom": print "in ceelry tasks", task['task_params']['image']['image_server_password'] if task['task_params']['image']['is_encrypted']: password = encrypt_data(task['task_params']['image']['image_server_password']) task['task_params']['image']['image_server_password'] = password if task['group']['is_encrypted']: task['group']['password'] = encrypt_data(task['group']['password']) fill_image_details(task, decrypt=False) jb.tasks = tasks except Exception as e: print e jb.status = 'EXCEPTION' ref_count_delete(jb) ctime = str(datetime.datetime.utcnow()) ctime = datetime.datetime.strptime(ctime, '%Y-%m-%d %H:%M:%S.%f') ctime = timezone.make_aware(ctime, pytz.timezone('UTC')) jb.ctime = ctime print tasks jb.save()
def _add_task(data, user, id=0): logger.debug("Task name = %s", data[NAME]) if id: # get existing task task = Task.objects.get(pk=id) if not task.editable: raise IgniteException(ERR_TASK_NOT_EDITABLE) else: # create new task task = Task() task.name = data[NAME] task.handler = data[HANDLER] task.function = data[FUNCTION] task.desc = data[DESCRIPTION] task.location_access_protocol = data[LOC_ACCESS_PROTO] task.location_server_ip = data[LOC_SERVER_IP] task.location_server_user = data[LOC_SERVER_USER] password = encrypt_data(data[LOC_SERVER_PASSWORD]) task.location_server_password = password task.is_encrypted = True task.parameters = data[PARAMETERS] task.updated_by = user task.save() return task
def update_group(data, fab_id, grp_id, user): grp = Group.objects.get(pk=grp_id) grp.name = data["name"] grp.username = data["username"] password = encrypt_data(data["password"]) grp.password = password grp.is_encrypted = True grp.updated_by = user delete_switches(grp_id) add_switches(data['switch_list'], fab_id, grp_id, user) grp.save() return grp
def add_group(data, fab_id, user): grp = Group() grp.name = data["name"] grp.username = data["username"] password = encrypt_data(data["password"]) grp.password = password grp.is_encrypted = True grp.updated_by = user grp.fabric = Fabric.objects.get(id=fab_id) grp.save() add_switches(data['switch_list'], fab_id, grp.id, user) return grp