def router(ctx, name, protocol, user, password): """Connect to the console of a network router""" # Router only supports console access if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/router', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No Router named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') if password: password_value = getpass.getpass( 'Password for {}: '.format(user)) conn = Connectorizer(ctx.obj.vlab_config, info['content']['gateway_ip'], user=user, password=password_value) else: conn = Connectorizer(ctx.obj.vlab_config, info['content']['gateway_ip'], user=user) conn.console(vm_moid) else: error = 'Unexpected connection protocol supplied' raise click.ClickException(error)
def icap(ctx, name, protocol): """Connect to an ICAP server""" if protocol == 'console': info = consume_task(ctx.obj.vlab_api, endpoint='/api/2/inf/icap', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No ICAP VM named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: target_port = get_protocol_port('icap', protocol) with Spinner('Lookin up connection information for {}'.format(name)): resp = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={'name' : name, 'target_port' : target_port}).json() try: conn_port = list(resp['content']['ports'].keys())[0] except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format(protocol, name) raise click.ClickException(error) conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip']) conn.rdp(port=conn_port)
def avamar(ctx, name, protocol, user, password): """Connect to an Avamar server""" if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/avamar/server', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No Avamar server named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: target_port = get_protocol_port('Avamar', protocol) with Spinner('Lookin up connection information for {}'.format(name)): resp = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={ 'name': name, 'target_port': target_port }).json() try: conn_port = list(resp['content']['ports'].keys())[0] except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format( protocol, name) raise click.ClickException(error) if password: password_value = getpass.getpass('Password for {}: '.format(user)) conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user, password=password_value) else: conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user) if protocol == 'ssh': conn.ssh(port=conn_port) elif protocol == 'https': click.secho( "WARNING: Some parts of the Avamar WebUI only work from inside your lab.", bold=True) conn.https(port=conn_port, endpoint='/dtlt/home.html') elif protocol == 'scp': conn.scp(port=conn_port) elif protocol == 'mgmt': conn.https(port=conn_port) else: error = 'Unexpected protocol requested: {}'.format(protocol) raise RuntimeError(error)
def deployment(ctx, name, protocol, user, password): """Connect to a deployed machine""" if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/deployment', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No Deployment VM named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: with Spinner('Looking up connection information for {}'.format(name)): data = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={ 'name': name }).json()['content'] ports = data['ports'] port_map = {ports[x]['target_port']: x for x in ports.keys()} try: conn_port = determine_port(protocol, port_map) except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format( protocol, name) raise click.ClickException(error) if password: password_value = getpass.getpass('Password for {}: '.format(user)) conn = Connectorizer(ctx.obj.vlab_config, data['gateway_ip'], user=user, password=password_value) else: conn = Connectorizer(ctx.obj.vlab_config, data['gateway_ip'], user=user) if protocol == 'ssh': conn.ssh(port=conn_port) elif protocol == 'scp': conn.scp(port=conn_port) elif protocol == 'rdp': conn.rdp(port=conn_port) elif protocol == 'https': conn.https(port=conn_port) else: error = 'Unexpected protocol requested: {}'.format(protocol) raise RuntimeError(error)
def kemp(ctx, name, protocol, user, password): """Connect to a Kemp ECS Connection Management load balancer""" if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/kemp', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No Kemp ECS Connection Management load balancer named {} found'.format( name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: target_port = get_protocol_port('insightiq', protocol) with Spinner('Lookin up connection information for {}'.format(name)): resp = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={ 'name': name, 'target_port': target_port }).json() try: conn_port = list(resp['content']['ports'].keys())[0] except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format( protocol, name) raise click.ClickException(error) if password: password_value = getpass.getpass('Password for {}: '.format(user)) conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user, password=password_value) else: conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user) if protocol == 'ssh': conn.ssh(port=conn_port) elif protocol == 'https': conn.https(port=conn_port) elif protocol == 'scp': conn.scp(port=conn_port) else: error = 'Unexpected protocol requested: {}'.format(protocol) raise RuntimeError(error)
def superna(ctx, name, protocol, user, password): """Connect to an Superna Eyeglass server""" if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/superna', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No Data Domain server named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: if protocol.lower() == 'https': error = 'Superna web interface only accessible from a machine *inside* your lab.' raise click.ClickException(error) with Spinner('Lookin up connection information for {}'.format(name)): resp = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={ 'name': name, 'target_port': target_port }).json() try: conn_port = list(resp['content']['ports'].keys())[0] except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format( protocol, name) raise click.ClickException(error) if password: password_value = getpass.getpass('Password for {}: '.format(user)) conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user, password=password_value) else: conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user) if protocol == 'ssh': conn.ssh(port=conn_port) elif protocol == 'scp': conn.scp(port=conn_port) else: error = 'Unexpected protocol requested: {}'.format(protocol) raise RuntimeError(error)
def dataiq(ctx, name, protocol): """Connect to a DataIQ instance""" if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/dataiq', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No dataiq VM named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: target_port = get_protocol_port('dataiq', protocol) with Spinner('Lookin up connection information for {}'.format(name)): resp = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={ 'name': name, 'target_port': target_port }).json() try: conn_port = list(resp['content']['ports'].keys())[0] except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format( protocol, name) raise click.ClickException(error) conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip']) if protocol == 'ssh': conn.ssh(port=conn_port) elif protocol == 'https': conn.https(port=conn_port) elif protocol == 'scp': conn.scp(port=conn_port) elif protocol == 'rdp': conn.rdp(port=conn_port) else: error = 'Unexpected protocol requested: {}'.format(protocol) raise RuntimeError(error)
def winserver(ctx, name, protocol, user, password): """Connect to a Microsoft Server instance""" if protocol == 'console': info = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/winserver', message='Looking up connection info for {}'.format(name), method='GET').json() if not info['content'].get(name, None): error = 'No Windows Server named {} found'.format(name) raise click.ClickException(error) else: vm_moid = info['content'][name].get('moid', 'n/a') conn = Connectorizer(ctx.obj.vlab_config, gateway_ip='n/a') conn.console(vm_moid) else: target_port = get_protocol_port('winserver', protocol) with Spinner('Lookin up connection information for {}'.format(name)): resp = ctx.obj.vlab_api.get('/api/1/ipam/portmap', params={ 'name': name, 'target_port': target_port }).json() try: conn_port = list(resp['content']['ports'].keys())[0] except Exception as doh: ctx.obj.log.debug(doh, exc_info=True) conn_port = None if not conn_port: error = 'No mapping rule for {} to {} exists'.format( protocol, name) raise click.ClickException(error) if password: password_value = getpass.getpass('Password for {}: '.format(user)) conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user, password=password_value) else: conn = Connectorizer(ctx.obj.vlab_config, resp['content']['gateway_ip'], user=user) conn.rdp(port=conn_port)