Ejemplo n.º 1
0
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_schema('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)
Ejemplo n.º 2
0
# 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)

client_session.update('ipset', uri_parameters={'ipsetId': newipset_return['objectId']}, request_body_dict=newipset)
Ejemplo n.º 3
0
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'

# create new lswitch
new_ls = client_session.create('logicalSwitches', uri_parameters={'scopeId': vdn_scope},
                               request_body_dict=lswitch_create_dict)
client_session.view_response(new_ls)

# list all logical switches
all_lswitches = client_session.read('logicalSwitchesGlobal')
client_session.view_response(all_lswitches)
Ejemplo n.º 4
0
def main():
    module = AnsibleModule(
        argument_spec=dict(state=dict(default='present',
                                      choices=['present', 'absent']),
                           nsxmanager_spec=dict(required=True, no_log=True),
                           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(choices=[True, False])),
        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_schema('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)
Ejemplo n.º 5
0
def main():
    module = AnsibleModule(
        argument_spec=dict(
            state=dict(default='present', choices=['present', 'absent']),
            nsxmanager_spec=dict(required=True, no_log=True),
            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(choices=[True, False])
        ),
        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_schema('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)
Ejemplo n.º 6
0
# 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_schema(
    '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
Ejemplo n.º 7
0
# 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']

#create_response = client_session.create('vdnScopes', request_body_dict=create_body)

#TODO: Complete the tests for Scopes

Ejemplo n.º 8
0
# 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_schema('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'

time.sleep(10)
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
from nsxramlclient.client import NsxClient
import time


TRANSPORT_ZONE = 'TZ'

client_session = NsxClient(nsxraml_file, nsxmanager, nsx_username, nsx_password, debug=True)


# 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'

# create new lswitch
new_ls = client_session.create('logicalSwitches', uri_parameters={'scopeId': vdn_scope},
                               request_body_dict=lswitch_create_dict)
client_session.view_response(new_ls)

# list all logical switches
all_lswitches = client_session.read('logicalSwitchesGlobal')
client_session.view_response(all_lswitches)