def ucs_vlan_exists(module):
    vlan_name = module.params.get('vlan_name')
    vlan_id = module.params.get('vlan_id')
    configure_lan_seperate = module.params.get('configure_lan_seperate')
    vlan_a = module.params.get('vlan_a')
    vlan_b = module.params.get('vlan_b')
    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)

    defined_vlans = handle.query_children(
                in_mo=lancloud[0], 
                class_id="FabricVlan"
                )
    results = defined_vlans

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

    return results
Beispiel #2
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
Beispiel #3
0
def ucs_inventory(module):
    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)

    query_dict = {}
    query_dict['chassis'] = {}
    query_dict['fi'] = {}
    query_dict['blade'] = {}

    try:
        query_data = ucsm.handle.query_classids('orgOrg', 'EquipmentChassis',
                                                'NetworkElement',
                                                'ComputeBlade')
        with open(module.params.get('output_file'), 'w+') as ucs_file:
            writer = csv.writer(ucs_file)
            writer.writerow(
                ['Serial Number', 'Device Name / Hostname', 'Tags', 'Notes'])
            for chassis in query_data['EquipmentChassis']:
                query_dict['chassis'][chassis.dn] = {}
                query_dict['chassis'][chassis.dn]['model'] = chassis.model
                query_dict['chassis'][chassis.dn]['serial'] = chassis.serial
                writer.writerow([chassis.serial, ucsm_ip, 'UCS-Chassis', ''])

            for fi in query_data['NetworkElement']:
                query_dict['fi'][fi.dn] = {}
                query_dict['fi'][fi.dn]['model'] = fi.model
                query_dict['fi'][fi.dn]['serial'] = fi.serial
                writer.writerow([fi.serial, ucsm_ip, 'UCS-FI', ''])

            for blade in query_data['ComputeBlade']:
                query_dict['blade'][blade.dn] = {}
                query_dict['blade'][blade.dn]['model'] = blade.model
                query_dict['blade'][blade.dn]['serial'] = blade.serial
                writer.writerow([blade.serial, ucsm_ip, 'UCS-Blades', ''])

    except Exception as e:
        module.fail_json(msg=e)

    try:
        ucsm.handle.logout()
        results['logged_out'] = True
    except Exception as e:
        module.fail_json(msg=e)
    results['inventory'] = query_dict
    return results
Beispiel #4
0
def ucs_remove_vlan_from_pc(module):
    vlan_name = module.params.get('vlan_name')
    vlan_id = module.params.get('vlan_id')
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    pc_id = module.params.get('pc_id')
    admin_speed = module.params.get('admin_speed')
    is_native = module.params.get('is_native')

    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)

    FILIST = ['A','B']
    for FI in FILIST:
        obj = ucsm.handle.query_dn("fabric/lan")
        lancloud = ucsm.handle.query_classid(class_id="FabricLanCloud") 
        try:
            mo = FabricEthLan(parent_mo_or_dn=obj, id=FI)
            mo_1 = FabricVlan(parent_mo_or_dn=mo, sharing="none", name=vlan_name, id=vlan_id, mcast_policy_name="", policy_owner="local", default_net="no", pub_nw_name="", compression_type="included")
            mo_1_1 = ucsm.handle.query_children(
                in_mo=mo_1,
                class_id="FabricEthVlanPc",
                filter_str='(vlan_name + + str(vlan_id), %s, type="eq")' % (vlan_name,vlan_id)
    	 	)  
            #mo_1_1 = FabricEthVlanPc(parent_mo_or_dn=mo_1, name=vlan_name + + str(vlan_id), descr="", is_native=is_native, admin_speed=admin_speed, switch_id=FI, admin_state="enabled", oper_speed=admin_speed, port_id=pc_id)

            ucsm.handle.remove_mo(mo_1_1)
            ucsm.handle.commit()
            results['changed'] = True

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

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

    return results
Beispiel #5
0
def ucs_add_vlan_to_pc(module):
    vlan_name = module.params.get('vlan_name')
    vlan_id = module.params.get('vlan_id')
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    pc_id = module.params.get('pc_id')
    admin_speed = module.params.get('admin_speed')
    is_native = module.params.get('is_native')

    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)

    FILIST = ['A', 'B']
    for FI in FILIST:
        obj = ucsm.handle.query_dn("fabric/lan")
	# Attaches a single Global Vlan to Port Channel
        try:
#            mo = FabricEthLan(parent_mo_or_dn=obj, id=FI)
            mo_1 = FabricVlan(parent_mo_or_dn=obj, sharing="none", name=vlan_name, id=vlan_id, mcast_policy_name="", policy_owner="local", default_net="no", pub_nw_name="", compression_type="included")
            mo_1_1 = FabricEthVlanPc(parent_mo_or_dn=mo_1, name="", descr="", is_native=is_native, admin_speed=admin_speed, switch_id=FI, admin_state="enabled", oper_speed=admin_speed, port_id=pc_id)
            ucsm.handle.add_mo(mo_1, modify_present=True)

            ucsm.handle.commit()
            results['changed'] = True

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

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

    return results
Beispiel #6
0
def ucs_enable_snmp(module):
    sys_location = module.params.get('sys_location')
    community = module.params.get('community')
    admin_state = module.params.get('admin_state')
    sys_contact = module.params.get('sys_contact')
    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)

    snmp_secure = 'no'

    obj = ucsm.handle.query_dn("sys/svc-ext")
    mo = CommSnmp(parent_mo_or_dn=obj,
                  descr="SNMP Service",
                  sys_location=sys_location,
                  community=community,
                  policy_owner="local",
                  admin_state=admin_state,
                  sys_contact=sys_contact,
                  is_set_snmp_secure=snmp_secure)

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

    except Exception as e:
        module.fail_json(msg=e)

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

    return results
Beispiel #7
0
def ucs_add_vlan_to_vnic(module):
    vlan_name = module.params.get('vlan_name')
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    vnic_template = module.params.get('vnic_template')
    default_net = module.params.get('default_net')

    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)

    FILIST = ['A']
    for FI in FILIST:
        try:
            obj = ucsm.handle.query_dn("org-root/lan-conn-templ-" +
                                       vnic_template)
            mo_1 = VnicEtherIf(parent_mo_or_dn=obj,
                               default_net=default_net,
                               name=vlan_name)
            ucsm.handle.add_mo(mo_1)
            ucsm.handle.commit()

            results['changed'] = True

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

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

    return results
Beispiel #8
0
def ucs_add_snmp_trap(module):
    v3_priv = module.params.get('v3_priv')
    hostname = module.params.get('hostname')
    community = module.params.get('community')
    version = module.params.get('version')
    notify_type = module.params.get('notification_type')
    port = module.params.get('port')
    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 = CommSnmpTrap(parent_mo_or_dn="sys/svc-ext/snmp-svc",
                      v3_privilege=v3_priv,
                      hostname=hostname,
                      community=community,
                      version=version,
                      notification_type=notify_type,
                      port=port)

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

    except Exception as e:
        module.fail_json(msg=e)

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

    return results
Beispiel #9
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
Beispiel #10
0
def ucs_remove_vlan_from_vnic(module):
    vlan_name = module.params.get('vlan_name')
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    vnic_template = module.params.get('vnic_template')
    ucsm = UCS(ucsm_ip, ucsm_login, ucsm_pw)

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

    FILIST = ['A']
    for FI in FILIST:
        try:
            mo_1 = ucsm.handle.query_dn("org-root/lan-conn-templ-" +
                                        vnic_template + "/if-" + vlan_name)
            ucsm.handle.remove_mo(mo_1)
            ucsm.handle.commit()
            results['changed'] = True

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

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

    return results
Beispiel #11
0
def ucs_add_dns(module):
    dns_ip = module.params.get('dns_ip')
    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)

    for ip in dns_ip:
        if ip:
            mo = CommDnsProvider(parent_mo_or_dn="sys/svc-ext/dns-svc",
                                 name=ip,
                                 descr="")

        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
Beispiel #12
0
def ucs_disable_snmp(module):
    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)

    obj = ucsm.handle.query_dn("sys/svc-ext")
    mo = CommSnmp(parent_mo_or_dn=obj,
                  descr="",
                  sys_location="",
                  community="",
                  policy_owner="local",
                  admin_state="disabled",
                  sys_contact="contact",
                  is_set_snmp_secure="no")

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

    except Exception as e:
        module.fail_json(msg=e)

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

    return results
Beispiel #13
0
def ucs_add_ntp(module):
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    ntp_servers = module.params['ntp_servers']

    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)

    for ntp_addr in ntp_servers:
        if ntp_addr:
            mo = CommNtpProvider(parent_mo_or_dn="sys/svc-ext/datetime-svc", name=ntp_addr, descr="")

        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
def ucs_vlan_exists(module):
    vlan_id = module.params.get('vlan_id')
    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)

    # Obtain a handle for the LAN Cloud
    lancloud = ucsm.handle.query_classid(class_id="FabricLanCloud")

    test_vlan = ucsm.handle.query_children(in_mo=lancloud[0],
                                           class_id="FabricVlan",
                                           filter_str='(id, %s, type="eq")' %
                                           (vlan_id))

    try:
        if test_vlan[0].id == vlan_id:
            module.fail_json(msg="UCS Vlan already exists!")
            results['existance'] = 'true'
    except Exception as e:
        results['existance'] = 'false'
    try:
        ucsm.handle.logout()
        results['logged_out'] = True
    except Exception as e:
        module.fail_json(msg=e)

    return results
Beispiel #15
0
def ucs_remove_ntp(module):
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    ntp_servers = module.params['ntp_servers']
    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)

    for ntp_addr in ntp_servers:
        if ntp_addr:
            mo = ucsm.handle.query_dn("sys/svc-ext/datetime-svc/ntp-" + str(ntp_addr))

        try:
            ucsm.handle.remove_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
Beispiel #16
0
def ucs_remove_dns(module):
    dns_ip = module.params.get('dns_ip')
    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)

    for ip in dns_ip:
        if ip:
            mo = ucsm.handle.query_dn("sys/svc-ext/dns-svc/dns-" + ip)

        try:
            ucsm.handle.remove_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
Beispiel #17
0
def ucs_add_vlan(module):
    vlan_name = module.params.get('vlan_name')
    vlan_id = module.params.get('vlan_id')
    mcast_policy_name = module.params.get('mcast_policy_name')
    policy_owner = module.params.get('policy_owner')
    configure_lan_seperate = module.params.get('configure_lan_seperate')
    vlan_a = module.params.get('vlan_a')
    vlan_b = module.params.get('vlan_b')
    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)


#
# Checking if configured for lan seperate per FI or not.
#

    if configure_lan_seperate == 'no':
        mo = FabricVlan(parent_mo_or_dn="fabric/lan",
                        sharing="none",
                        name=vlan_name + str(vlan_id),
                        id=vlan_id,
                        mcast_policy_name=mcast_policy_name,
                        policy_owner=policy_owner,
                        default_net="no",
                        pub_nw_name="",
                        compression_type="included")

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

        except Exception as e:
            module.fail_json(msg=e)
            results['changed'] = False
    else:
        mo = FabricVlan(parent_mo_or_dn="fabric/lan/A",
                        sharing="none",
                        name=vlan_name + str(vlan_a),
                        id=str(vlan_a),
                        mcast_policy_name=mcast_policy_name,
                        policy_owner=policy_owner,
                        default_net="no",
                        pub_nw_name="",
                        compression_type="included")
        ucsm.handle.add_mo(mo)

        mo = FabricVlan(parent_mo_or_dn="fabric/lan/B",
                        sharing="none",
                        name=vlan_name + str(vlan_b),
                        id=str(vlan_b),
                        mcast_policy_name=mcast_policy_name,
                        policy_owner=policy_owner,
                        default_net="no",
                        pub_nw_name="",
                        compression_type="included")

        ucsm.handle.add_mo(mo)

        try:
            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
Beispiel #18
0
def ucs_add_vlan_range(module):
    ucsm_ip = module.params.get('ip')
    ucsm_pw = module.params.get('password')
    ucsm_login = module.params.get('login')
    vlan_name = module.params.get('vlan_name')
    vlan_range = module.params.get('vlan_range')
    mcast_policy_name = module.params.get('mcast_policy_name')
    policy_owner = module.params.get('policy_owner')
    configure_lan_seperate = module.params.get('configure_lan_seperate')
    vlan_a_range = module.params.get('vlan_a_range')
    vlan_b_range = module.params.get('vlan_b_range')

    results = {}

    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)

    if vlan_range:
        vlan_range_split = vlan_range.split('-')
        vlan_start = int(vlan_range_split[0])
        vlan_end = int(vlan_range_split[1]) + 1
        vlan_list = list(range(vlan_start, vlan_end))

    elif vlan_a_range:
        vlan_a_range_split = vlan_a_range.split('-')
        vlan_a_start = int(vlan_a_range_split[0])
        vlan_a_end = int(vlan_a_range_split[1]) + 1
        vlan_a_list = list(range(vlan_a_start, vlan_a_end))

    if vlan_b_range:
        vlan_b_range_split = vlan_b_range.split('-')
        vlan_b_start = int(vlan_b_range_split[0])
        vlan_b_end = int(vlan_b_range_split[1]) + 1
        vlan_b_list = list(range(vlan_b_start, vlan_b_end))

    if configure_lan_seperate == 'no':

        for vlan in vlan_list:
            mo = FabricVlan(parent_mo_or_dn="fabric/lan",
                            sharing="none",
                            name=vlan_name + str(vlan),
                            id=str(vlan),
                            mcast_policy_name=mcast_policy_name,
                            policy_owner=policy_owner,
                            default_net="no",
                            pub_nw_name="",
                            compression_type="included")
            try:
                ucsm.handle.add_mo(mo)
                results['changed'] = True

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

        for vlan in vlan_a_list:
            mo = FabricVlan(parent_mo_or_dn="fabric/lan/A",
                            sharing="none",
                            name=vlan_name + str(vlan),
                            id=str(vlan),
                            mcast_policy_name=mcast_policy_name,
                            policy_owner=policy_owner,
                            default_net="no",
                            pub_nw_name="",
                            compression_type="included")
            try:
                ucsm.handle.add_mo(mo)
                results['changed'] = True

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

        for vlan in vlan_b_list:
            mo = FabricVlan(parent_mo_or_dn="fabric/lan/B",
                            sharing="none",
                            name=vlan_name + str(vlan),
                            id=str(vlan),
                            mcast_policy_name=mcast_policy_name,
                            policy_owner=policy_owner,
                            default_net="no",
                            pub_nw_name="",
                            compression_type="included")
            try:
                ucsm.handle.add_mo(mo)
                results['changed'] = True

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

    #Committing Changes
    ucsm.handle.commit()

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

    return results
Beispiel #19
0
def ucs_callhome(module):
    admin_state = module.params.get('admin_state')
    throttle_state = module.params.get('throttle_state')
    urgency = module.params.get('urgency')
    contact = module.params.get('contact')
    phone = module.params.get('phone')
    email = module.params.get('email')
    addr = module.params.get('addr')
    customer = module.params.get('customer')
    contract = module.params.get('contract')
    site = module.params.get('site')
    r_from = module.params.get('r_from')
    reply_to = module.params.get('reply_to')
    host = module.params.get('host')
    port = module.params.get('port')
    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)
        module.fail_json(msg="login failed")

    mo = ucsm.handle.query_dn("call-home")
    if mo.admin_state == "off":
        mo = ucsm.handle.query_dn("call-home")
        mo.alert_throttling_admin_state = throttle_state
        mo.policy_owner = "local"
        mo.admin_state = admin_state
        mo.name = ""
        mo.descr = ""
        mo_1 = CallhomeSmtp(parent_mo_or_dn=mo, host=host, port=port)
        mo_2 = CallhomeSource(parent_mo_or_dn=mo,
                              customer=customer,
                              addr=addr,
                              r_from=r_from,
                              site=site,
                              contract=contract,
                              phone=phone,
                              contact=contact,
                              reply_to=reply_to,
                              email=email,
                              urgency=urgency)
        try:
            ucsm.handle.set_mo(mo)
            ucsm.handle.commit()
            results['changed'] = True

        except Exception as e:
            module.jail_json(msg=e)
            module.fail_json(msg="callhome configuration failed")
    else:
        obj = ucsm.handle.query_dn("call-home")
        mo = CallhomeSource(parent_mo_or_dn=obj,
                            customer=customer,
                            addr=addr,
                            r_from=r_from,
                            site=site,
                            contract=contact,
                            phone=phone,
                            contact=contact,
                            reply_to=reply_to,
                            email=email,
                            urgency=urgency)
        ucsm.handle.add_mo(mo, True)
        ucsm.handle.commit()
        results['changed'] = True

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

    return results