Exemple #1
0
def nw_control_policy_create(handle, name, cdp, mac_register_mode, uplink_fail_action,
                             forge, lldp_transmit, lldp_receive, descr="", parent_dn="org-root"):
    """
    Creates Network Control Policy

    Args:
        handle (UcsHandle)
        name (String) : Network Control Policy Name
        cdp (String) : ["disabled", "enabled"]
        mac_register_mode (String): ["all-host-vlans", "only-native-vlan"]
        uplink_fail_action (String) : ["link-down", "warning"]
        forge (string) : ["allow", "deny"]
        lldp_transmit (String) : ["disabled", "enabled"]
        lldp_receive (String) : ["disabled", "enabled"]
        descr (String) :
        parent_dn (String) :

    Returns:
        None

    Example:
        nw_control_policy_create(handle, "sample_nwcontrol_policy", "enabled", "all-host-vlans",
                                 "link-down", "allow", "disabled", "disabled")
    """
    from ucsmsdk.mometa.nwctrl.NwctrlDefinition import NwctrlDefinition
    from ucsmsdk.mometa.dpsec.DpsecMac import DpsecMac

    obj = handle.query_dn(parent_dn)
    if obj:
        mo = NwctrlDefinition(parent_mo_or_dn=obj,
                              lldp_transmit=lldp_transmit,
                              name=name,
                              lldp_receive=lldp_receive,
                              mac_register_mode=mac_register_mode,
                              policy_owner="local",
                              cdp=cdp,
                              uplink_fail_action=uplink_fail_action,
                              descr=descr)
        mo_1 = DpsecMac(parent_mo_or_dn=mo,
                        forge=forge,
                        policy_owner="local",
                        name="",
                        descr="")

        handle.add_mo(mo, modify_present=True)
        handle.commit()
    else:
        log.info(parent_dn + " MO is not available")
Exemple #2
0
handle.add_mo(mo)
handle.commit()

if(iSCSI):
    mo = MacpoolPool(parent_mo_or_dn=my_Full_Path_Org, policy_owner="local", descr="iSCSI FI-A", assignment_order="sequential", name="iSCSI-A")
    mo_1 = MacpoolBlock(parent_mo_or_dn=mo, to="00:25:B5:A2:00:0F", r_from="00:25:B5:A2:00:00")
    handle.add_mo(mo)
    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()
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        name=dict(type='str', required=True),
        descr=dict(type='str', default=''),
        cdp=dict(type='str', default='disabled'),
        mac_register_mode=dict(type='str',
                               default='only-native-vlan',
                               choices=['all-host-vlans', 'only-native-vlan']),
        uplink_fail_action=dict(type='str',
                                default='link-down',
                                choices=['link-down', 'warning']),
        forge=dict(type='str',
                   default='deny',
                   choices=['allow', 'deny', 'no-config']),
        lldp_transmit=dict(type='str',
                           default='disabled',
                           choices=['disabled', 'enabled']),
        lldp_receive=dict(type='str',
                          default='disabled',
                          choices=['disabled', 'enabled']),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
    )
    ucs = UCSModule(module)

    err = False

    # UCSModule creation above verifies ucsmsdk is present and exits on failure, so additional imports are done below.
    from ucsmsdk.mometa.nwctrl.NwctrlDefinition import NwctrlDefinition
    from ucsmsdk.mometa.dpsec.DpsecMac import DpsecMac

    changed = False
    try:
        mo_exists = False
        props_match = False
        # dn is fabric/lan/net-<name> for common network control policies or fabric/lan/[A or B]/net-<name> for A or B
        dn = module.params['org_dn'] + '/nwctrl-' + module.params['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(name=module.params['name'])
                kwargs['cdp'] = module.params['cdp']
                kwargs['descr'] = module.params['descr']
                kwargs['mac_register_mode'] = module.params[
                    'mac_register_mode']
                kwargs['uplink_fail_action'] = module.params[
                    'uplink_fail_action']
                kwargs['lldp_receive'] = module.params['lldp_receive']
                kwargs['lldp_transmit'] = module.params['lldp_transmit']
                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 = NwctrlDefinition(
                        parent_mo_or_dn=module.params['org_dn'],
                        lldp_transmit=module.params['lldp_transmit'],
                        name=module.params['name'],
                        lldp_receive=module.params['lldp_receive'],
                        mac_register_mode=module.params['mac_register_mode'],
                        policy_owner="local",
                        cdp=module.params['cdp'],
                        uplink_fail_action=module.params['uplink_fail_action'],
                        descr=module.params['descr'])
                    if not module.params['forge'] == 'no-config':
                        DpsecMac(parent_mo_or_dn=mo,
                                 forge=module.params['forge'],
                                 policy_owner="local",
                                 name="",
                                 descr="")

                    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)
Exemple #4
0
            is_secure = False
        handle = ucshandle.UcsHandle(settings_file['ip'],
                                     settings_file['user'],
                                     settings_file['pw'],
                                     secure=is_secure)
        handle.login()

        # apply hardcoded policies
        from ucsmsdk.mometa.nwctrl.NwctrlDefinition import NwctrlDefinition
        from ucsmsdk.mometa.dpsec.DpsecMac import DpsecMac

        mo = NwctrlDefinition(parent_mo_or_dn="org-root",
                              lldp_transmit="disabled",
                              name="Enable_CDP",
                              lldp_receive="disabled",
                              mac_register_mode="only-native-vlan",
                              policy_owner="local",
                              cdp="enabled",
                              uplink_fail_action="link-down",
                              descr="")
        mo_1 = DpsecMac(parent_mo_or_dn=mo,
                        forge="allow",
                        policy_owner="local",
                        name="",
                        descr="")
        handle.add_mo(mo)

        handle.commit()

        # setup ext-mgmt IP pool
        from ucsmsdk.mometa.ippool.IppoolBlock import IppoolBlock