def _add_nat_rule(client_session, **kwargs): # PEZ Changes needed_params = [ 'esg_name', 'nat_type', 'nat_vnic', 'original_ip', 'translated_ip', 'original_port', 'translated_port', 'protocol', 'description' ] if not check_for_parameters(needed_params, kwargs): return None # PEZ Changes result = add_nat_rule(client_session, kwargs['esg_name'], kwargs['nat_type'], kwargs['nat_vnic'], kwargs['original_ip'], kwargs['translated_ip'], kwargs['original_port'], kwargs['translated_port'], kwargs['protocol'], kwargs['description']) if result and kwargs['verbose']: print result elif result: print '{} Rule created on edge {} for {} -> {}'.format( kwargs['nat_type'].upper(), kwargs['esg_name'], kwargs['original_ip'], kwargs['translated_ip']) else: print '{} Rule creation failed on edge {} for {} -> {}'.format( kwargs['nat_type'].upper(), kwargs['esg_name'], kwargs['original_ip'], kwargs['translated_ip'])
def _add_dhcp_pool(client_session, **kwargs): needed_params = ['esg_name', 'ip_range'] if not check_for_parameters(needed_params, kwargs): return None if kwargs['auto_dns'] != 'true': auto_dns = 'false' else: auto_dns = 'true' result = add_dhcp_pool(client_session, kwargs['esg_name'], kwargs['ip_range'], default_gateway=kwargs['default_gateway'], subnet_mask=kwargs['subnet_mask'], domain_name=kwargs['domain_name'], dns_server_1=kwargs['dns_server_1'], dns_server_2=kwargs['dns_server_2'], lease_time=kwargs['lease_time'], auto_dns=auto_dns) if result and kwargs['verbose']: print result elif result: print 'IP Pool configuration on esg {} succeeded, the DHCP Pool Id is {}'.format( kwargs['esg_name'], result) else: print 'IP Pool configuration on esg {} failed'.format( kwargs['esg_name'])
def _add_vm_binding(client_session, vccontent, **kwargs): needed_params = ['esg_name', 'vm_name', 'vnic_id', 'hostname', 'ip'] if not check_for_parameters(needed_params, kwargs): return None if kwargs['auto_dns'] != 'true': auto_dns = 'false' else: auto_dns = 'true' vm_id = get_vm_by_name(vccontent, kwargs['vm_name']) if not vm_id: print 'Static binding configuration on esg {} failed, VM {} not found'.format(kwargs['esg_name'], kwargs['vm_name']) return None result = add_vm_binding(client_session, kwargs['esg_name'], vm_id, kwargs['vnic_id'], kwargs['hostname'], kwargs['ip'], default_gateway=kwargs['default_gateway'], subnet_mask=kwargs['subnet_mask'], domain_name=kwargs['domain_name'], dns_server_1=kwargs['dns_server_1'], dns_server_2=kwargs['dns_server_2'], lease_time=kwargs['lease_time'], auto_dns=auto_dns) if result and kwargs['verbose']: print result elif result: print 'Static binding configuration on esg {} succeeded, the Binding Id is {}'.format(kwargs['esg_name'], result) else: print 'Static binding configuration on esg {} failed'.format(kwargs['esg_name'])
def _esg_read(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None esg_id, esg_params = esg_read(client_session, kwargs['esg_name']) if esg_params and kwargs['verbose']: print json.dumps(esg_params) elif esg_id: print 'Edge Services Gateway {} has the ID {}'.format(kwargs['esg_name'], esg_id) else: print 'Edge Services Gateway {} not found'.format(kwargs['esg_name'])
def _esg_dgw_clear(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = esg_dgw_clear(client_session, kwargs['esg_name']) if result: print 'Edge Services Router {} default gateway cleared'.format(kwargs['esg_name']) else: print 'Edge Services Router {} clearing the default gateway config failed'.format(kwargs['esg_name'])
def _disable_server(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = dhcp_server(client_session, kwargs['esg_name'], enabled=False) if not result: print 'Disabling DHCP on Edge Services Gateway {} failed'.format(kwargs['esg_name']) else: print 'Disabling DHCP on Edge Services Gateway {} succeeded'.format(kwargs['esg_name'])
def _delete_dhcp_binding(client_session, **kwargs): needed_params = ['esg_name', 'binding_id'] if not check_for_parameters(needed_params, kwargs): return None result = delete_dhcp_binding(client_session, kwargs['esg_name'], kwargs['binding_id']) if result: print 'Deleting DHCP binding {} on esg {} succeeded'.format(kwargs['binding_id'], kwargs['esg_name']) else: print 'Deleting DHCP binding {} on esg {} failed'.format(kwargs['binding_id'], kwargs['esg_name'])
def _esg_dgw_set(client_session, **kwargs): needed_params = ['esg_name', 'next_hop'] if not check_for_parameters(needed_params, kwargs): return None result = esg_dgw_set(client_session, kwargs['esg_name'], kwargs['next_hop'], kwargs['vnic_index']) if result: print 'Edge Services Router {} default gateway config succeeded'.format(kwargs['esg_name']) else: print 'Edge Services Router {} default gateway config failed'.format(kwargs['esg_name'])
def _esg_delete(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None esg_name = kwargs['esg_name'] result, dlr_id = esg_delete(client_session, esg_name) if result and kwargs['verbose']: return json.dumps(dlr_id) elif result: print 'Edge Services Router {} with the ID {} has been deleted'.format(esg_name, dlr_id) else: print 'Edge Services Router deletion failed'
def _esg_fw_default_set(client_session, **kwargs): needed_params = ['esg_name', 'fw_default'] if not check_for_parameters(needed_params, kwargs): return None result = esg_fw_default_set(client_session, kwargs['esg_name'], kwargs['fw_default']) if result: print 'Default firewall policy on Edge Services Router {} set to {}'.format(kwargs['esg_name'], kwargs['fw_default']) else: print 'Setting default firewall policy on Edge Services Router {} failed'.format(kwargs['esg_name'])
def _enable_server(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = dhcp_server(client_session, kwargs['esg_name'], enabled=True, syslog_enabled=kwargs['logging'], syslog_level=kwargs['log_level']) if not result: print 'Enabling DHCP on Edge Services Gateway {} failed'.format(kwargs['esg_name']) else: print 'Enabling DHCP on Edge Services Gateway {} succeeded'.format(kwargs['esg_name'])
def _list_dhcp_pools(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None ip_pool_list, ip_pool_verbose = list_dhcp_pools(client_session, kwargs['esg_name']) if kwargs['verbose']: print json.dumps(ip_pool_verbose) else: print tabulate(ip_pool_list, headers=["Pool ID", "IP Range", "Gateway", "Subnet Mask", "Domain Name", "DNS 1", "DNS 2", "Lease Time", "Auto Config DNS"], tablefmt="psql")
def _esg_fw_default_set(client_session, **kwargs): needed_params = ['esg_name', 'fw_default'] if not check_for_parameters(needed_params, kwargs): return None result = esg_fw_default_set(client_session, kwargs['esg_name'], kwargs['fw_default'], logging_enabled='true') if result: print 'Default firewall policy on Edge Services Router {} set to {}'.format(kwargs['esg_name'], kwargs['fw_default']) else: print 'Setting default firewall policy on Edge Services Router {} failed'.format(kwargs['esg_name'])
def _esg_route_del(client_session, **kwargs): needed_params = ['esg_name', 'next_hop', 'route_net'] if not check_for_parameters(needed_params, kwargs): return None result = esg_route_del(client_session, kwargs['esg_name'], kwargs['route_net'], kwargs['next_hop']) if result: print 'Deletion of route {} on Edge Services Router {} succeeded'.format(kwargs['route_net'], kwargs['esg_name']) else: print 'Deletion of route {} on Edge Services Router {} failed'.format(kwargs['route_net'], kwargs['esg_name'])
def _esg_clear_interface(client_session, **kwargs): needed_params = ['vnic_index', 'esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = esg_clear_interface(client_session, kwargs['esg_name'], kwargs['vnic_index']) if result: print 'Edge Services Router {} vnic{} configuration has been cleared'.format(kwargs['esg_name'], kwargs['vnic_index']) else: print 'Edge Services Router {} vnic{} configuration failed'.format(kwargs['esg_name'], kwargs['vnic_index'])
def _esg_route_add(client_session, **kwargs): needed_params = ['esg_name', 'next_hop', 'route_net'] if not check_for_parameters(needed_params, kwargs): return None result = esg_route_add(client_session, kwargs['esg_name'], kwargs['route_net'], kwargs['next_hop'], vnic=kwargs['vnic_index']) if result: print 'Added route {} to Edge Services Router {}'.format(kwargs['route_net'], kwargs['esg_name']) else: print 'Addition of route {} to Edge Services Router {} failed'.format(kwargs['route_net'], kwargs['esg_name'])
def _esg_route_add(client_session, **kwargs): needed_params = ['esg_name', 'next_hop', 'route_net'] if not check_for_parameters(needed_params, kwargs): return None result = esg_route_add(client_session, kwargs['esg_name'], kwargs['route_net'], kwargs['next_hop'], kwargs['vnic_index']) if result: print 'Added route {} to Edge Services Router {}'.format(kwargs['route_net'], kwargs['esg_name']) else: print 'Addition of route {} to Edge Services Router {} failed'.format(kwargs['route_net'], kwargs['esg_name'])
def _esg_route_list(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None routes, rtg_cfg = esg_route_list(client_session, kwargs['esg_name']) if rtg_cfg and kwargs['verbose']: print json.dumps(rtg_cfg) elif routes: print tabulate(routes, headers=["network", "next-hop", "vnic", "admin distance", "mtu"], tablefmt="psql") else: print 'Failed to get static roues of Edge {}'.format(kwargs['esg_name'])
def _esg_dgw_read(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None dgw_cfg_tpl, rtg_cfg = esg_dgw_read(client_session, kwargs['esg_name']) if rtg_cfg and kwargs['verbose']: print json.dumps(rtg_cfg) elif dgw_cfg_tpl: print tabulate(dgw_cfg_tpl, headers=["vNic", "Gateway IP", "Admin Distance", "MTU"], tablefmt="psql") else: print 'Failed to get default gateway info of Edge {}'.format(kwargs['esg_name'])
def _create_self_signed_cert(client_session, **kwargs): needed_params = ['scope_id', 'cert', 'private_key'] if not check_for_parameters(needed_params, kwargs): return None result = create_self_signed_cert(client_session, kwargs['scope_id'], kwargs['cert'], kwargs['private_key']) if result and kwargs['verbose']: print result elif result: print 'Certifcate {} created in scope {}'.format(result, kwargs['scope_id']) else: print 'Certifcate creation failed in scope {}'.format(kwargs['scope_id'])
def _list_dhcp_bindings(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None bindings, bindings_verbose = list_dhcp_bindings(client_session, kwargs['esg_name']) if kwargs['verbose']: print json.dumps(bindings_verbose) else: print tabulate(bindings, headers=["Binding ID", "MAC", "VM Id", "vnic Index", "Hostname", "IP", "Default Gw", "Subnet Mask", "Domain Name", "DNS 1", "DNS 2", "Lease Time", "Auto Config DNS"], tablefmt="psql")
def _esg_list_interfaces(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None esg_int_list, esg_int_list_verbose = esg_list_interfaces(client_session, kwargs['esg_name']) if esg_int_list_verbose and kwargs['verbose']: print json.dumps(esg_int_list_verbose) elif esg_int_list: print tabulate(esg_int_list, headers=["Vnic name", "Vnic ID", "Vnic IP", "Vnic subnet", "Connected To", "Secondary IPs"], tablefmt="psql") else: print 'Failed to get interface list of Edge {}'.format(kwargs['esg_name'])
def _disable_server(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = dhcp_server(client_session, kwargs['esg_name'], enabled=False) if not result: print 'Disabling DHCP on Edge Services Gateway {} failed'.format( kwargs['esg_name']) else: print 'Disabling DHCP on Edge Services Gateway {} succeeded'.format( kwargs['esg_name'])
def _create_fw_rule(client_session, vccontent, **kwargs): needed_params = ['rule_src', 'rule_dst', 'rule_app', 'rule_action', 'rule_description' ] if not check_for_parameters(needed_params, kwargs): return None result, rule_id = create_fw_rule(client_session, vccontent, kwargs['esg_name'], kwargs['rule_src'], kwargs['rule_dst'], kwargs['rule_app'], kwargs['rule_action'],kwargs['rule_description']) if kwargs['verbose'] and result and esg_id: edge_id, esg_details = esg_read(client_session, esg_id) print json.dumps(esg_details) elif result and rule_id: print 'Rule {} created on Edge Service Gateway'.format(rule_id) else: print 'Rule creation failed on Edge Service Gateway'
def _create_ipset(client_session, vccontent, **kwargs): needed_params = ['esg_name', 'ipset_name', 'ipset_value'] if not check_for_parameters(needed_params, kwargs): return None result, esg_id = create_ipset(client_session, kwargs['esg_name'], kwargs['ipset_name'], kwargs['ipset_value']) if kwargs['verbose'] and result and esg_id: edge_id, esg_details = esg_read(client_session, esg_id) print json.dumps(esg_details) elif result and esg_id: print '{} created on Edge Service Gateway'.format(kwargs['ipset_name']) else: print '{} creation failed on Edge Service Gateway'.format(kwargs['ipset_name'])
def _delete_nat_rule(client_session, **kwargs): needed_params = ['esg_name', 'rule_id'] if not check_for_parameters(needed_params, kwargs): return None result = delete_nat_rule(client_session, kwargs['esg_name'], kwargs['rule_id']) if result and kwargs['verbose']: print result elif result: print 'NAT rule {} on edge {} deleted'.format(kwargs['rule_id'], kwargs['esg_name']) else: print 'Failed to delete NAT rule {} on {}'.format(kwargs['rule_id'], kwargs['esg_name'])
def _delete_dhcp_binding(client_session, **kwargs): needed_params = ['esg_name', 'binding_id'] if not check_for_parameters(needed_params, kwargs): return None result = delete_dhcp_binding(client_session, kwargs['esg_name'], kwargs['binding_id']) if result: print 'Deleting DHCP binding {} on esg {} succeeded'.format( kwargs['binding_id'], kwargs['esg_name']) else: print 'Deleting DHCP binding {} on esg {} failed'.format( kwargs['binding_id'], kwargs['esg_name'])
def _routing_ospf(client_session, vccontent, **kwargs): needed_params = ['esg_name', 'vnic_ip', 'area_id', 'auth_type', 'auth_value'] if not check_for_parameters(needed_params, kwargs): return None result, esg_id = routing_ospf(client_session, kwargs['esg_name'], kwargs['vnic_ip'], kwargs['area_id'], kwargs['auth_type'], kwargs['auth_value']) if kwargs['verbose'] and result and esg_id: edge_id, esg_details = esg_read(client_session, esg_id) print json.dumps(esg_details) elif result and esg_id: print 'Edge Service Gateway {} configured for OSPF'.format(kwargs['esg_name'], esg_id) else: print 'Edge Service Gateway {} configuration of OSPF failed'.format(kwargs['esg_name'])
def _get_nat_rules_with_ip(client_session, **kwargs): needed_params = ['esg_name', 'original_ip','translated_ip'] if not check_for_parameters(needed_params, kwargs): return None result = get_nat_rules_with_ip(client_session, kwargs['esg_name'], kwargs['original_ip'], kwargs['translated_ip']) if result and kwargs['verbose']: print result elif result: for i in result: print i else: print 'Failed to get NAT rules for {} on {}'.format(kwargs['translated_ip'], kwargs['esg_name'])
def _create_ip_block(client, **kwargs): needed_params = ['name', 'cidr'] if not check_for_parameters(needed_params, kwargs): return None result = create_ip_block(client, kwargs['name'], kwargs['cidr'], kwargs['tag']) if result and kwargs['verbose']: print result elif result: print 'IP Block {} created with CIDR {}'.format( kwargs['name'], kwargs['cidr']) else: print 'Creation of IP Block {} failed for CIDR {}'.format( kwargs['name'], kwargs['cidr'])
def _create_router(client, **kwargs): needed_params = ['router_type', 'name'] if not check_for_parameters(needed_params, kwargs): return None result = create_router(client, kwargs['name'], kwargs['router_type'], kwargs['edge_cluster'], kwargs['t0'], kwargs['tag']) if result and kwargs['verbose']: print result elif result: print '{} router {} created'.format(kwargs['router_type'], kwargs['name']) else: print 'Creation of {} router {} failed'.format(kwargs['router_type'], kwargs['name'])
def _create_switch(client, **kwargs): needed_params = ['transport_zone', 'name'] if not check_for_parameters(needed_params, kwargs): return None result = create_switch(client, kwargs['name'], kwargs['transport_zone'], kwargs['vlan']) if result and kwargs['verbose']: print result elif result: print 'Switch {} created in Transport Zone {}'.format( kwargs['name'], kwargs['transport_zone']) else: print 'Creation of switch {} failed in Transport Zone {}'.format( kwargs['name'], kwargs['transport_zone'])
def _create_static_route(client, **kwargs): needed_params = ['logical_router', 'network', 'next_hop'] if not check_for_parameters(needed_params, kwargs): return None result = create_static_route(client, kwargs['logical_router'], kwargs['network'], kwargs['next_hop']) if result and kwargs['verbose']: print result elif result: print 'Static route created on {} from {} to {}'.format( kwargs['logical_router'], kwargs['network'], kwargs['next_hop']) else: print 'Creation of static route on {} from {} to {} failed'.format( kwargs['logical_router'], kwargs['network'], kwargs['next_hop'])
def _read(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = read(client_session, kwargs['esg_name']) if result and kwargs['verbose']: print json.dumps(result) elif result: print tabulate([(result['dhcp']['enabled'], result['dhcp']['logging']['enable'], result['dhcp']['logging']['logLevel'])], headers=["DHCP Enabled", "Logging Enabled", "Log Level"], tablefmt="psql") else: print 'Failed to get DHCP status from Edge Services Gateway {}'.format(kwargs['esg_name'])
def _enable_server(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = dhcp_server(client_session, kwargs['esg_name'], enabled=True, syslog_enabled=kwargs['logging'], syslog_level=kwargs['log_level']) if not result: print 'Enabling DHCP on Edge Services Gateway {} failed'.format( kwargs['esg_name']) else: print 'Enabling DHCP on Edge Services Gateway {} succeeded'.format( kwargs['esg_name'])
def _esg_cfg_interface(client_session, vccontent, **kwargs): needed_params = ['vnic_index', 'esg_name'] if not check_for_parameters(needed_params, kwargs): return None if kwargs['logical_switch'] and kwargs['portgroup']: print 'Both a logical switch and a portgroup were specified, please only specify one of these values' return None if kwargs['logical_switch']: lsid, lsparams = get_logical_switch(client_session, kwargs['logical_switch']) portgroup = lsid elif kwargs['portgroup']: pgid = get_vdsportgroupid(vccontent, kwargs['portgroup']) portgroup = pgid else: portgroup = None if kwargs['vnic_ip']: if not kwargs['vnic_mask']: print 'You need to specify a netmask when configuring an IP Address on the Interface' return None try: pflen_int = int(kwargs['vnic_mask']) prefixlen = pflen_int netmask = None except ValueError: netmask = kwargs['vnic_mask'] prefixlen = None else: netmask = None prefixlen = None secondary_ips = None if kwargs['vnic_secondary_ips']: secondary_ips = kwargs['vnic_secondary_ips'].split(',') result = esg_cfg_interface(client_session, kwargs['esg_name'], kwargs['vnic_index'], name=kwargs['vnic_name'], vnic_type=kwargs['vnic_type'], portgroup_id=portgroup, is_connected=kwargs['vnic_state'], ipaddr=kwargs['vnic_ip'], netmask=netmask, prefixlen=prefixlen, secondary_ips=secondary_ips) if result: print 'Edge Services Router {} vnic{} has been configured'.format(kwargs['esg_name'], kwargs['vnic_index']) else: print 'Edge Services Router {} vnic{} configuration failed'.format(kwargs['esg_name'], kwargs['vnic_index'])
def _esg_cfg_interface(client_session, vccontent, **kwargs): needed_params = ['vnic_index', 'esg_name'] if not check_for_parameters(needed_params, kwargs): return None if kwargs['logical_switch'] and kwargs['portgroup']: print 'Both a logical switch and a portgroup were specified, please only specify one of these values' return None if kwargs['logical_switch']: lsid, lsparams = get_logical_switch(client_session, kwargs['logical_switch']) portgroup = lsid elif kwargs['portgroup']: pgid = get_vdsportgroupid(vccontent, kwargs['portgroup']) portgroup = pgid else: portgroup = None if kwargs['vnic_ip']: if not kwargs['vnic_mask']: print 'You need to specify a netmask when configuring an IP Address on the Interface' return None try: pflen_int = int(kwargs['vnic_mask']) prefixlen = pflen_int netmask = None except ValueError: netmask = kwargs['vnic_mask'] prefixlen = None else: netmask = None prefixlen = None secondary_ips = None if kwargs['vnic_secondary_ips']: secondary_ips = kwargs['vnic_secondary_ips'].split(',') result = esg_cfg_interface(client_session, kwargs['esg_name'], kwargs['vnic_index'], name=kwargs['vnic_name'], vnic_type=kwargs['vnic_type'], portgroup_id=portgroup, is_connected=kwargs['vnic_state'], ipaddr=kwargs['vnic_ip'], netmask=netmask, prefixlen=prefixlen, secondary_ips=secondary_ips, enable_send_redirects='false') if result: print 'Edge Services Router {} vnic{} has been configured'.format(kwargs['esg_name'], kwargs['vnic_index']) else: print 'Edge Services Router {} vnic{} configuration failed'.format(kwargs['esg_name'], kwargs['vnic_index'])
def _list_dhcp_pools(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None ip_pool_list, ip_pool_verbose = list_dhcp_pools(client_session, kwargs['esg_name']) if kwargs['verbose']: print json.dumps(ip_pool_verbose) else: print tabulate(ip_pool_list, headers=[ "Pool ID", "IP Range", "Gateway", "Subnet Mask", "Domain Name", "DNS 1", "DNS 2", "Lease Time", "Auto Config DNS" ], tablefmt="psql")
def _read(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None result = read(client_session, kwargs['esg_name']) if result and kwargs['verbose']: print json.dumps(result) elif result: print tabulate( [(result['dhcp']['enabled'], result['dhcp']['logging']['enable'], result['dhcp']['logging']['logLevel'])], headers=["DHCP Enabled", "Logging Enabled", "Log Level"], tablefmt="psql") else: print 'Failed to get DHCP status from Edge Services Gateway {}'.format( kwargs['esg_name'])
def _list_dhcp_bindings(client_session, **kwargs): needed_params = ['esg_name'] if not check_for_parameters(needed_params, kwargs): return None bindings, bindings_verbose = list_dhcp_bindings(client_session, kwargs['esg_name']) if kwargs['verbose']: print json.dumps(bindings_verbose) else: print tabulate(bindings, headers=[ "Binding ID", "MAC", "VM Id", "vnic Index", "Hostname", "IP", "Default Gw", "Subnet Mask", "Domain Name", "DNS 1", "DNS 2", "Lease Time", "Auto Config DNS" ], tablefmt="psql")
def _esg_create(client_session, vccontent, **kwargs): needed_params = ['esg_name', 'esg_size', 'esg_pwd', 'datacenter_name', 'edge_datastore', 'edge_cluster', 'portgroup'] if not check_for_parameters(needed_params, kwargs): return None datacentermoid = get_datacentermoid(vccontent, kwargs['datacenter_name']) datastoremoid = get_datastoremoid(vccontent, kwargs['edge_datastore']) resourcepoolid = get_edgeresourcepoolmoid(vccontent, kwargs['edge_cluster']) portgroupmoid = get_vdsportgroupid(vccontent, kwargs['portgroup']) esg_id, esg_params = esg_create(client_session, kwargs['esg_name'], kwargs['esg_pwd'], kwargs['esg_size'], datacentermoid, datastoremoid, resourcepoolid, portgroupmoid, esg_remote_access=kwargs['esg_remote_access']) if kwargs['verbose'] and esg_id: edge_id, esg_details = esg_read(client_session, esg_id) print json.dumps(esg_details) elif esg_id: print 'Edge Service Gateway {} created with the ID {}'.format(kwargs['esg_name'], esg_id) else: print 'Edge Service Gateway {} creation failed'.format(kwargs['esg_name'])
def _add_dhcp_pool(client_session, **kwargs): needed_params = ['esg_name', 'ip_range'] if not check_for_parameters(needed_params, kwargs): return None if kwargs['auto_dns'] != 'true': auto_dns = 'false' else: auto_dns = 'true' result = add_dhcp_pool(client_session, kwargs['esg_name'], kwargs['ip_range'], default_gateway=kwargs['default_gateway'], subnet_mask=kwargs['subnet_mask'], domain_name=kwargs['domain_name'], dns_server_1=kwargs['dns_server_1'], dns_server_2=kwargs['dns_server_2'], lease_time=kwargs['lease_time'], auto_dns=auto_dns) if result and kwargs['verbose']: print result elif result: print 'IP Pool configuration on esg {} succeeded, the DHCP Pool Id is {}'.format(kwargs['esg_name'], result) else: print 'IP Pool configuration on esg {} failed'.format(kwargs['esg_name'])