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 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 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 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))