Ejemplo n.º 1
0
def create():
    from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy
    from ucsmsdk.mometa.vnic.VnicFc import VnicFc
    from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode

    mo = VnicSanConnPolicy(parent_mo_or_dn="org-root",
                           policy_owner="local",
                           name="TestSANConPolicy",
                           descr="TestSANConPolicy")
    mo_1 = VnicFc(parent_mo_or_dn=mo,
                  addr="derived",
                  name="TestWWPNForSAN",
                  admin_host_port="ANY",
                  admin_vcon="any",
                  stats_policy_name="default",
                  admin_cdn_name="",
                  switch_id="A",
                  pin_to_group_name="",
                  pers_bind="disabled",
                  pers_bind_clear="no",
                  qos_policy_name="",
                  adaptor_profile_name="",
                  ident_pool_name="test001",
                  order="1",
                  nw_templ_name="",
                  max_data_field_size="2048")
    mo_1_1 = VnicFcIf(parent_mo_or_dn=mo_1, name="default")
    mo_2 = VnicFcNode(parent_mo_or_dn=mo,
                      ident_pool_name="WWNtestPool",
                      addr="pool-derived")
    handle.add_mo(mo)
    handle.commit()
Ejemplo n.º 2
0
def modify_Fc():
    from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy
    from ucsmsdk.mometa.vnic.VnicFc import VnicFc

    mo = VnicSanConnPolicy(parent_mo_or_dn="org-root",
                           policy_owner="local",
                           name="TestSANConPolicy",
                           descr="Test SAN Connectivity Policy Change Test")
    mo_1 = VnicFc(parent_mo_or_dn=mo,
                  addr="derived",
                  name="TestvHBA001",
                  admin_host_port="ANY",
                  admin_vcon="any",
                  stats_policy_name="default",
                  admin_cdn_name="",
                  switch_id="A",
                  pin_to_group_name="",
                  pers_bind="disabled",
                  pers_bind_clear="no",
                  qos_policy_name="",
                  adaptor_profile_name="",
                  ident_pool_name="WWPNTEST001",
                  order="1",
                  nw_templ_name="",
                  max_data_field_size="2048")
    handle.add_mo(mo, True)
    handle.commit()
Ejemplo n.º 3
0
def modify_FcNode():
    from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode

    mo = VnicSanConnPolicy(parent_mo_or_dn="org-root",
                           policy_owner="local",
                           name="TestSANConPolicy",
                           descr="Test SAN Connectivity Policy")
    mo_1 = VnicFcNode(parent_mo_or_dn=mo,
                      ident_pool_name="test",
                      addr="pool-derived")
    handle.add_mo(mo, True)
    handle.commit()
Ejemplo n.º 4
0
def setup_san_connectivity(server, module):
    from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode
    from ucsmsdk.mometa.vnic.VnicFc import VnicFc
    from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf

    ansible = module.params
    args_mo  =  _get_mo_params(ansible)

    changed = False

    for san_conn in args_mo['san_conn_list']:
        exists = False
        mo = server.query_dn(args_mo['org_dn']+'/san-conn-pol-'+san_conn['name'])
        if mo:
            exists = True

        if ansible['state'] == 'absent':
            if exists:
                changed = True
                if not module.check_mode:
                    server.remove_mo(mo)
                    server.commit()
        else:
            if not exists:
                changed = True
                if not module.check_mode:
                    # create if mo does not already exist
	            mo = VnicSanConnPolicy(parent_mo_or_dn=args_mo['org_dn'],
	                                   name=san_conn['name'])
	            mo_1 = VnicFcNode(parent_mo_or_dn=mo,
	                              ident_pool_name=san_conn['wwnn_pool'],
			              addr='pool-derived')
                    for vhba in san_conn['vhba_list']:
                        mo_2 = VnicFc(parent_mo_or_dn=mo,
		                      adaptor_profile_name=vhba['adapter_policy'],
			              order=vhba['order'],
			              name=vhba['name'],
			              nw_templ_name=vhba['vhba_template'])
	                mo_2_1 = VnicFcIf(parent_mo_or_dn=mo_2, name='default')
                    server.add_mo(mo, True)
                    server.commit()
    
    return changed
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        name=dict(type='str'),
        descr=dict(type='str'),
        wwnn_pool=dict(type='str', default='default'),
        vhba_list=dict(type='list'),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
        san_connectivity_list=dict(type='list'),
    )

    # Note that use of san_connectivity_list is an experimental feature which allows multiple resource updates with a single UCSM connection.
    # Support for san_connectivity_list may change or be removed once persistent UCS connections are supported.
    # Either san_connectivity_list or name is required (user can specify either a list or single resource).

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        required_one_of=[
            ['san_connectivity_list', 'name'],
        ],
        mutually_exclusive=[
            ['san_connectivity_list', 'name'],
        ],
    )
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode
    from ucsmsdk.mometa.vnic.VnicFc import VnicFc
    from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf

    changed = False
    try:
        # Only documented use is a single resource, but to also support experimental
        # feature allowing multiple updates all params are converted to a san_connectivity_list below.

        if module.params['san_connectivity_list']:
            # directly use the list (single resource and list are mutually exclusive
            san_connectivity_list = module.params['san_connectivity_list']
        else:
            # single resource specified, create list from the current params
            san_connectivity_list = [module.params]
        for san_connectivity in san_connectivity_list:
            mo_exists = False
            props_match = False
            # set default params.  Done here to set values for lists which can't be done in the argument_spec
            if not san_connectivity.get('descr'):
                san_connectivity['descr'] = ''
            if not san_connectivity.get('wwnn_pool'):
                san_connectivity['wwnn_pool'] = 'default'
            if san_connectivity.get('vhba_list'):
                for vhba in san_connectivity['vhba_list']:
                    if not vhba.get('adapter_policy'):
                        vhba['adapter_policy'] = ''
                    if not vhba.get('order'):
                        vhba['order'] = 'unspecified'
            # dn is <org_dn>/san-conn-pol-<name>
            dn = module.params['org_dn'] + '/san-conn-pol-' + san_connectivity[
                'name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                mo_exists = True
                # check top-level mo props
                kwargs = dict(descr=san_connectivity['descr'])
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    # vnicFcNode object
                    child_dn = dn + '/fc-node'
                    mo_1 = ucs.login_handle.query_dn(child_dn)
                    if mo_1:
                        kwargs = dict(
                            ident_pool_name=san_connectivity['wwnn_pool'])
                        if (mo_1.check_prop_match(**kwargs)):
                            if not san_connectivity.get('vhba_list'):
                                props_match = True
                            else:
                                # check vnicFc props
                                for vhba in san_connectivity['vhba_list']:
                                    child_dn = dn + '/fc-' + vhba['name']
                                    mo_2 = ucs.login_handle.query_dn(child_dn)
                                    kwargs = {}
                                    kwargs['adaptor_profile_name'] = vhba[
                                        'adapter_policy']
                                    kwargs['order'] = vhba['order']
                                    kwargs['nw_templ_name'] = vhba[
                                        'vhba_template']
                                    if (mo_2.check_prop_match(**kwargs)):
                                        props_match = True

            if module.params['state'] == 'absent':
                # mo must exist but all properties do not have to match
                if mo_exists:
                    if not module.check_mode:
                        ucs.login_handle.remove_mo(mo)
                        ucs.login_handle.commit()
                    changed = True
            else:
                if not props_match:
                    if not module.check_mode:
                        # create if mo does not already exist
                        mo = VnicSanConnPolicy(
                            parent_mo_or_dn=module.params['org_dn'],
                            name=san_connectivity['name'],
                            descr=san_connectivity['descr'],
                        )
                        mo_1 = VnicFcNode(
                            parent_mo_or_dn=mo,
                            ident_pool_name=san_connectivity['wwnn_pool'],
                            addr='pool-derived',
                        )
                        if san_connectivity.get('vhba_list'):
                            for vhba in san_connectivity['vhba_list']:
                                mo_2 = VnicFc(
                                    parent_mo_or_dn=mo,
                                    name=vhba['name'],
                                    adaptor_profile_name=vhba[
                                        'adapter_policy'],
                                    nw_templ_name=vhba['vhba_template'],
                                    order=vhba['order'],
                                )
                                mo_2_1 = VnicFcIf(
                                    parent_mo_or_dn=mo_2,
                                    name='default',
                                )

                        ucs.login_handle.add_mo(mo, True)
                        ucs.login_handle.commit()
                    changed = True

    except Exception as e:
        err = True
        ucs.result['msg'] = "setup error: %s " % str(e)

    ucs.result['changed'] = changed
    if err:
        module.fail_json(**ucs.result)
    module.exit_json(**ucs.result)
Ejemplo n.º 6
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(san_connectivity_list=dict(type='list'),
                         org_dn=dict(type='str', default='org-root'),
                         name=dict(type='str'),
                         descr=dict(type='str'),
                         wwnn_pool=dict(type='str', default='default'),
                         vhba_list=dict(type='list'),
                         state=dict(type='str',
                                    default='present',
                                    choices=['present', 'absent']))
    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        required_one_of=[['san_connectivity_list', 'name']],
        mutually_exclusive=[['san_connectivity_list', 'name']])
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode
    from ucsmsdk.mometa.vnic.VnicFc import VnicFc
    from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf

    changed = False
    try:
        if module.params['san_connectivity_list']:
            # directly use the list (single resource and list are mutually exclusive
            san_connectivity_list = module.params['san_connectivity_list']
        else:
            # single resource specified, create list from the current params
            san_connectivity_list = [module.params]
        for san_connectivity in san_connectivity_list:
            exists = False
            # set default params.  Done here to set values for lists which can't be done in the argument_spec
            if not san_connectivity.get('descr'):
                san_connectivity['descr'] = ''
            if not san_connectivity.get('wwnn_pool'):
                san_connectivity['wwnn_pool'] = 'default'
            for vhba in san_connectivity['vhba_list']:
                if not vhba.get('adapter_policy'):
                    vhba['adapter_policy'] = ''
            # dn is <org_dn>/san-conn-pol-<name>
            dn = module.params['org_dn'] + '/san-conn-pol-' + san_connectivity[
                'name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                # check top-level mo props
                kwargs = {}
                kwargs['descr'] = san_connectivity['descr']
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    # vnicFcNode object
                    child_dn = dn + '/fc-node'
                    mo_1 = ucs.login_handle.query_dn(child_dn)
                    if mo_1:
                        kwargs = {}
                        kwargs['ident_pool_name'] = san_connectivity[
                            'wwnn_pool']
                        if (mo_1.check_prop_match(**kwargs)):
                            if len(san_connectivity['vhba_list']) == 0:
                                exists = True
                            else:
                                # check vnicFc props
                                for vhba in san_connectivity['vhba_list']:
                                    child_dn = dn + '/fc-' + vhba['name']
                                    mo_2 = ucs.login_handle.query_dn(child_dn)
                                    kwargs = {}
                                    kwargs['adaptor_profile_name'] = vhba[
                                        'adapter_policy']
                                    kwargs['order'] = vhba['order']
                                    kwargs['nw_templ_name'] = vhba[
                                        'vhba_template']
                                    if (mo_2.check_prop_match(**kwargs)):
                                        exists = True

            if module.params['state'] == 'absent':
                if exists:
                    if not module.check_mode:
                        ucs.login_handle.remove_mo(mo)
                        ucs.login_handle.commit()
                    changed = True
            else:
                if not exists:
                    if not module.check_mode:
                        # create if mo does not already exist
                        mo = VnicSanConnPolicy(
                            parent_mo_or_dn=module.params['org_dn'],
                            name=san_connectivity['name'],
                            descr=san_connectivity['descr'])
                        mo_1 = VnicFcNode(
                            parent_mo_or_dn=mo,
                            ident_pool_name=san_connectivity['wwnn_pool'],
                            addr='pool-derived')
                        for vhba in san_connectivity['vhba_list']:
                            mo_2 = VnicFc(
                                parent_mo_or_dn=mo,
                                name=vhba['name'],
                                adaptor_profile_name=vhba['adapter_policy'],
                                nw_templ_name=vhba['vhba_template'],
                                order=vhba['order'])
                            mo_2_1 = VnicFcIf(parent_mo_or_dn=mo_2,
                                              name='default')

                        ucs.login_handle.add_mo(mo, True)
                        ucs.login_handle.commit()
                    changed = True

    except Exception as e:
        err = True
        ucs.result['msg'] = "setup error: %s " % str(e)

    ucs.result['changed'] = changed
    if err:
        module.fail_json(**ucs.result)
    module.exit_json(**ucs.result)
Ejemplo n.º 7
0
def san_connectivity(input):
    san_connectivity = input
    results = {}
    ucs_handle = pickle.loads(
        str(
            ucs_login.main(san_connectivity['ip'],
                           san_connectivity['username'],
                           san_connectivity['password'])))

    # set default params
    if not san_connectivity.get('descr'):
        san_connectivity['descr'] = ''
    if not san_connectivity.get('wwnn_pool'):
        san_connectivity['wwnn_pool'] = 'default'
    if not san_connectivity.get('org_dn'):
        san_connectivity['org_dn'] = 'org-root'
    for vhba in san_connectivity['vhba_list']:
        if not vhba.get('adapter_policy'):
            vhba['adapter_policy'] = ''

    changed = False
    if san_connectivity['state'] == 'present':
        results['expected'] = True
    else:
        results['expected'] = False
    results['name'] = san_connectivity['name']
    try:
        exists = False
        # dn is <org_dn>/san-conn-pol-<name>
        dn = san_connectivity['org_dn'] + '/san-conn-pol-' + san_connectivity[
            'name']

        mo = ucs_handle.query_dn(dn)
        if mo:
            # check top-level mo props
            kwargs = {}
            kwargs['descr'] = san_connectivity['descr']
            if (mo.check_prop_match(**kwargs)):
                # top-level props match, check next level mo/props
                # vnicFcNode object
                child_dn = dn + '/fc-node'
                mo_1 = ucs_handle.query_dn(child_dn)
                if mo_1:
                    kwargs = {}
                    kwargs['ident_pool_name'] = san_connectivity['wwnn_pool']
                    if (mo_1.check_prop_match(**kwargs)):
                        if len(san_connectivity['vhba_list']) == 0:
                            exists = True
                        else:
                            # check vnicFc props
                            for vhba in san_connectivity['vhba_list']:
                                child_dn = dn + '/fc-' + vhba['name']
                                mo_2 = ucs.login_handle.query_dn(child_dn)
                                kwargs = {}
                                kwargs['adaptor_profile_name'] = vhba[
                                    'adapter_policy']
                                kwargs['order'] = vhba['order']
                                kwargs['nw_templ_name'] = vhba['vhba_template']
                                if (mo_2.check_prop_match(**kwargs)):
                                    exists = True

        if san_connectivity['state'] == 'absent':
            if exists:
                if not san_connectivity['check_exists']:
                    ucs_handle.remove_mo(mo)
                    ucs_handle.commit()
                changed = True
                results['removed'] = True
        else:
            # create/modify for state 'present'
            results['removed'] = False
            if not exists:
                if not san_connectivity['check_exists']:
                    # create if mo does not already exist
                    mo = VnicSanConnPolicy(
                        parent_mo_or_dn=san_connectivity['org_dn'],
                        name=san_connectivity['name'],
                        descr=san_connectivity['descr'])
                    mo_1 = VnicFcNode(
                        parent_mo_or_dn=mo,
                        ident_pool_name=san_connectivity['wwnn_pool'],
                        addr='pool-derived')
                    for vhba in san_connectivity['vhba_list']:
                        mo_2 = VnicFc(
                            parent_mo_or_dn=mo,
                            name=vhba['name'],
                            adaptor_profile_name=vhba['adapter_policy'],
                            nw_templ_name=vhba['vhba_template'],
                            order=vhba['order'])
                        mo_2_1 = VnicFcIf(parent_mo_or_dn=mo_2, name='default')

                    ucs_handle.add_mo(mo, True)
                    ucs_handle.commit()
                changed = True
                results['created'] = True

    except Exception as e:
        err = True
        results['msg'] = "setup error: %s " % str(e)

    results['changed'] = changed
    results['present'] = exists

    ucs_handle = pickle.dumps(ucs_handle)
    ucs_logout.main(ucs_handle)
    return results