def main(): module = AnsibleModule(argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), name=dict(required=True), transportzone=dict(required=True), description=dict(), value=dict()), supports_check_mode=False) from nsxramlclient.client import NsxClient client_session = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) macset_id_lst = get_macset_id(client_session, module.params['name'], module.params['transportzone']) if len(macset_id_lst) is 0 and 'present' in module.params['state']: # Create a new macset new_macset = client_session.extract_resource_body_example( 'macsetScopeCreate', 'create') new_macset['macset']['name'] = module.params['name'] new_macset['macset']['description'] = module.params['description'] new_macset['macset']['value'] = module.params['value'] create_response = create_macset(client_session, new_macset, module.params['transportzone']) module.exit_json(changed=True, argument_spec=module.params, create_response=create_response) elif len(macset_id_lst) is not 0 and 'present' in module.params['state']: # Update existing macset macset_details = get_macset_details(client_session, macset_id_lst[0]) change_required = False for detail_key, detail_val in macset_details['macset'].iteritems(): if detail_key == 'description' and detail_val != module.params[ 'description']: macset_details['macset']['description'] = module.params[ 'description'] change_required = True elif detail_key == 'value' and detail_val != module.params['value']: macset_details['macset']['value'] = module.params['value'] change_required = True if change_required: ms_ops_response = change_macset_details(client_session, macset_id_lst[0], macset_details) module.exit_json(changed=True, argument_spec=module.params, ms_ops_response=ms_ops_response) else: module.exit_json(changed=False, argument_spec=module.params) elif len(macset_id_lst) is not 0 and 'absent' in module.params['state']: # Delete existing macset ms_ops_response = delete_macset(client_session, macset_id_lst[0]) module.exit_json(changed=True, argument_spec=module.params, ms_ops_response=ms_ops_response) else: module.exit_json(changed=False, argument_spec=module.params)
def return_sgs(): # Return a list of all the SGs installed in NSX Managers to_return = list() nsxmanager = config.get('nsxv', 'nsx_manager') nsxuser = config.get('nsxv', 'nsx_username') nsxpass = config.get('nsxv', 'nsx_password') nsxramlfile_dir = resource_filename(__name__, 'api_spec') nsxramlfile = '{}/nsxvapi.raml'.format(nsxramlfile_dir) # Too lazy...just hard code it for now nsxramlfile = '/usr/local/lib/python2.7/dist-packages/pynsxv/library/api_spec/nsxvapi.raml' #Connect to NSX Manager nsx_session = NsxClient(nsxramlfile, nsxmanager, nsxuser, nsxpass, debug=False) sgs = nsx_session.read('secGroupScope', uri_parameters={'scopeId': 'globalroot-0'}) # sgs = get_secgroups(nsx_session, 'globalroot-0') sgs_list = sgs.items()[1][1]['list']['securitygroup'] # print sgs_list for i, val in enumerate(sgs_list): # print i,val # print val['name'] to_return.append(val['name']) return to_return
def __init__(self, **kwargs): self._nsxraml_file = kwargs.pop('raml_file') self._nsx_password = kwargs.pop('password') self._nsx_username = kwargs.pop('username') self._nsxmanager = kwargs.pop('ip') self._client_session = NsxClient(self._nsxraml_file, self._nsxmanager, self._nsx_username, self._nsx_password) self.logger = logging.getLogger(__name__) self._cert = "" self._bfd = True self._name = ""
def main(): s = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) prep_response = cluster_prep(s, 'domain-c26') s.view_response(prep_response) wait_for_job_completion(s, prep_response['objectId'], completion_status='COMPLETED')
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True), name=dict(required=True), transportzone=dict(required=True), description=dict(), value=dict() ), supports_check_mode=False ) from nsxramlclient.client import NsxClient client_session = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) macset_id_lst = get_macset_id(client_session, module.params['name'], module.params['transportzone']) if len(macset_id_lst) is 0 and 'present' in module.params['state']: # Create a new macset new_macset = client_session.extract_resource_body_example('macsetScopeCreate', 'create') new_macset['macset']['name'] = module.params['name'] new_macset['macset']['description'] = module.params['description'] new_macset['macset']['value'] = module.params['value'] create_response = create_macset(client_session, new_macset, module.params['transportzone']) module.exit_json(changed=True, argument_spec=module.params, create_response=create_response) elif len(macset_id_lst) is not 0 and 'present' in module.params['state']: # Update existing macset macset_details = get_macset_details(client_session, macset_id_lst[0]) change_required = False for detail_key, detail_val in macset_details['macset'].iteritems(): if detail_key == 'description' and detail_val != module.params['description']: macset_details['macset']['description'] = module.params['description'] change_required = True elif detail_key == 'value' and detail_val != module.params['value']: macset_details['macset']['value'] = module.params['value'] change_required = True if change_required: ms_ops_response = change_macset_details(client_session, macset_id_lst[0], macset_details) module.exit_json(changed=True, argument_spec=module.params, ms_ops_response=ms_ops_response) else: module.exit_json(changed=False, argument_spec=module.params) elif len(macset_id_lst) is not 0 and 'absent' in module.params['state']: # Delete existing macset ms_ops_response = delete_macset(client_session, macset_id_lst[0]) module.exit_json(changed=True, argument_spec=module.params, ms_ops_response=ms_ops_response) else: module.exit_json(changed=False, argument_spec=module.params)
def _lswitch_main(args): if args.debug: debug = True else: debug = False config = ConfigParser.ConfigParser() assert config.read(args.ini), 'could not read config file {}'.format( args.ini) if args.transport_zone: transport_zone = args.transport_zone else: transport_zone = config.get('defaults', 'transport_zone') client_session = NsxClient(config.get('nsxraml', 'nsxraml_file'), config.get('nsxv', 'nsx_manager'), config.get('nsxv', 'nsx_username'), config.get('nsxv', 'nsx_password'), debug=debug) try: command_selector = { 'list': _logical_switch_list_print, 'create': _logical_switch_create, 'delete': _logical_switch_delete, 'read': _logical_switch_read, } command_selector[args.command](client_session, transport_zone=transport_zone, logical_switch_name=args.name, verbose=args.verbose) except KeyError: print('Unknown command')
def main(): module = AnsibleModule(argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), syslog_server=dict(required=True), syslog_port=dict(default=514), syslog_protocol=dict(default='udp', choices=['udp', 'tcp'])), supports_check_mode=False) from nsxramlclient.client import NsxClient client_session = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) changed = False if module.params['state'] == 'present': changed = configure_syslog_server(client_session, module.params['syslog_server'], module.params['syslog_port'], module.params['syslog_protocol']) elif module.params['state'] == 'absent': changed = delete_syslog_server(client_session) if changed: module.exit_json(changed=True) else: module.exit_json(changed=False)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'update', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), name=dict(required=True), is_group=dict(default='false', choices=['true', 'false']), role_type=dict(choices=['super_user', 'vshield_admin', 'security_admin', 'auditor', 'enterprise_admin']) ), supports_check_mode=False ) from nsxramlclient.client import NsxClient client_session = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) changed = False if module.params['state'] == 'present': changed = create_user_role(client_session, module.params['name'], module.params['role_type'], module.params['is_group']) elif module.params['state'] == 'update': changed = update_user_role(client_session, module.params['name'], module.params['role_type']) elif module.params['state'] == 'absent': changed = delete_user_role(client_session, module.params['name']) module.exit_json(changed=changed)
def _cert_main(args): if args.debug: debug = True else: debug = False config = ConfigParser.ConfigParser() assert config.read(args.ini), 'could not read config file {}'.format(args.ini) try: nsxramlfile = config.get('nsxraml', 'nsxraml_file') except (ConfigParser.NoSectionError): nsxramlfile_dir = resource_filename(__name__, 'api_spec') nsxramlfile = '{}/nsxvapi.raml'.format(nsxramlfile_dir) client_session = NsxClient(nsxramlfile, config.get('nsxv', 'nsx_manager'), config.get('nsxv', 'nsx_username'), config.get('nsxv', 'nsx_password'), debug=debug) try: command_selector = { 'create_self_signed': _create_self_signed_cert, } command_selector[args.command](client_session, cert=args.cert, scope_id=args.scope_id, private_key=args.private_key, verbose=args.verbose) except KeyError: print('Unknown command')
def main(): s = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) get_sec_group_valid_types(s) new_sec_group = empty_sec_group_create(s, 'newSecGroup') print new_sec_group sec_group_add_member(s, new_sec_group, '503bfba4-007b-0c27-aac7-26c71c1cbcff.000') get_all_sec_groups(s) add_dynamic_match(s, new_sec_group) get_sec_group_by_id(s, new_sec_group) get_sec_group_by_vm(s, 'vm-55') get_vm_in_sec_group(s, new_sec_group) get_ips_in_sec_group(s, new_sec_group) get_macs_in_sec_group(s, new_sec_group) get_vnics_in_sec_group(s, new_sec_group) time.sleep(20) sec_group_delete_member(s, new_sec_group, '503bfba4-007b-0c27-aac7-26c71c1cbcff.000') time.sleep(20) delete_sec_group(s, new_sec_group)
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), name=dict(required=True, type='str'), description=dict(type='str'), controlplanemode=dict(default='UNICAST_MODE', choices=['HYBRID_MODE', 'MULTICAST_MODE', 'UNICAST_MODE'], type='str'), cluster_moid_list=dict(required=True, type='list') ), supports_check_mode=True ) from nsxramlclient.client import NsxClient s = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) scope_state = {'absent': {'absent': state_exit_unchanged, 'present': state_delete_scope}, 'present': {'absent': state_create_scope, 'present': state_check_scope_update} } scope_state[module.params['state']][check_scope_states(s, module.params['name'])](s, module) module.exit_json(changed=False)
def _nat_main(args): if args.debug: debug = True else: debug = False config = ConfigParser.ConfigParser() assert config.read(args.ini), 'could not read config file {}'.format( args.ini) try: nsxramlfile = config.get('nsxraml', 'nsxraml_file') except (ConfigParser.NoSectionError): nsxramlfile_dir = resource_filename(__name__, 'api_spec') nsxramlfile = '{}/nsxvapi.raml'.format(nsxramlfile_dir) client_session = NsxClient(nsxramlfile, config.get('nsxv', 'nsx_manager'), config.get('nsxv', 'nsx_username'), config.get('nsxv', 'nsx_password'), debug=debug) try: command_selector = { 'add_nat': _add_nat_rule, } command_selector[args.command](client_session, esg_name=args.esg_name, original_ip=args.original_ip, translated_ip=args.translated_ip, verbose=args.verbose, nat_type=args.nat_type) except KeyError: print('Unknown command')
def main(): module = AnsibleModule(argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), nsx_edge_gateway_name=dict(required=True), app_profile_name_https=dict(required=True), app_profile_name_tcp=dict(required=True), monitor_name=dict(required=True), monitor_type=dict(required=True), monitor_interval=dict(required=True), monitor_time_out=dict(required=True), monitor_retries=dict(required=True), monitor_url_method=dict(required=True), monitor_url=dict(required=True), psc_1_http_pool_name=dict(required=True), psc_1_http_pool_member_name=dict(required=True), psc_1_http_pool_member_ip=dict(required=True), psc_1_http_pool_monitor_port=dict(required=True), psc_2_http_pool_name=dict(required=True), psc_2_http_pool_member_name=dict(required=True), psc_2_http_pool_member_ip=dict(required=True), psc_2_http_pool_monitor_port=dict(required=True), psc_1_tcp_pool_name=dict(required=True), psc_1_tcp_pool_member_name=dict(required=True), psc_1_tcp_pool_member_ip=dict(required=True), psc_1_tcp_pool_monitor_port=dict(required=True), psc_2_tcp_pool_name=dict(required=True), psc_2_tcp_pool_member_name=dict(required=True), psc_2_tcp_pool_member_ip=dict(required=True), psc_2_tcp_pool_monitor_port=dict(required=True), https_virtual_server_name=dict(required=True), virtual_ip_address=dict(required=True), https_virtual_server_port=dict(required=True), tcp_virtual_server_name=dict(required=True), tcp_virtual_server_port=dict(required=True), app_rule_name_http=dict(required=True), app_rule_name_tcp=dict(required=True), psc_password=dict(required=True), ), supports_check_mode=False) from nsxramlclient.client import NsxClient client_session = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) edge_id = get_edge_id(client_session, module.params['nsx_edge_gateway_name']) disable = disable_firewall(client_session, edge_id) cert_status = add_certificates(module, client_session, edge_id) loadBalancer_config = lb_config(client_session, module, edge_id) update_pool_res = add_pools(client_session, module, edge_id) virtual_servers = add_virtual_servers(client_session, module, edge_id) module.exit_json(changed=True, argument_spec=module.params['state'], virtual_servers=virtual_servers)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) update_locale(session) get_locale(session)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) get_notifications(session) delete_notifications(session)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) create_edge_syslog(session) get_edge_syslog(session) delete_edge_syslog(session)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) get_time_settings(session) delete_time_settings(session) update_time_settings(session)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) ospf_config = get_ospf(session) delete_ospf(session) create_ospf(session, ospf_config)
def main(): s = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) vxlan_prep_response = vxlan_prep(s, 'domain-c26', 'dvs-34', 'ipaddresspool-3') wait_for_job_completion(s, vxlan_prep_response, completion_status='COMPLETED') unprep_response = vxlan_unprep_cluster(s, 'domain-c26') wait_for_job_completion(s, unprep_response, completion_status='COMPLETED') vxlan_unprep_dvs_context(s, 'dvs-34')
def main(): module = AnsibleModule(argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), cluster_moid=dict(required=True), dvs_moid=dict(required=True), ippool_id=dict(), ippool_name=dict(), vlan_id=dict(default=0, type='int'), vmknic_count=dict(default=1), teaming=dict(default='FAILOVER_ORDER', choices=[ 'FAILOVER_ORDER', 'ETHER_CHANNEL', 'LACP_ACTIVE', 'LACP_PASSIVE', 'LOADBALANCE_SRCID', 'LOADBALANCE_SRCMAC' 'LACP_V2' ]), mtu=dict(default=1600)), mutually_exclusive=['ippool_id', 'ippool_name'], supports_check_mode=False) from nsxramlclient.client import NsxClient s = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) vxlan_status = get_cluster_status(s, module.params['cluster_moid']) if vxlan_status == 'GREEN' and module.params['state'] == 'absent': unprep_job = vxlan_unprep_cluster(s, module.params['cluster_moid']) wait_for_job_completion(s, unprep_job, completion_status='COMPLETED') vxlan_unprep_dvs_context(s, module.params['dvs_moid']) module.exit_json(changed=True) if vxlan_status != 'GREEN' and module.params['state'] == 'present': if module.params.get('ippool_name'): # TODO: Figure out a better way to handle this module.params['ippool_id'] = get_ippool_id( s, module.params['ippool_name']) if not module.params['ippool_id']: module.fail_json(msg='NSX IP pool not found - {}'.format( module.params['ippool_name'])) vxlan_prep_response = vxlan_prep( s, module.params['cluster_moid'], module.params['dvs_moid'], module.params['ippool_id'], module.params['vlan_id'], module.params['vmknic_count'], module.params['teaming'], module.params['mtu']) wait_for_job_completion(s, vxlan_prep_response, completion_status='COMPLETED') module.exit_json(changed=True, vxlan_prep_response=vxlan_prep_response) module.exit_json(changed=False, vxlan_status=vxlan_status)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) configure_dns(session) retrieve_dns(session) retrieve_dns_stats(session) delete_dns(session)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) segment_id, job_id_resp = create_segment_id(session) get_segment_id(session) get_segment_id_by_id(session, segment_id) delete_segment_id(session, segment_id)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) scope_id, job_id_resp = create_network_scope(session) get_network_scope(session) get_scope_by_id(session, scope_id) update_scope_by_id(session, scope_id) delete_network_scope(session, scope_id)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) configure_nat(session) append_nat(session) query_nat(session) rule_id = raw_input('Enter RuleID as seen in above output: ') update_nat(session, rule_id) delete_nat(session)
def main(): module = AnsibleModule(argument_spec=dict( nsxmanager_spec=dict(required=True, no_log=True, type='dict'), name=dict(required=True), mode=dict(required=True, choices=['create_pool', 'enable_service']), ip_range=dict(), default_gateway=dict(), subnet=dict(required=True), domain_name=dict(), dns_server_1=dict(), dns_server_2=dict(), lease_time=dict(), auto_dns=dict(default='false'), dhcp_enabled=dict(default='yes', choices=['yes', 'no']), syslog_enabled=dict(default='yes', choices=['yes', 'no']), syslog_level=dict(default='info', choices=[ 'emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug' ]), next_server=dict(), bootfile=dict()), supports_check_mode=False) from nsxramlclient.client import NsxClient client_session = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) changed = False edge_id, edge_params = get_edge(client_session, module.params['name']) if module.params['mode'] == 'create_pool': changed = add_dhcp_pool( client_session, module.params['name'], module.params['ip_range'], module.params['default_gateway'], module.params['subnet'], module.params['domain_name'], module.params['dns_server_1'], module.params['dns_server_2'], module.params['lease_time'], module.params['auto_dns'], module.params['next_server'], module.params['bootfile']) elif module.params['mode'] == 'enable_service': changed = dhcp_service(client_session, module.params['name'], module.params['dhcp_enabled'], module.params['syslog_enabled'], module.params['syslog_level']) if changed: module.exit_json(changed=True) else: module.exit_json(changed=False)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) object_id = create_monitor(session) get_monitor_by_id(session, object_id) get_monitors(session) update_monitor(session, object_id) delete_monitor_by_id(session, object_id) delete_monitors(session)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) security_tag_id, job_id_resp = create_security_tag(session, 'RAMLTag') get_security_tags(session) get_security_tag_by_id(session, security_tag_id) attach_security_tag(session, security_tag_id) detach_security_tag(session, security_tag_id) delete_security_tag(session, security_tag_id)
def main(): session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) object_id = create_application_rule(session) application_rule_by_id(session, object_id) application_rule(session) update_application_rule(session, object_id) delete_application_rule_by_id(session, object_id) delete_application_rule(session)
def _nat_main(args): if args.debug: debug = True else: debug = False config = ConfigParser.ConfigParser() assert config.read(args.ini), 'could not read config file {}'.format( args.ini) try: nsxramlfile = config.get('nsxraml', 'nsxraml_file') except (ConfigParser.NoSectionError): nsxramlfile_dir = resource_filename(__name__, 'api_spec') nsxramlfile = '{}/nsxvapi.raml'.format(nsxramlfile_dir) client_session = NsxClient(nsxramlfile, config.get('nsxv', 'nsx_manager'), config.get('nsxv', 'nsx_username'), config.get('nsxv', 'nsx_password'), debug=debug) try: command_selector = { 'add_nat': _add_nat_rule, # PEZ changes # New functions 'get_nat_rules_tip': _get_nat_rules_with_ip, 'delete_nat': _delete_nat_rule, } # PEZ Changes # New arguments command_selector[args.command]( client_session, esg_name=args.esg_name, original_ip=args.original_ip, translated_ip=args.translated_ip, verbose=args.verbose, nat_type=args.nat_type, original_port=args.original_port, translated_port=args.translated_port, nat_vnic=args.nat_vnic, protocol=args.protocol, description=args.description, rule_id=args.rule_id, ) except KeyError: print('Unknown command')
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), name=dict(required=True), description=dict(), transportzone=dict(required=True), controlplanemode=dict(default='UNICAST_MODE', choices=['UNICAST_MODE', 'MULTICAST_MODE', 'HYBRID_MODE']), tenant=dict() ), supports_check_mode=False ) from nsxramlclient.client import NsxClient client_session=NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) vdn_scope=retrieve_scope(module, client_session, module.params['transportzone']) lswitch_id=get_lswitch_id(client_session, module.params['name'], vdn_scope) if len(lswitch_id) is 0 and 'present' in module.params['state']: ls_ops_response=create_lswitch(client_session, module.params['name'], module.params['description'], module.params['controlplanemode'], module.params['tenant'], vdn_scope) module.exit_json(changed=True, argument_spec=module.params, ls_ops_response=ls_ops_response) elif len(lswitch_id) is not 0 and 'present' in module.params['state']: lswitch_details=get_lswitch_details(client_session,lswitch_id[0]) change_required=False for lswitch_detail_key, lswitch_detail_value in lswitch_details['virtualWire'].iteritems(): if lswitch_detail_key == 'name' and lswitch_detail_value != module.params['name']: #TODO: Check the bellow line lswitch_details['virtualWire']['name']=module.params['nsxmanager_spec']['name'] change_required=True elif lswitch_detail_key == 'description' and lswitch_detail_value != module.params['description']: lswitch_details['virtualWire']['description']=module.params['description'] change_required=True elif lswitch_detail_key == 'controlPlaneMode' and lswitch_detail_value != module.params['controlplanemode']: lswitch_details['virtualWire']['controlPlaneMode']=module.params['controlplanemode'] change_required=True if change_required: ls_ops_response=change_lswitch_details(client_session,lswitch_id[0],lswitch_details) module.exit_json(changed=True, argument_spec=module.params, ls_ops_response=ls_ops_response) else: module.exit_json(changed=False, argument_spec=module.params) elif len(lswitch_id) is not 0 and 'absent' in module.params['state']: ls_ops_response=delete_lswitch(client_session, lswitch_id[0]) module.exit_json(changed=True, argument_spec=module.params, ls_ops_response=ls_ops_response) else: module.exit_json(changed=False, argument_spec=module.params)
def main(): s = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) new_sec_policy_id = sec_empty_policy_create(s) sec_policy_read(s) sec_policy_read(s, new_sec_policy_id) sec_policy_retrieve_action(s, new_sec_policy_id) sec_policy_add_fw_rule(s, new_sec_policy_id) sec_group_id = get_sg_group_id(s, 'Test_SG') sec_policy_attach_sec_group(s, sec_group_id, new_sec_policy_id) user_yes_no_query('ready to delete created objects?') sec_policy_delete(s, new_sec_policy_id)
# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. from tests.config import * from nsxramlclient.client import NsxClient from nsxramlclient.exceptions import NsxError __author__ = 'yfauser' TRANSPORT_ZONE = 'TZ1' client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True, fail_mode='raise') lswitch_id1 = 'virtualwire-237' lswitch_id2 = 'virtualwire-999' lswitch_id3 = 'blaar' # find the objectId of the Scope with the name of the Transport Zone vdn_scopes = client_session.read('vdnScopes', 'read')['body'] vdn_scope_dict_list = [scope_dict for scope_dict in vdn_scopes['vdnScopes'].items()] vdn_scope = [scope[1]['objectId'] for scope in vdn_scope_dict_list if scope[1]['name'] == TRANSPORT_ZONE][0] # Read the properties of the logical switch new_ls_props = client_session.read('logicalSwitch', uri_parameters={'virtualWireID': lswitch_id1}) client_session.view_response(new_ls_props) # Read the property of an not existing virtual wire ID
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. __author__ = 'yfauser' from tests.config import * from nsxramlclient.client import NsxClient import time TRANSPORT_ZONE = 'TZ' client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) # find the objectId of the Scope with the name of the Transport Zone vdn_scopes = client_session.read('vdnScopes', 'read')['body'] vdn_scope_dict_list = [scope_dict for scope_dict in vdn_scopes['vdnScopes'].items()] vdn_scope = [scope[1]['objectId'] for scope in vdn_scope_dict_list if scope[1]['name'] == TRANSPORT_ZONE][0] # get a template dict for the lswitch create lswitch_create_dict = client_session.extract_resource_body_schema('logicalSwitches', 'create') client_session.view_body_dict(lswitch_create_dict) # fill the details for the new lswitch in the body dict lswitch_create_dict['virtualWireCreateSpec']['controlPlaneMode'] = 'UNICAST_MODE' lswitch_create_dict['virtualWireCreateSpec']['name'] = 'TestLogicalSwitch1' lswitch_create_dict['virtualWireCreateSpec']['tenantId'] = 'Tenant1'
# # The above copyright notice and this permission notice shall be included in all copies or substantial portions # of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. __author__ = 'yfauser' from nsxramlclient.client import NsxClient from config import * client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) # Get specific scope Information response_scope1 = client_session.read('vdnScope', uri_parameters={'scopeId': 'vdnscope-1'}) client_session.view_response(response_scope1) # Get all scopes response_all_scopes = client_session.read('vdnScopes') client_session.view_response(response_all_scopes) # Add a scope create_body = client_session.extract_resource_body_schema('vdnScopes', 'create') client_session.view_body_dict(create_body) create_body['vdnScope']['clusters']['cluster']['cluster']
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True, type='dict'), sso_lookupservice_url=dict(required=True), sso_lookupservice_port=dict(required=True), sso_lookupservice_server=dict(required=True), sso_admin_username=dict(required=True), sso_admin_password=dict(required=True, no_log=True), sso_certthumbprint=dict(), accept_all_certs=dict(type='bool') ), required_one_of = [['accept_all_certs','sso_certthumbprint']], mutually_exclusive = [['accept_all_certs','sso_certthumbprint']], supports_check_mode=False ) from nsxramlclient.client import NsxClient import OpenSSL, ssl s = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) lookup_service_full_url = 'https://{}:{}/{}'.format(module.params['sso_lookupservice_server'], module.params['sso_lookupservice_port'], module.params['sso_lookupservice_url']) sso_cert = ssl.get_server_certificate((module.params['sso_lookupservice_server'], module.params['sso_lookupservice_port']), ssl_version=2) x509_sso = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, sso_cert) sso_cert_thumbp = x509_sso.digest('sha1') if module.params['accept_all_certs']: module.params['sso_certthumbprint'] = sso_cert_thumbp if not check_sso_status(s) and module.params['state'] == 'present': sso_reg = s.extract_resource_body_example('ssoConfig', 'create') sso_reg['ssoConfig']['ssoAdminUsername'] = module.params['sso_admin_username'] sso_reg['ssoConfig']['ssoAdminUserpassword'] = module.params['sso_admin_password'] sso_reg['ssoConfig']['ssoLookupServiceUrl'] = lookup_service_full_url sso_reg['ssoConfig']['certificateThumbprint'] = module.params['sso_certthumbprint'] sso_config_response = config_sso(s, sso_reg) module.exit_json(changed=True, argument_spec=module.params, sso_config_response=sso_config_response) elif check_sso_status(s) and module.params['state'] == 'absent': sso_config_response = delete_sso_config(s) module.exit_json(changed=True, argument_spec=module.params, sso_config_response=sso_config_response) sso_config = retrieve_sso_config(s) change_required = False for ssoconfig_detail_key, ssoconfig_detail_value in sso_config['ssoConfig'].iteritems(): if ssoconfig_detail_key == 'ssoAdminUsername' and ssoconfig_detail_value != module.params['sso_admin_username']: sso_config['ssoConfig']['ssoAdminUsername'] = module.params['sso_admin_username'] change_required = True elif ssoconfig_detail_key == 'ssoLookupServiceUrl' and \ ssoconfig_detail_value != lookup_service_full_url: sso_config['ssoConfig']['ssoLookupServiceUrl'] = lookup_service_full_url change_required = True elif ssoconfig_detail_key == 'certificateThumbprint' and \ ssoconfig_detail_value != module.params['sso_certthumbprint']: sso_config['ssoConfig']['certificateThumbprint'] = module.params[' sso_certthumbprint'] change_required = True if change_required: sso_config['ssoConfig']['ssoAdminUserpassword'] = module.params['sso_admin_password'] delete_sso_config(s) sso_config_response = config_sso(s, sso_config) module.exit_json(changed=True, argument_spec=module.params, sso_config_response=sso_config_response) else: module.exit_json(changed=False, argument_spec=module.params)
# of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. __author__ = 'cmullaney' from tests.config import * from nsxramlclient.client import NsxClient import time client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) macset_dict = client_session.extract_resource_body_example('macsetScopeCreate', 'create') macset_dict['macset']['name'] = 'test0' # CREATE macset on scope newmacset_return = client_session.create('macsetScopeCreate', uri_parameters={'scopeId': 'globalroot-0'}, request_body_dict=macset_dict) # READ macset by ID newmacset = dict(client_session.read('macset', uri_parameters={'macsetId': newmacset_return['objectId']})['body']) # UPDATE macset by ID newmacset['macset']['name'] = 'test1' newmacset['macset']['revision'] = '1' newmacset['macset']['value'] = '44:55:66:77:88:99'
def main(): s = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=False) prep_response = cluster_prep(s, 'domain-c26') s.view_response(prep_response) wait_for_job_completion(s, prep_response['objectId'], completion_status='COMPLETED')
from creds import * from nsxramlclient.client import NsxClient import pprint pp = pprint.PrettyPrinter(indent=1) nsxraml_file = 'nsxraml/nsxvapiv614.raml' client_session = NsxClient(nsxraml_file, nsx_manager, nsx_username, nsx_password) vdn_scopes = client_session.read('vdnScopes', 'read') pp.pprint(vdn_scopes['body'])
def main(): module = AnsibleModule( argument_spec=dict( state=dict(default='present', choices=['present', 'absent']), nsxmanager_spec=dict(required=True, no_log=True), name=dict(required=True), start_ip=dict(required=True), end_ip=dict(required=True), prefix_length=dict(required=True), gateway=dict(), dns_server_1=dict(), dns_server_2=dict() ), supports_check_mode=False ) from nsxramlclient.client import NsxClient s = NsxClient(module.params['nsxmanager_spec']['raml_file'], module.params['nsxmanager_spec']['host'], module.params['nsxmanager_spec']['user'], module.params['nsxmanager_spec']['password']) ip_pool_objectid = get_ippool_id(s, module.params['name']) if not ip_pool_objectid and module.params['state'] == 'present': new_ip_pool = s.extract_resource_body_schema('ipPools', 'create') new_ip_pool['ipamAddressPool']['ipRanges']['ipRangeDto']['startAddress'] = module.params['start_ip'] new_ip_pool['ipamAddressPool']['ipRanges']['ipRangeDto']['endAddress'] = module.params['end_ip'] new_ip_pool['ipamAddressPool']['gateway'] = module.params['gateway'] new_ip_pool['ipamAddressPool']['prefixLength'] = module.params['prefix_length'] new_ip_pool['ipamAddressPool']['dnsServer1'] = module.params['dns_server_1'] new_ip_pool['ipamAddressPool']['dnsServer2'] = module.params['dns_server_2'] new_ip_pool['ipamAddressPool']['name'] = module.params['name'] create_response = create_ip_pool(s, new_ip_pool) module.exit_json(changed=True, argument_spec=module.params, create_response=create_response, ippool_id=create_response['objectId']) elif module.params['state'] == 'absent': if ip_pool_objectid: delete_response = delete_ip_pool(s, ip_pool_objectid) module.exit_json(changed=True, argument_spec=module.params, delete_response=delete_response) else: module.exit_json(changed=False, argument_spec=module.params) ippool_config = get_ippool_details(s, ip_pool_objectid) change_required = False for ippool_detail_key, ippool_detail_value in ippool_config['ipamAddressPool'].iteritems(): if ippool_detail_key == 'ipRanges': for range_detail_key, range_detail_value in \ ippool_config['ipamAddressPool']['ipRanges']['ipRangeDto'].iteritems(): if range_detail_key == 'startAddress' and range_detail_value != module.params['start_ip']: ippool_config['ipamAddressPool']['ipRanges']['ipRangeDto']['startAddress'] = \ module.params['start_ip'] change_required = True elif range_detail_key == 'endAddress' and range_detail_value != module.params['end_ip']: ippool_config['ipamAddressPool']['ipRanges']['ipRangeDto']['endAddress'] = \ module.params['end_ip'] change_required = True elif ippool_detail_key == 'gateway' and ippool_detail_value != module.params['gateway']: ippool_config['ipamAddressPool']['gateway'] = module.params['gateway'] change_required = True elif ippool_detail_key == 'prefixLength' and ippool_detail_value != module.params['prefix_length']: ippool_config['ipamAddressPool']['prefixLength'] = module.params['prefix_length'] change_required = True elif ippool_detail_key == 'name' and ippool_detail_value != module.params['name']: ippool_config['ipamAddressPool']['name'] = module.params['name'] change_required = True elif ippool_detail_key == 'dnsServer1' and ippool_detail_value != module.params['dns_server_1']: ippool_config['ipamAddressPool']['dnsServer1'] = module.params['dns_server_1'] change_required = True elif ippool_detail_key == 'dnsServer2' and ippool_detail_value != module.params['dns_server_2']: ippool_config['ipamAddressPool']['dnsServer2'] = module.params['dns_server_2'] change_required = True if change_required: revision = int(ippool_config['ipamAddressPool']['revision']) revision += 1 ippool_config['ipamAddressPool']['revision'] = str(revision) updateippool_response = update_ippool(s, ip_pool_objectid, ippool_config) module.exit_json(changed=True, argument_spec=module.params, update_response=updateippool_response, ippool_id=ip_pool_objectid) else: module.exit_json(changed=False, argument_spec=module.params, ippool_config=ippool_config, ippool_id=ip_pool_objectid)
# of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. __author__ = 'yfauser' from tests.config import * from nsxramlclient.client import NsxClient import time client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) ipset_dict = client_session.extract_resource_body_schema('ipsetCreate', 'create') ipset_dict['ipset']['name'] = 'Test' ipset_dict['ipset']['value'] = '192.168.1.0/24' ipset_dict['ipset']['inheritanceAllowed'] = 'True' newipset_return = client_session.create('ipsetCreate', uri_parameters={'scopeMoref': 'globalroot-0'}, request_body_dict=ipset_dict) newipset = dict(client_session.read('ipset', uri_parameters={'ipsetId': newipset_return['objectId']})['body']) newipset['ipset']['value'] = '10.0.0.0/16' newipset['ipset']['inheritanceAllowed'] = 'False' time.sleep(10)
# coding=utf-8 # # Copyright © 2015 VMware, Inc. All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated # documentation files (the "Software"), to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and # to permit persons to whom the Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions # of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. __author__ = 'yfauser' from tests.config import * from nsxramlclient.client import NsxClient client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True) print client_session.read('nwfabricFeatures') print client_session.read('nwfabricStatus', query_parameters_dict={'resource': 'domain-c1632'})