示例#1
0
def ucs_add_vsan_seperate(module):
    vsan_name = module.params.get('vsan_name')
    fcoe_vlan_a = module.params.get('fcoe_vlan_a')
    fcoe_vlan_b = module.params.get('fcoe_vlan_b')
    vsan_id_a = module.params.get('vsan_id_a')
    vsan_id_b = module.params.get('vsan_id_b')
    fc_zone_mode = module.params.get('fc_zone_mode')
    zoning_state = module.params.get('zoning_state')
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')

    ucsm = UCS(ucsm_ip, ucsm_login, ucsm_pw)

    results = {}

    # Login to UCSM
    try:
        ucsm.login()
        results['logged_in'] = True
    except Exception as e:
        module.fail_json(msg=e)



    #Setup SAN A
    mo = FabricVsan(parent_mo_or_dn="fabric/san/A", name=vsan_name, fcoe_vlan=fcoe_vlan_a, policy_owner="local",
                    fc_zone_sharing_mode=fc_zone_mode, zoning_state=zoning_state, id=vsan_id_a)

    try:
        ucsm.handle.add_mo(mo)
        results['changed'] = True

    except Exception as e:
        module.fail_json(msg="vsan for FI A configuration failed")
        results['changed'] = False




    #Setup SAN B
    mo = FabricVsan(parent_mo_or_dn="fabric/san/B", name=vsan_name, fcoe_vlan=fcoe_vlan_b, policy_owner="local",
                    fc_zone_sharing_mode=fc_zone_mode, zoning_state=zoning_state, id=vsan_id_b)

    try:
        ucsm.handle.add_mo(mo)
        results['changed'] = True

    except Exception as e:
        module.fail_json(msg=e)
        results['changed'] = False


    #Commit Changes to UCSM
    ucsm.handle.commit()


    return results
示例#2
0
def test_001_mo_to_xml():
    from ucsmsdk.mometa.fabric.FabricVsan import FabricVsan

    expected = '<fabricVsan dn="org-root/net-test" name="test" status="modified" />'

    mo = FabricVsan("org-root", "test")
    mo.status = "modified"

    elem = mo.to_xml()
    xml_str = xc.to_xml_str(elem)
    assert_equal(xml_str, expected)
示例#3
0
def test_001_mo_to_xml():
    from ucsmsdk.mometa.fabric.FabricVsan import FabricVsan

    expected = b'<fabricVsan dn="org-root/net-test" name="test" status="modified" />'

    mo = FabricVsan("org-root", "test")
    mo.status = "modified"

    elem = mo.to_xml()
    xml_str = xc.to_xml_str(elem)
    assert_equal(xml_str, expected)
示例#4
0
def ucs_add_single_vsan(module):
    configured_fi = module.params.get('configured_fi')
    vsan_name = module.params.get('vsan_name')
    vsan_id = module.params.get('vsan_id')
    fcoe_vlan = module.params.get('fcoe_vlan')
    fc_zone_mode = module.params.get('fc_zone_mode')
    zoning_state = module.params.get('zoning_state')
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')

    ucsm = UCS(ucsm_ip, ucsm_login, ucsm_pw)

    results = {}

    #Login to UCSM
    try:
        ucsm.login()
        results['logged_in'] = True
    except Exception as e:
        module.fail_json(msg=e)


    mo = FabricVsan(parent_mo_or_dn=configured_fi, name=vsan_name, fcoe_vlan=fcoe_vlan, policy_owner="local",
                    fc_zone_sharing_mode=fc_zone_mode, zoning_state=zoning_state, id=vsan_id)

    try:
        ucsm.handle.add_mo(mo)
        ucsm.handle.commit()
        results['changed'] = True

    except Exception as e:
        module.fail_json(msg=e)
        results['changed'] = False

    try:
        ucsm.handle.logout()
        results['logged_out'] = True
    except Exception as e:
        module.fail_json(msg=e)


    return results
示例#5
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        name=dict(type='str'),
        vsan_id=dict(type='str'),
        vlan_id=dict(type='str'),
        fc_zoning=dict(type='str',
                       default='disabled',
                       choices=['disabled', 'enabled']),
        fabric=dict(type='str', default='common', choices=['common', 'A',
                                                           'B']),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
        vsan_list=dict(type='list'),
    )

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

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

    err = False

    from ucsmsdk.mometa.fabric.FabricVsan import FabricVsan

    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 vsan_list below.

        if module.params['vsan_list']:
            # directly use the list (single resource and list are mutually exclusive
            vsan_list = module.params['vsan_list']
        else:
            # single resource specified, create list from the current params
            vsan_list = [module.params]
        for vsan in vsan_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 vsan.get('fc_zoning'):
                vsan['fc_zoning'] = 'disabled'
            if not vsan.get('fabric'):
                vsan['fabric'] = 'common'
            # dn is fabric/san/net-<name> for common vsans or fabric/san/[A or B]/net-<name> for A or B
            dn_base = 'fabric/san'
            if vsan['fabric'] != 'common':
                dn_base += '/' + vsan['fabric']
            dn = dn_base + '/net-' + vsan['name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                mo_exists = 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 mo_exists:
                    # check top-level mo props
                    kwargs = dict(id=vsan['vsan_id'])
                    kwargs['fcoe_vlan'] = vsan['vlan_id']
                    kwargs['zoning_state'] = vsan['fc_zoning']
                    if (mo.check_prop_match(**kwargs)):
                        props_match = True

                if not props_match:
                    if not module.check_mode:
                        # create if mo does not already exist
                        mo = FabricVsan(
                            parent_mo_or_dn=dn_base,
                            name=vsan['name'],
                            id=vsan['vsan_id'],
                            fcoe_vlan=vsan['vlan_id'],
                            zoning_state=vsan['fc_zoning'],
                        )

                        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)
示例#6
0
if needfc == "yes":
    mo = FcpoolInitiators(parent_mo_or_dn="org-root", name="UCS_WWNN", policy_owner="local", descr="", assignment_order="sequential", purpose="node-wwn-assignment")
    mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to=wwnn_to_var, r_from=wwnn_from_var)
    handle.add_mo(mo)

    
    mo = FcpoolInitiators(parent_mo_or_dn="org-root", name="WWPN_A", policy_owner="local", descr="", assignment_order="sequential", purpose="port-wwn-assignment")
    mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to=wwpn_a_to_var, r_from=wwpn_a_from_var)
    handle.add_mo(mo)
    mo = FcpoolInitiators(parent_mo_or_dn="org-root", name="WWPN_B", policy_owner="local", descr="", assignment_order="sequential", purpose="port-wwn-assignment")
    mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to=wwpn_b_to_var, r_from=wwpn_b_from_var)
    handle.add_mo(mo)

    vsananame = str(raw_input("What is the Fabric A VSAN Name?"))
    vsananumber = str(raw_input("What is the Fabric A VSAN Number?"))
    mo = FabricVsan(parent_mo_or_dn="fabric/san/A", name=vsananame, fcoe_vlan=vsananumber, policy_owner="local", fc_zone_sharing_mode="coalesce", zoning_state="disabled", id=vsananumber)
    handle.add_mo(mo)
    vsanbname = str(raw_input("What is the Fabric B VSAN Name?"))
    vsanbnumber = str(raw_input("What is the Fabric B VSAN Number?"))
    mo = FabricVsan(parent_mo_or_dn="fabric/san/B", name=vsanbname, fcoe_vlan=vsanbnumber, policy_owner="local", fc_zone_sharing_mode="coalesce", zoning_state="disabled", id=vsanbnumber)
    handle.add_mo(mo)

#CREATE VHBA TEMPLATE
    mo = VnicSanConnTempl(parent_mo_or_dn="org-root", templ_type="updating-template", name="FC_A", descr="", stats_policy_name="default", switch_id="A", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_A", max_data_field_size="2048")
    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name=vsananame)
    handle.add_mo(mo)

    mo = VnicSanConnTempl(parent_mo_or_dn="org-root", templ_type="updating-template", name="FC_B", descr="", stats_policy_name="default", switch_id="B", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_B", max_data_field_size="2048")
    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name=vsanbname)
    handle.add_mo(mo)
示例#7
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(vsan_list=dict(type='list'),
                         name=dict(type='str'),
                         vsan_id=dict(type='str'),
                         vlan_id=dict(type='str'),
                         fc_zoning=dict(type='str',
                                        default='disabled',
                                        choices=['disabled', 'enabled']),
                         fabric=dict(type='str',
                                     default='common',
                                     choices=['common', 'A', 'B']),
                         state=dict(type='str',
                                    default='present',
                                    choices=['present', 'absent']))
    module = AnsibleModule(argument_spec,
                           supports_check_mode=True,
                           required_one_of=[['vsan_list', 'name']],
                           mutually_exclusive=[['vsan_list', 'name']],
                           required_together=[['name', 'vsan_id', 'vlan_id']])
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.fabric.FabricVsan import FabricVsan

    changed = False
    try:
        if module.params['vsan_list']:
            # directly use the list (single resource and list are mutually exclusive
            vsan_list = module.params['vsan_list']
        else:
            # single resource specified, create list from the current params
            vsan_list = [module.params]
        for vsan in vsan_list:
            exists = False
            # set default params.  Done here to set values for lists which can't be done in the argument_spec
            if not vsan.get('fc_zoning'):
                vsan['fc_zoning'] = 'disabled'
            if not vsan.get('fabric'):
                vsan['fabric'] = 'common'
            # dn is fabric/san/net-<name> for common vsans or fabric/san/[A or B]/net-<name> for A or B
            dn_base = 'fabric/san'
            if vsan['fabric'] != 'common':
                dn_base += '/' + vsan['fabric']
            dn = dn_base + '/net-' + vsan['name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                # check top-level mo props
                kwargs = {}
                kwargs['id'] = vsan['vsan_id']
                kwargs['fcoe_vlan'] = vsan['vlan_id']
                kwargs['zoning_state'] = vsan['fc_zoning']
                if (mo.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 = FabricVsan(parent_mo_or_dn=dn_base,
                                        name=vsan['name'],
                                        id=vsan['vsan_id'],
                                        fcoe_vlan=vsan['vlan_id'],
                                        zoning_state=vsan['fc_zoning'])

                        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)