def bash(): """fab bash\t\t\t\tDefine bash aliases for lab""" from lab.laboratory import Laboratory from lab.nodes.lab_server import LabServer from lab.nodes.virtual_server import VirtualServer pod = Laboratory.create(lab_name=get_user_input( obj=Laboratory.MERCURY_DIC.keys())) aliases = [] for node in pod.nodes.values(): if not isinstance(node, VirtualServer): aliases.append( 'alias z{n}="sshpass -p {p} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no {u}@{ip}"' .format(n=node.id, p=node.oob_password, u=node.oob_username, ip=node.oob_ip)) # cimc if isinstance(node, LabServer): ip, username, password = ( node.proxy.ip + ' ' + 'ssh -o StrictHostKeyChecking=no ' + node.id, node.proxy.username, node.proxy.password) if node.proxy else (node.ip, node.username, node.password) password = '******' + password + ' ' if password else '' # if password is None use the key pair to ssh aliases.append( 'alias {n}="{p}ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no {u}@{ip}"' .format(p=password, n=node.id, u=username, ip=ip)) # ssh with open('tmp.aliases', 'w') as f: f.write('\n'.join(sorted(aliases))) f.write('\nPS1="({}) $PS1 "\n'.format(pod))
def info(pod_name=None, regex=None): """fab info:g10,regex\t\t\tExec grep regex """ from lab.laboratory import Laboratory pod = Laboratory.create(lab_name=pod_name) pod.r_collect_info(regex=regex, comment=regex)
def bash(): """fab bash\t\t\t\tDefine bash aliases for lab""" from lab.laboratory import Laboratory from lab.nodes.lab_server import LabServer from lab.nodes.virtual_server import VirtualServer pod = Laboratory.create(lab_name=get_user_input(obj=Laboratory.MERCURY_DIC.keys())) aliases = [] for node in pod.nodes.values(): if not isinstance(node, VirtualServer): aliases.append('alias z{n}="sshpass -p {p} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no {u}@{ip}"'.format(n=node.id, p=node.oob_password, u=node.oob_username, ip=node.oob_ip)) # cimc if isinstance(node, LabServer): ip, username, password = (node.proxy.ip + ' ' + 'ssh -o StrictHostKeyChecking=no ' + node.id, node.proxy.username, node.proxy.password) if node.proxy else (node.ip, node.username, node.password) password = '******' + password + ' ' if password else '' # if password is None use the key pair to ssh aliases.append('alias {n}="{p}ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no {u}@{ip}"'.format(p=password, n=node.id, u=username, ip=ip)) # ssh with open('tmp.aliases', 'w') as f: f.write('\n'.join(sorted(aliases))) f.write('\nPS1="({}) $PS1 "\n'.format(pod))
def cmd(): """fab cmd\t\t\t\tRun single command on lab device """ import inspect from fabric.operations import prompt import time from lab.deployers.deployer_existing_light import DeployerExistingLight from lab.with_log import lab_logger from lab.laboratory import Laboratory pod_names = Laboratory.MERCURY_DIC['pods'].keys() l_and_s_names = map(lambda x: 'l' + x, pod_names) + map( lambda x: 's' + x, pod_names) _, pod_name = get_user_input(obj=l_and_s_names) root = Laboratory.create( lab_name=pod_name[1:], is_interactive=True) if pod_name[0] == 'l' else DeployerExistingLight( pod_name[1:])() obj = root while True: obj, method = get_user_input(obj=obj) try: obj.log('{} executing ......................'.format(method)) time.sleep(1) parameters = method.func_code.co_varnames[1:method.func_code. co_argcount] arguments = [] for parameter in parameters: argument = prompt(text='{p}=? '.format(p=parameter)) if argument.startswith('['): argument = argument.strip('[]').split(',') elif argument in ['True', 'true', 'yes']: argument = True elif argument in ['False', 'false', 'no']: argument = False arguments.append(argument) results = method(*arguments) if arguments else method() time.sleep(1) obj.log('{}() returns:\n\n {}\n'.format(method, results)) except Exception as ex: lab_logger.exception('\n Exception: {0}'.format(ex)) prompt('')
def cmd(): """fab cmd\t\t\t\tRun single command on lab device """ import inspect from fabric.operations import prompt import time from lab.deployers.deployer_existing_light import DeployerExistingLight from lab.with_log import lab_logger from lab.laboratory import Laboratory pod_names = Laboratory.MERCURY_DIC['pods'].keys() l_and_s_names = map(lambda x: 'l' + x, pod_names) + map(lambda x: 's' + x, pod_names) _, pod_name = get_user_input(obj=l_and_s_names) root = Laboratory.create(lab_name=pod_name[1:], is_interactive=True) if pod_name[0] == 'l' else DeployerExistingLight(pod_name[1:])() obj = root while True: obj, method = get_user_input(obj=obj) try: obj.log('{} executing ......................'.format(method)) time.sleep(1) parameters = method.func_code.co_varnames[1:method.func_code.co_argcount] arguments = [] for parameter in parameters: argument = prompt(text='{p}=? '.format(p=parameter)) if argument.startswith('['): argument = argument.strip('[]').split(',') elif argument in ['True', 'true', 'yes']: argument = True elif argument in ['False', 'false', 'no']: argument = False arguments.append(argument) results = method(*arguments) if arguments else method() time.sleep(1) obj.log('{}() returns:\n\n {}\n'.format(method, results)) except Exception as ex: lab_logger.exception('\n Exception: {0}'.format(ex)) prompt('')
def __call__(self, *args, **kwargs): from lab.cloud.openstack import OS from lab.laboratory import Laboratory mgm = Laboratory.create(lab_name=self.pod_name, is_mgm_only=True) return OS(name=self.pod_name, mediator=mgm, openrc_path='openrc')
def __init__(self, lab_name, allowed_drivers): from lab.laboratory import Laboratory self.pod = Laboratory.create(lab_name=lab_name, allowed_drivers=allowed_drivers)