def kemp(ctx, name, image, external_network): """Create a Kemp ECS Connection Management load balancer""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/kemp', message= 'Creating a new instance of Kemp ECS connection management load balancer running {}' .format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: with Spinner("Creating port mapping rules for HTTPS and SSH"): vm_type = data['meta']['component'] https_port = https_to_port(vm_type.lower()) portmap_payload = { 'target_addr': ipv4_addrs[0], 'target_port': https_port, 'target_name': name, 'target_component': data['meta']['component'] } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) portmap_payload['target_port'] = 22 ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect kemp --protocol console --name {}'".format( name))
def insightiq(ctx, name, image, external_network): """Create an instance of InsightIQ""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/insightiq', message='Creating a new instance of InsightIQ running {}'.format( image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: with Spinner("Creating port mapping rules for HTTPS and SSH"): vm_type = data['meta']['component'] https_port = https_to_port(vm_type.lower()) portmap_payload = { 'target_addr': ipv4_addrs[0], 'target_port': https_port, 'target_name': name, 'target_component': 'InsightIQ' } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) portmap_payload['target_port'] = 22 ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect insightiq --protocol console --name {}' to setup a login password" .format(name)) typewriter("for your new InsightIQ instance.")
def router(ctx, image, name, networks): """Create a new network router""" if len(networks) < 2: error = 'Routers must connect at least 2 networks, supplied {}: {}'.format( len(networks), ' '.join(networks)) raise click.ClickException(error) elif len(networks) > 4: error = 'Routers can only connect at most 4 networks, supplied {}: {}'.format( len(networks), ' '.join(networks)) raise click.ClickException(error) body = {'name': name, 'image': image, 'networks': networks} resp = consume_task(ctx.obj.vlab_api, endpoint='/api/2/inf/router', message='Creating a new router for networks {}'.format( ' '.join(networks)), body=body, timeout=900, pause=5) data = resp.json()['content'][name] output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) typewriter( "\nUse 'vlab connect router --name {}' to access your new network Router" .format(name))
def centos(ctx, name, image, external_network, desktop, cpu_count, ram): """Create an instance of CentOS""" body = {'network': external_network, 'name': name, 'image': image, 'desktop': desktop, 'ram': int(ram), 'cpu-count': int(cpu_count)} resp = consume_task(ctx.obj.vlab_api, endpoint='/api/2/inf/centos', message='Creating a new instance of CentOS {}'.format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: vm_type = data['meta']['component'] with Spinner('Creating an SSH port mapping rule'): for ipv4 in ipv4_addrs: portmap_payload = {'target_addr' : ipv4, 'target_port' : 22, 'target_name' : name, 'target_component' : vm_type} ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) if desktop: with Spinner('Creating an RDP port mapping rule'): for ipv4 in ipv4_addrs: portmap_payload = {'target_addr' : ipv4, 'target_port' : 3389, 'target_name' : name, 'target_component' : vm_type} ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter("\nUse 'vlab connect centos --name {}' to access your new CentOS instance".format(name))
def dd(ctx, name, image, external_network): """Create a Data Domain server""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/data-domain', message='Creating a new Data Domain server running {}'.format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: with Spinner("Creating port mapping rules for HTTPS and SSH"): vm_type = data['meta']['component'] https_port = https_to_port(vm_type.lower()) portmap_payload = { 'target_addr': ipv4_addrs[0], 'target_port': https_port, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) portmap_payload['target_port'] = 22 ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect dd --name {}' to configure your new Data Domain server." .format(name)) typewriter("Initial/default credentials are 'sysadmin' and 'changeme'")
def windows(ctx, name, image, external_network): """Create a new Windows Desktop client""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/windows', message='Creating a new instance of Windows {}'.format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: vm_type = data['meta']['component'] with Spinner('Creating an RDP port mapping rule'): for ipv4 in ipv4_addrs: portmap_payload = { 'target_addr': ipv4, 'target_port': 3389, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect windows --name {}' to access your new Windows client" .format(name))
def ana(ctx, name, image, static_ip, external_netmask, default_gateway, dns_servers, domain, external_network): """Create a new Avamar NDMP accelerator.""" body = {'network': external_network, 'name': name, 'image': image, 'ip-config': {'static-ip': static_ip, 'default-gateway': default_gateway, 'netmask': external_netmask, 'dns': dns_servers, 'domain': domain } } resp = consume_task(ctx.obj.vlab_api, endpoint='/api/2/inf/avamar/ndmp-accelerator', message='Creating a new Avamar NDMP accelerator running version {}'.format(image), body=body, timeout=1800, pause=5) data = resp.json()['content'][name] vm_type = data['meta']['component'] with Spinner('Creating port mapping rules for HTTPS and SSH'): protocols = get_component_protocols(vm_type.lower()) for protocol in protocols: port = get_protocol_port(vm_type, protocol) payload = {'target_addr' : static_ip, 'target_port' : port, 'target_name' : name, 'target_component' : vm_type} ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) msg = "Use 'vlab connect avamar --name {} --protocol mgmt' to setup your new Avamar Server\n".format(name) msg += "The default credentials are 'root' and 'changme'".format(name) typewriter(msg)
def dataiq(ctx, name, image, external_network, external_netmask, default_gateway, dns_servers, static_ip, disk_size, cpu_count, ram): """Create an instance of DataIQ""" error = network_config_ok(static_ip, default_gateway, external_netmask) if error: raise click.ClickException(error) body = { 'network': external_network, 'name': name, 'image': image, 'static-ip': static_ip, 'default-gateway': default_gateway, 'external-netmask': external_netmask, 'dns-servers': dns_servers, 'disk-size': int(disk_size), 'cpu-count': int(cpu_count), 'ram': int(ram) } resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/dataiq', message='Creating a new instance of DataIQ {}'.format(image), body=body, timeout=1800, pause=5) data = resp.json()['content'][name] data['ips'] = [static_ip] vm_type = data['meta']['component'] protocols = get_component_protocols(vm_type.lower()) with Spinner('Creating port mapping rules for SSH, HTTPS, and RDP'): for protocol in protocols: target_port = get_protocol_port(vm_type.lower(), protocol) portmap_payload = { 'target_addr': static_ip, 'target_port': target_port, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) message = """\n ***IMPORTANT*** DataIQ still needs to be installed on your new instance. Please refer to the DataIQ Admin guide for installation directions: https://www.dell.com/support/home/us/en/19/product-support/product/data-iq/docs """ click.secho(message, bold=True) typewriter( "\nUse 'vlab connect dataiq --name {}' to access your new DataIQ instance" .format(name))
def dns(ctx, name, image, external_network, external_netmask, default_gateway, dns_servers, static_ip): """Create a DNS server""" error = network_config_ok(static_ip, default_gateway, external_netmask) if error: raise click.ClickException(error) body = { 'network': external_network, 'name': name, 'image': image, 'static-ip': static_ip, 'default-gateway': default_gateway, 'external-netmask': external_netmask, 'dns-servers': dns_servers } resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/dns', message='Creating a new DNS server running {}'.format(image), body=body, timeout=1800, pause=5) data = resp.json()['content'][name] data['ips'] = [static_ip] vm_type = data['meta']['component'] if image.lower().startswith('windows'): protocols = ['rdp'] else: protocols = ['ssh'] with Spinner('Creating a port mapping rule for {}'.format( protocols[0].upper())): for protocol in protocols: target_port = get_protocol_port(vm_type.lower(), protocol) portmap_payload = { 'target_addr': static_ip, 'target_port': target_port, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) typewriter( "\nUse 'vlab connect dns --name {} --protocol {}' to access your new dns instance" .format(name, protocols[0]))
def claritynow(ctx, name, image, external_network): """Create an instance of ClarityNow""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/claritynow', message='Creating a new instance of ClarityNow {}'.format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: vm_type = data['meta']['component'] https_port = https_to_port(vm_type.lower()) with Spinner('Creating an SSH, RDP, and HTTPS port mapping rules'): for ipv4 in ipv4_addrs: portmap_payload = { 'target_addr': ipv4, 'target_port': 22, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) portmap_payload['target_port'] = 3389 ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) portmap_payload['target_port'] = https_port ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) info = """\n ***IMPORTANT*** ClarityNow requires a valid license to operate. Your ClarityNow server license will expire in 60 days. """ click.secho(info, bold=True) if ipv4_addrs: typewriter( "Use 'vlab connect claritynow --name {}' to access your new ClarityNow instance" .format(name))
def icap(ctx, name, image, external_network): """Create an ICAP Antivirus server""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/icap', message='Creating a new ICAP server running version {}'.format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: vm_type = data['meta']['component'] with Spinner('Creating an RDP port mapping rule'): for ipv4 in ipv4_addrs: portmap_payload = { 'target_addr': ipv4, 'target_port': 3389, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) ip_addr = ipv4_addrs[0] else: ip_addr = 'ERROR' output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) note = """\n ***IMPORTANT*** Before you can use your ICAP sever you must configure the IP the service listens on. To configure this, please open the console and: 1) Launch the McAfee admin panel (look at the task bar) 2) Right click on the ICAP service, and select "properties" 3) Update the IP to {} 4) Remember to click "OK" to save the setting """.format(ip_addr) click.secho(note, bold=True) if ipv4_addrs: typewriter( "Use 'vlab connect icap --name {}' to access your new ICAP server". format(name))
def winserver(ctx, name, image, external_network, external_netmask, default_gateway, dns_servers, static_ip): """Create a new Microsoft Server instance""" body = { 'network': external_network, 'name': name, 'image': image.upper(), # upper in case they supply 2012r2 'ip-config': { 'static-ip': static_ip, 'default-gateway': default_gateway, 'netmask': external_netmask, 'dns': dns_servers } } resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/winserver', message='Creating a new instance of Microsoft Server {}'.format(image), body=body, timeout=1800, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: vm_type = data['meta']['component'] with Spinner('Creating an RDP port mapping rule'): for ipv4 in ipv4_addrs: portmap_payload = { 'target_addr': ipv4, 'target_port': 3389, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect winserver --name {}' to access your new Microsoft Server" .format(name))
def superna(ctx, name, image, static_ip, external_netmask, default_gateway, dns_servers, domain, external_network): """Create a new Superna Eyeglass server.""" body = { 'network': external_network, 'name': name, 'image': image, 'ip-config': { 'static-ip': static_ip, 'default-gateway': default_gateway, 'netmask': external_netmask, 'dns': dns_servers, 'domain': domain } } resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/superna', message='Creating a new Superna Eyeglass server running version {}'. format(image), body=body, timeout=1800, pause=5) data = resp.json()['content'][name] vm_type = data['meta']['component'] with Spinner('Creating port a mapping rule for SSH.'): payload = { 'target_addr': static_ip, 'target_port': 22, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) msg = "Use 'vlab connect superna --name {} --protocol ssh' to setup your new Superna Eyeglass server\n".format( name) msg += "The default credentials are 'admin' and '3y3gl4ss'".format(name) typewriter(msg)
def esrs(ctx, name, image, external_network): """Create an instance of ESRS""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/esrs', message='Creating a new instance of ESRS running {}'.format(image), body=body, timeout=900, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) if ipv4_addrs: vm_type = data['meta']['component'] https_port = https_to_port(vm_type.lower()) with Spinner('Creating an SSH and HTTPS port mapping rules'): for ipv4 in ipv4_addrs: portmap_payload = { 'target_addr': ipv4, 'target_port': 22, 'target_name': name, 'target_component': vm_type } ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) portmap_payload['target_port'] = https_port ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect esrs --name {}' to access your new ESRS instance" .format(name))
def ecs(ctx, name, image, external_network, skip_config): """Create an instance of Dell EMC Elastic Cloud Storage""" body = {'network': external_network, 'name': name, 'image': image} resp = consume_task( ctx.obj.vlab_api, endpoint='/api/2/inf/ecs', message='Creating a new instance of ECS running {}'.format(image), body=body, timeout=1200, pause=5) data = resp.json()['content'][name] ipv4_addrs = get_ipv4_addrs(data['ips']) port_mapping = {} if ipv4_addrs: vm_type = data['meta']['component'] https_port = https_to_port(vm_type.lower()) with Spinner('Creating SSH and HTTPS port mapping rules'): for ipv4 in ipv4_addrs: portmap_payload = { 'target_addr': ipv4, 'target_port': 22, 'target_name': name, 'target_component': vm_type } new_port = ctx.obj.vlab_api.post( '/api/1/ipam/portmap', json=portmap_payload).json()['content']['conn_port'] port_mapping[ipv4] = new_port portmap_payload['target_port'] = https_port ctx.obj.vlab_api.post('/api/1/ipam/portmap', json=portmap_payload) if not skip_config: resp = consume_task(ctx.obj.vlab_api, endpoint='/api/2/inf/gateway', message='Looking gateway information', method='GET').json()['content'] gateway_ips = [ x for x in resp['ips'] if not x.startswith('192.168.') and not ':' in x ] if gateway_ips: gateway_ip = gateway_ips[0] else: error = "Unable to determine IP of your vLab gateway. Is it powered on?" raise click.ClickException(error) ecs_ip = _determine_ip(port_mapping.keys()) config_payload = { 'name': name, 'ssh_port': port_mapping[ecs_ip], 'gateway_ip': gateway_ip, 'ecs_ip': ecs_ip } consume_task(ctx.obj.vlab_api, endpoint='/api/2/inf/ecs/config', message='Configuring your ECS instance', method='POST', body=config_payload, base_endpoint=False, timeout=1800, pause=5) output = format_machine_info(ctx.obj.vlab_api, info=data) click.echo(output) if ipv4_addrs: typewriter( "\nUse 'vlab connect ecs --name {}' to access your new ECS instance" .format(name))