Пример #1
0
def handle_updates(vlab_api, vlab_config, skip_update_check):
    """Check for an updated CLI, and prompt the user to download if available.

    :Returns: None

    :param vlab_api: An established HTTP/S connect to the vLab server
    :type vlab_api: vlab_cli.lib.api.vLabApi

    :param vlab_config: The user's config
    :type vlab_config: configparser.ConfigParser

    :param skip_update_check: A chicken switch to avoid SPAMing power users
    :type skip_update_check: Boolean
    """
    if skip_update_check:
        return
    page = vlab_api.get('https://vlab.emc.com/getting_started.html').content
    soup = BeautifulSoup(page, features="html.parser")
    site_version = ''
    for a in soup.find_all('a', href=True):
        url = a['href']
        package = os.path.basename(url)
        if package.startswith('vlab-cli'):
            # example package name: vlab-cli-2020.5.21-amd64.msi
            site_version = package.split('-')[2]
            break

    current_version = version.__version__
    if site_version and site_version != current_version:
        question = "A new version of vLab CLI is available. Download now? [Y/n]"
        answer = prompt(question, boolean=True, boolean_default=True)
        if answer:
            download_url = build_url(vlab_api.server, url)
            conn = Connectorizer(vlab_config, gateway_ip='n/a')
            conn.https(port=443, url=download_url)
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)