def get_all_switches(task, decrypt=True): gid = task['group_id'] grp = Group.objects.get(id=int(gid)) gsh = GroupSwitch.objects.filter(group__id=int(gid)) task['group'] = {} task['group']['group_name'] = grp.name task['group']['username'] = grp.username task['group']['is_encrypted'] = grp.is_encrypted password = grp.password if decrypt: if grp.is_encrypted: password = decrypt_data(grp.password) task['group']['password'] = password switches = [] task['group']['switches'] = [] index = 0 for i in gsh: sw = {} sw['ip'] = i.grp_switch.mgmt_ip.split('/')[0] sw['id'] = i.grp_switch.id sw['fab_id'] = i.grp_switch.topology_id sw['name'] = i.grp_switch.name sw['user'] = grp.username password = grp.password if decrypt: if grp.is_encrypted: password = decrypt_data(grp.password) #i.username if i.username else grp.username sw['pwd'] = password #i.password if i.password else grp.password sw['retry'] = int(task['retry_count']) + 1 switches.append(sw) return switches
def _update_image_params(img, serial_number): param = dict() param[SERIAL_NUM] = serial_number param[PROTOCOL] = img.access_protocol param[HOSTNAME] = img.image_server_ip param[FILE_SRC] = img.system_image param[USERNAME] = img.image_server_username password = img.image_server_password if img.is_encrypted: password = decrypt_data(password) param[PASSWORD] = password return param
def login(request): error_msg = '' if request.method == "POST": username = request.POST.get('username', None) passwd = request.POST.get('passwd', None) passwd = base64.b64decode(passwd) passwd = decrypt_data(passwd) passwd = SHA256(passwd) res = Account.objects.filter(username=username, password=passwd) if res.count() >= 1: account = res.get() request.session['user'] = account.username return redirect('/index') else: error_msg = '用户名密码不正确' pub_key = open('./pub.pem').read() return render(request, 'login.html', {'key': pub_key, 'errmsg': error_msg})
def _get_server_location(task_obj=None): location = {} if not task_obj: location[PROTOCOL] = ACCESS_PROTOCOL location[HOSTNAME] = IGNITE_IP location[USERNAME] = IGNITE_USER location[PASSWORD] = IGNITE_PASSWORD return location location[PROTOCOL] = task_obj.location_access_protocol location[HOSTNAME] = task_obj.location_server_ip location[USERNAME] = task_obj.location_server_user password = task_obj.location_server_password if task_obj.is_encrypted: password = decrypt_data(password) location[PASSWORD] = password return location
def fill_image_details(task, decrypt=True): image_profile = ImageProfile.objects.get(pk=int(task['image_id'])) image = {} if image_profile.system_image == None: raise Exception("No system image is found in "+image_profile.profile_name) if task['type'] == 'epld_upgrade' and image_profile.epld_image == None: raise Exception("No epld image is found in "+image_profile.profile_name) task['task_params'] = {} image['profile_name'] = image_profile.profile_name image['system_image'] = image_profile.system_image image['id'] = image_profile.id image['image_server_ip'] = image_profile.image_server_ip image['image_server_username'] = image_profile.image_server_username password = image_profile.image_server_password image['is_encrypted'] = image_profile.is_encrypted if decrypt: if image_profile.is_encrypted: password = decrypt_data(password) image['image_server_password'] = password image['access_protocol'] = image_profile.access_protocol if task['type'] == 'epld_upgrade': image['epld_image'] = image_profile.epld_image task['task_params']['image'] = image
def run_single_sequence(task, break_flag=False): print 'Running sequence ' + ' on group ' + str(task['group_id']) print 'break_flag is', break_flag switches = get_all_switches(task) if task['type'] not in ["custom", "switch_upgrade", "epld_upgrade"]: if task['task_params']['image']['is_encrypted']: password = decrypt_data(task['task_params']['image']['image_server_password']) task['task_params']['image']['image_server_password'] = password if break_flag: for switch in switches: switch['status'] = 'SKIPPED' task['group']['switches'] = switches task['status'] = 'SKIPPED' else: runsize = task['run_size'] #create a threadpool of size runsize with concurrent.futures.ThreadPoolExecutor(max_workers=runsize) as pool: run_task_switches(switches, task, pool) 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')) task['ctime'] = ctime return task['status']