예제 #1
0
def setup_wwn(server, module):
    from ucsmsdk.mometa.fcpool.FcpoolInitiators import FcpoolInitiators
    from ucsmsdk.mometa.fcpool.FcpoolBlock import FcpoolBlock

    ansible = module.params
    args_mo = _get_mo_params(ansible)

    changed = False

    for wwn in args_mo['wwn_list']:
        exists = False
        mo = server.query_dn(args_mo['org_dn'] + '/wwn-pool-' + wwn['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 = FcpoolInitiators(parent_mo_or_dn=args_mo['org_dn'],
                                          name=wwn['name'],
                                          assignment_order=wwn['order'],
                                          purpose=wwn['purpose'])
                    if (wwn['to'] <> '' and wwn['from'] <> ''):
                        mo_1 = FcpoolBlock(parent_mo_or_dn=mo,
                                           to=wwn['to'],
                                           r_from=wwn['from'])
                    server.add_mo(mo)
                    server.commit()

    return changed
예제 #2
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        name=dict(type='str'),
        purpose=dict(type='str', choices=['node', 'port']),
        descr=dict(type='str'),
        order=dict(type='str',
                   default='default',
                   choices=['default', 'sequential']),
        first_addr=dict(type='str'),
        last_addr=dict(type='str'),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
        wwn_list=dict(type='list'),
    )

    # Note that use of wwn_list is an experimental feature which allows multiple resource updates with a single UCSM connection.
    # Support for wwn_list may change or be removed once persistent UCS connections are supported.
    # Either wwn_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=[['wwn_list', 'name']],
        mutually_exclusive=[['wwn_list', 'name']],
    )
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.fcpool.FcpoolInitiators import FcpoolInitiators
    from ucsmsdk.mometa.fcpool.FcpoolBlock import FcpoolBlock

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

        if module.params['wwn_list']:
            # directly use the list (single resource and list are mutually exclusive
            wwn_list = module.params['wwn_list']
        else:
            # single resource specified, create list from the current params
            wwn_list = [module.params]
        for wwn in wwn_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 wwn.get('descr'):
                wwn['descr'] = ''
            if not wwn.get('order'):
                wwn['order'] = 'default'
            # dn is <org_dn>/wwn-pool-<name> for WWNN or WWPN
            dn = module.params['org_dn'] + '/wwn-pool-' + wwn['name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                mo_exists = True

            if module.params['state'] == 'absent':
                if mo_exists:
                    if not module.check_mode:
                        ucs.login_handle.remove_mo(mo)
                        ucs.login_handle.commit()
                    changed = True
            else:
                # append purpose param with suffix used by UCSM
                purpose_param = wwn['purpose'] + '-wwn-assignment'
                if mo_exists:
                    # check top-level mo props
                    kwargs = dict(assignment_order=wwn['order'])
                    kwargs['descr'] = wwn['descr']
                    kwargs['purpose'] = purpose_param
                    if (mo.check_prop_match(**kwargs)):
                        # top-level props match, check next level mo/props
                        if 'last_addr' in wwn and 'first_addr' in wwn:
                            block_dn = dn + '/block-' + wwn['first_addr'].upper(
                            ) + '-' + wwn['last_addr'].upper()
                            mo_1 = ucs.login_handle.query_dn(block_dn)
                            if mo_1:
                                props_match = True
                        else:
                            props_match = True

                if not props_match:
                    if not module.check_mode:
                        # create if mo does not already exist
                        mo = FcpoolInitiators(
                            parent_mo_or_dn=module.params['org_dn'],
                            name=wwn['name'],
                            descr=wwn['descr'],
                            assignment_order=wwn['order'],
                            purpose=purpose_param,
                        )
                        if 'last_addr' in wwn and 'first_addr' in wwn:
                            mo_1 = FcpoolBlock(
                                parent_mo_or_dn=mo,
                                to=wwn['last_addr'],
                                r_from=wwn['first_addr'],
                            )

                        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)
예제 #3
0
    handle.commit()
    mo = MacpoolPool(parent_mo_or_dn=my_Full_Path_Org, policy_owner="local", descr="iSCSI FI-B", assignment_order="sequential", name="iSCSI-B")
    mo_1 = MacpoolBlock(parent_mo_or_dn=mo, to="00:25:B5:B3:00:0F", r_from="00:25:B5:B3:00:00")
    handle.add_mo(mo)
    handle.commit()
#End Create MAC Pools

#Create Network Control Policy
mo = NwctrlDefinition(parent_mo_or_dn=my_Full_Path_Org, lldp_transmit="disabled", name="CDP_EN", lldp_receive="disabled", mac_register_mode="only-native-vlan", policy_owner="local", cdp="enabled", uplink_fail_action="link-down", descr="CDP Enable")
mo_1 = DpsecMac(parent_mo_or_dn=mo, forge="allow", policy_owner="local", name="", descr="")
handle.add_mo(mo)
handle.commit()

#FC WWNN and WWPN Pools
if(FC):
        mo = FcpoolInitiators(parent_mo_or_dn=my_Full_Path_Org, name="WWNN_Pool", policy_owner="local", descr="WWNN Pool", assignment_order="sequential", purpose="node-wwn-assignment")
        mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to="20:00:00:25:B5:A0:00:FF", r_from="20:00:00:25:B5:A0:00:00")
        handle.add_mo(mo)
        handle.commit()

        mo = FcpoolInitiators(parent_mo_or_dn=my_Full_Path_Org, name="WWPN_Pool-A", policy_owner="local", descr="WWPN Pool FI-A", assignment_order="sequential", purpose="port-wwn-assignment")
        mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to="20:01:00:25:B5:A0:00:0F", r_from="20:01:00:25:B5:A0:00:00")
        handle.add_mo(mo)
        handle.commit()

        mo = FcpoolInitiators(parent_mo_or_dn=my_Full_Path_Org, name="WWPN_Pool-B", policy_owner="local", descr="WWPN Pool FI-B", assignment_order="sequential", purpose="port-wwn-assignment")
        mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to="20:01:00:25:B5:B0:00:0F", r_from="20:01:00:25:B5:B0:00:00")
        handle.add_mo(mo)
        handle.commit()

#Create vNIC Templates
예제 #4
0
mo_1 = VnicEtherIf(parent_mo_or_dn=mo, default_net="yes", name="VLAN_200")
mo_2 = VnicEtherIf(parent_mo_or_dn=mo, default_net="no", name="VLAN_800")
handle.add_mo(mo)
handle.commit()

##### End-Of-PythonScript #####

#Create WWNN Pool
##### Start-Of-PythonScript #####

from ucsmsdk.mometa.fcpool.FcpoolInitiators import FcpoolInitiators
from ucsmsdk.mometa.fcpool.FcpoolBlock import FcpoolBlock

mo = FcpoolInitiators(parent_mo_or_dn="org-root/org-Sub_Org_Test",
                      name="WWNN_Pool",
                      policy_owner="local",
                      descr="WWNN Pool",
                      assignment_order="sequential",
                      purpose="node-wwn-assignment")
mo_1 = FcpoolBlock(parent_mo_or_dn=mo,
                   to="20:00:00:25:B5:A0:00:1F",
                   r_from="20:00:00:25:B5:A0:00:00")
handle.add_mo(mo)
handle.commit()

##### End-Of-PythonScript #####

#Create WWPN Pool
##### Start-Of-PythonScript #####

from ucsmsdk.mometa.fcpool.FcpoolInitiators import FcpoolInitiators
from ucsmsdk.mometa.fcpool.FcpoolBlock import FcpoolBlock
예제 #5
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(wwn_list=dict(type='list'),
                         org_dn=dict(type='str', default='org-root'),
                         name=dict(type='str'),
                         purpose=dict(type='str', choices=['node', 'port']),
                         descr=dict(type='str'),
                         order=dict(type='str',
                                    default='default',
                                    choices=['default', 'sequential']),
                         first_addr=dict(type='str'),
                         last_addr=dict(type='str'),
                         state=dict(type='str',
                                    default='present',
                                    choices=['present', 'absent']))
    module = AnsibleModule(argument_spec,
                           supports_check_mode=True,
                           required_one_of=[['wwn_list', 'name']],
                           mutually_exclusive=[['wwn_list', 'name']],
                           required_together=[['name', 'purpose']])
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.fcpool.FcpoolInitiators import FcpoolInitiators
    from ucsmsdk.mometa.fcpool.FcpoolBlock import FcpoolBlock

    changed = False
    try:
        if module.params['wwn_list']:
            # directly use the list (single resource and list are mutually exclusive
            wwn_list = module.params['wwn_list']
        else:
            # single resource specified, create list from the current params
            wwn_list = [module.params]
        for wwn in wwn_list:
            exists = False
            # set default params.  Done here to set values for lists which can't be done in the argument_spec
            if not wwn.get('descr'):
                wwn['descr'] = ''
            if not wwn.get('order'):
                wwn['order'] = 'default'
            # append purpose param with suffix used by UCSM
            purpose_param = wwn['purpose'] + '-wwn-assignment'
            # dn is <org_dn>/wwn-pool-<name> for WWNN or WWPN
            dn = module.params['org_dn'] + '/wwn-pool-' + wwn['name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                # check top-level mo props
                kwargs = {}
                kwargs['assignment_order'] = wwn['order']
                kwargs['descr'] = wwn['descr']
                kwargs['purpose'] = purpose_param
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    if 'last_addr' in wwn and 'first_addr' in wwn:
                        block_dn = dn + '/block-' + wwn['first_addr'].upper(
                        ) + '-' + wwn['last_addr'].upper()
                        mo_1 = ucs.login_handle.query_dn(block_dn)
                        if mo_1:
                            exists = True
                    else:
                        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 = FcpoolInitiators(
                            parent_mo_or_dn=module.params['org_dn'],
                            name=wwn['name'],
                            assignment_order=wwn['order'],
                            purpose=purpose_param)
                        if 'last_addr' in wwn and 'first_addr' in wwn:
                            mo_1 = FcpoolBlock(parent_mo_or_dn=mo,
                                               to=wwn['last_addr'],
                                               r_from=wwn['first_addr'])

                        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
def wwn_pool(input):
    wwn = input
    results = {}
    ucs_handle = pickle.loads(
        str(ucs_login.main(wwn['ip'], wwn['username'], wwn['password'])))

    # set default params
    if not wwn.get('descr'):
        wwn['descr'] = ''
    if not wwn.get('order'):
        wwn['order'] = 'default'
    if not wwn.get('org_dn'):
        wwn['org_dn'] = 'org-root'
    if not wwn.get('state'):
        wwn['state'] = 'present'
    # append purpose param with suffix used by UCSM
    purpose_param = wwn['purpose'] + '-wwn-assignment'
    changed = False
    if wwn['state'] == 'present':
        results['expected'] = True
    else:
        results['expected'] = False
    results['name'] = wwn['name']
    try:
        exists = False
        # dn is <org_dn>/wwn-pool-<name> for WWNN or WWPN
        dn = wwn['org_dn'] + '/wwn-pool-' + wwn['name']

        mo = ucs_handle.query_dn(dn)
        if mo:
            obj = {}
            obj['name'] = mo.name
            obj['descr'] = mo.descr
            # check top-level mo props
            kwargs = {}
            kwargs['assignment_order'] = wwn['order']
            kwargs['descr'] = wwn['descr']
            kwargs['purpose'] = purpose_param
            if (mo.check_prop_match(**kwargs)):
                # top-level props match, check next level mo/props
                if 'to' in wwn and 'r_from' in wwn:
                    block_dn = dn + '/block-' + wwn['r_from'].upper(
                    ) + '-' + wwn['to'].upper()
                    mo_1 = ucs_handle.query_dn(block_dn)
                    if mo_1:
                        exists = True
                else:
                    exists = True

        if wwn['state'] == 'absent':
            if exists:
                if not wwn['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 wwn['check_exists']:
                    # create if mo does not already exist
                    mo = FcpoolInitiators(parent_mo_or_dn=wwn['org_dn'],
                                          name=wwn['name'],
                                          assignment_order=wwn['order'],
                                          purpose=purpose_param)
                    if 'to' in wwn and 'r_from' in wwn:
                        mo_1 = FcpoolBlock(parent_mo_or_dn=mo,
                                           to=wwn['to'],
                                           r_from=wwn['r_from'])

                    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
예제 #7
0
vnamenfs = str(raw_input("Enter NFS Vlan name, if no NFS then type no: "))
if vnamenfs != "no":
    mo = VnicLanConnTempl(parent_mo_or_dn="org-root", templ_type="updating-template", name="NFS_A", descr="", stats_policy_name="default", switch_id="A", pin_to_group_name="",        mtu="1500", policy_owner="local", qos_policy_name="", ident_pool_name="Fabric_A", nw_ctrl_policy_name="default")
    mo_1 = VnicEtherIf(parent_mo_or_dn=mo, default_net="yes", name=vnamenfs)
    handle.add_mo(mo)
    mo = VnicLanConnTempl(parent_mo_or_dn="org-root", templ_type="updating-template", name="NFS_B", descr="", stats_policy_name="default", switch_id="B", pin_to_group_name="",        mtu="1500", policy_owner="local", qos_policy_name="", ident_pool_name="Fabric_B", nw_ctrl_policy_name="default")
    mo_1 = VnicEtherIf(parent_mo_or_dn=mo, default_net="yes", name=vnamenfs)
    handle.add_mo(mo)

else :
    print "Almost Finished"
    
#Checking for FC to Create WWPN/WWNN Pools
needfc = str(raw_input("Do you need Fiber Channel(yes or no)?"))
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)