Exemplo n.º 1
0
def add_ucs_ippool(ippool_name, ippool_descr, ippool_def_gw, ippool_from,
                   ippool_to, ippool_prim_dns, ippool_sec_dns):
    from ucsmsdk.mometa.ippool.IppoolPool import IppoolPool
    from ucsmsdk.mometa.ippool.IppoolBlock import IppoolBlock

    handle = ucs_login()

    mo = IppoolPool(parent_mo_or_dn="fabric/lan/network-sets",
                    descr=ippool_descr,
                    ext_managed="external",
                    name=ippool_name)
    handle.add_mo(mo, True)

    mo = IppoolBlock(parent_mo_or_dn="fabric/lan/network-sets/ip-pool-" +
                     ippool_name,
                     def_gw=ippool_def_gw,
                     r_from=ippool_from,
                     to=ippool_to,
                     prim_dns=ippool_prim_dns,
                     sec_dns=ippool_sec_dns)
    handle.add_mo(mo, True)

    handle.commit()

    response = "IpPool: " + ippool_name + " with IP Block: " + ippool_from + "-" + ippool_to + " has been created/updated"

    ucs_logout(handle)

    print(response)
    return response
Exemplo n.º 2
0
def update_ip_pool(ucs, module):
    from ucsmsdk.mometa.ippool.IppoolPool import IppoolPool

    mo = IppoolPool(
        parent_mo_or_dn=module.params['org_dn'],
        name=module.params['name'],
        descr=module.params['descr'],
        assignment_order=module.params['order'],
    )
    ucs.login_handle.add_mo(mo, True)
    ucs.login_handle.commit()

    return mo
Exemplo n.º 3
0
def ip_pool_create(handle,
                   name,
                   assignment_order,
                   descr="",
                   parent_dn="org-root"):
    """
    Creates IP Pool

    Args:
        handle (UcsHandle)
        name (String) : IP pool name
        assignment_order (String) : ["default", "sequential"]
        descr (String) :
        parent_dn (String) :

    Returns:
        IppoolPool : Managed Object

    Raises:
        ValueError: If OrgOrg is not present

    Example:
        ip_pool_create(handle, "sample_ip_pool", "default")
    """

    from ucsmsdk.mometa.ippool.IppoolPool import IppoolPool

    obj = handle.query_dn(parent_dn)
    if obj is None:
        raise ValueError("Org %s not found" % parent_dn)
    mo = IppoolPool(parent_mo_or_dn=obj,
                    policy_owner="local",
                    descr=descr,
                    assignment_order=assignment_order,
                    name=name)

    handle.add_mo(mo, True)
    handle.commit()
    return mo
Exemplo n.º 4
0
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='', aliases=['descrption', 'description']),
        order=dict(type='str', default='default', choices=['default', 'sequential']),
        first_addr=dict(type='str'),
        last_addr=dict(type='str'),
        subnet_mask=dict(type='str', default='255.255.255.0'),
        default_gw=dict(type='str', default='0.0.0.0'),
        primary_dns=dict(type='str', default='0.0.0.0'),
        secondary_dns=dict(type='str', default='0.0.0.0'),
        ipv6_first_addr=dict(type='str'),
        ipv6_last_addr=dict(type='str'),
        ipv6_prefix=dict(type='str', default='64'),
        ipv6_default_gw=dict(type='str', default='::'),
        ipv6_primary_dns=dict(type='str', default='::'),
        ipv6_secondary_dns=dict(type='str', default='::'),
        state=dict(type='str', default='present', choices=['present', 'absent']),
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
    )
    # UCSModule verifies ucsmsdk is present and exits on failure.  Imports are below ucs object creation.
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.ippool.IppoolPool import IppoolPool
    from ucsmsdk.mometa.ippool.IppoolBlock import IppoolBlock
    from ucsmsdk.mometa.ippool.IppoolIpV6Block import IppoolIpV6Block

    changed = False
    try:
        mo_exists = False
        props_match = False
        # dn is <org_dn>/ip-pool-<name>
        dn = module.params['org_dn'] + '/ip-pool-' + module.params['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:
            if mo_exists:
                # check top-level mo props
                kwargs = dict(assignment_order=module.params['order'])
                kwargs['descr'] = module.params['descr']
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    if module.params['last_addr'] and module.params['first_addr']:
                        # ipv4 block specified, check properties
                        block_dn = dn + '/block-' + module.params['first_addr'] + '-' + module.params['last_addr']
                        mo_1 = ucs.login_handle.query_dn(block_dn)
                        if mo_1:
                            kwargs = dict(subnet=module.params['subnet_mask'])
                            kwargs['def_gw'] = module.params['default_gw']
                            kwargs['prim_dns'] = module.params['primary_dns']
                            kwargs['sec_dns'] = module.params['secondary_dns']
                            if (mo_1.check_prop_match(**kwargs)):
                                # ipv4 block exists and properties match
                                props_match = True
                    else:
                        # no ipv4 block specified, but top-level props matched
                        props_match = True

                    # only check ipv6 props if the top-level and ipv4 props matched
                    if props_match and module.params['ipv6_last_addr'] and module.params['ipv6_first_addr']:
                        # ipv6 block specified, check properties
                        block_dn = dn + '/v6block-' + module.params['ipv6_first_addr'].lower() + '-' + module.params['ipv6_last_addr'].lower()
                        mo_1 = ucs.login_handle.query_dn(block_dn)
                        if mo_1:
                            kwargs = dict(prefix=module.params['ipv6_prefix'])
                            kwargs['def_gw'] = module.params['ipv6_default_gw']
                            kwargs['prim_dns'] = module.params['ipv6_primary_dns']
                            kwargs['sec_dns'] = module.params['ipv6_secondary_dns']
                            if (mo_1.check_prop_match(**kwargs)):
                                # ipv6 block exists and properties match
                                props_match = True
                        else:
                            # no ipv6 block specified, but previous checks matched
                            props_match = True

            if not props_match:
                if not module.check_mode:
                    # create if mo does not already exist
                    mo = IppoolPool(
                        parent_mo_or_dn=module.params['org_dn'],
                        name=module.params['name'],
                        descr=module.params['descr'],
                        assignment_order=module.params['order'],
                    )

                    if module.params['last_addr'] and module.params['first_addr']:
                        mo_1 = IppoolBlock(
                            parent_mo_or_dn=mo,
                            to=module.params['last_addr'],
                            r_from=module.params['first_addr'],
                            subnet=module.params['subnet_mask'],
                            def_gw=module.params['default_gw'],
                            prim_dns=module.params['primary_dns'],
                            sec_dns=module.params['secondary_dns'],
                        )

                    if module.params['ipv6_last_addr'] and module.params['ipv6_first_addr']:
                        mo_1 = IppoolIpV6Block(
                            parent_mo_or_dn=mo,
                            to=module.params['ipv6_last_addr'],
                            r_from=module.params['ipv6_first_addr'],
                            prefix=module.params['ipv6_prefix'],
                            def_gw=module.params['ipv6_default_gw'],
                            prim_dns=module.params['ipv6_primary_dns'],
                            sec_dns=module.params['ipv6_secondary_dns'],
                        )

                    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)
Exemplo n.º 5
0
#mo_7 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="7", chassis_id="1")
handle.add_mo(mo)
handle.commit()

#Create Maintenance Policy
mo = LsmaintMaintPolicy(parent_mo_or_dn=my_Full_Path_Org, uptime_disr="user-ack", name="User_Ack", descr="User Ack", trigger_config="on-next-boot", sched_name="", policy_owner="local")
handle.add_mo(mo)
handle.commit()

#Create Power Policy
mo = PowerPolicy(parent_mo_or_dn=my_Full_Path_Org, fan_speed="any", policy_owner="local", name="No_Cap", prio="no-cap", descr="No Cap")
handle.add_mo(mo)
handle.commit()

#Create IP Pool
mo = IppoolPool(parent_mo_or_dn=my_Full_Path_Org, is_net_bios_enabled="disabled", name="ext_mgmt", descr="KVM", policy_owner="local", ext_managed="internal", supports_dhcp="disabled", assignment_order="sequential")
mo_1 = IppoolBlock(parent_mo_or_dn=mo, prim_dns=my_Primary_DNS, r_from=my_kvm_pool_first, def_gw=my_KVM_Gateway, sec_dns=my_Secondary_DNS, to=my_kvm_last_addr)
handle.add_mo(mo)
handle.commit()

#Create MAC Pools
mo = MacpoolPool(parent_mo_or_dn=my_Full_Path_Org, policy_owner="local", descr="Management FI-A", assignment_order="sequential", name="MGMT-A")
mo_1 = MacpoolBlock(parent_mo_or_dn=mo, to="00:25:B5:A0:00:0F", r_from="00:25:B5:A0:00:00")
handle.add_mo(mo)
handle.commit()

mo = MacpoolPool(parent_mo_or_dn=my_Full_Path_Org, policy_owner="local", descr="Management FI-B", assignment_order="sequential", name="MGMT-B")
mo_1 = MacpoolBlock(parent_mo_or_dn=mo, to="00:25:B5:B0:00:0F", r_from="00:25:B5:B0:00:00")
handle.add_mo(mo)
handle.commit()
Exemplo n.º 6
0
#mo = handle.query_dn("org-root/org-Sub_Org_Test/mnt-cfg-policy-vMedia")
#handle.remove_mo(mo)
#handle.commit()
##### End-Of-PythonScript #####

#add IP Pool
##### Start-Of-PythonScript #####

from ucsmsdk.mometa.ippool.IppoolPool import IppoolPool
from ucsmsdk.mometa.ippool.IppoolBlock import IppoolBlock

mo = IppoolPool(parent_mo_or_dn="org-root/org-Sub_Org_Test",
                is_net_bios_enabled="disabled",
                name="ext_mgmt",
                descr="KVM",
                policy_owner="local",
                ext_managed="internal",
                supports_dhcp="disabled",
                assignment_order="sequential")
mo_1 = IppoolBlock(parent_mo_or_dn=mo,
                   prim_dns="10.10.10.100",
                   r_from="10.10.10.10",
                   def_gw="10.10.10.1",
                   sec_dns="10.10.10.200",
                   to="10.10.10.17")
handle.add_mo(mo)

handle.commit()
##### End-Of-PythonScript #####

#Create MAC Pool
def addIppoolPool(pool_name, desc):
    # name = pool_name
    # descr = desc
    mo = IppoolPool(parent_mo_or_dn="fabric/lan/network-sets", descr = dec, ext_managed="external", name = pool_name)
    handle.add_mo(mo)
    handle.commit()
Exemplo n.º 8
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(ip_list=dict(required=True, type='list'),
                         org_dn=dict(type='str', default='org-root'),
                         state=dict(default='present',
                                    choices=['present', 'absent'],
                                    type='str'))
    module = AnsibleModule(argument_spec, supports_check_mode=True)
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.ippool.IppoolPool import IppoolPool
    from ucsmsdk.mometa.ippool.IppoolBlock import IppoolBlock
    from ucsmsdk.mometa.ippool.IppoolIpV6Block import IppoolIpV6Block

    changed = False
    try:
        for ip in module.params['ip_list']:
            exists = False
            dn = module.params['org_dn'] + '/ip-pool-' + ip['name']
            # set default params
            if 'order' not in ip:
                ip['order'] = 'default'
            if 'descr' not in ip:
                ip['descr'] = ''
            if 'subnet_mask' not in ip:
                ip['subnet_mask'] = '255.255.255.0'
            if 'default_gw' not in ip:
                ip['default_gw'] = '0.0.0.0'
            if 'primary_dns' not in ip:
                ip['primary_dns'] = '0.0.0.0'
            if 'secondary_dns' not in ip:
                ip['secondary_dns'] = '0.0.0.0'
            if 'ipv6_prefix' not in ip:
                ip['ipv6_prefix'] = '64'
            if 'ipv6_default_gw' not in ip:
                ip['ipv6_default_gw'] = '::'
            if 'ipv6_primary_dns' not in ip:
                ip['ipv6_primary_dns'] = '::'
            if 'ipv6_secondary_dns' not in ip:
                ip['ipv6_secondary_dns'] = '::'

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                # check top-level mo props
                kwargs = {}
                kwargs['assignment_order'] = ip['order']
                kwargs['descr'] = ip['descr']
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    exists = True
                    if 'last_addr' in ip and 'first_addr' in ip:
                        block_dn = dn + '/block-' + ip[
                            'first_addr'] + '-' + ip['last_addr']
                        mo_1 = ucs.login_handle.query_dn(block_dn)
                        if mo_1:
                            kwargs = {}
                            kwargs['subnet'] = ip['subnet_mask']
                            kwargs['def_gw'] = ip['default_gw']
                            kwargs['prim_dns'] = ip['primary_dns']
                            kwargs['sec_dns'] = ip['secondary_dns']
                            if (not mo_1.check_prop_match(**kwargs)):
                                exists = False
                        else:
                            exists = False

                    if 'ipv6_last_addr' in ip and 'ipv6_first_addr' in ip:
                        block_dn = dn + '/v6block-' + ip[
                            'ipv6_first_addr'].lower(
                            ) + '-' + ip['ipv6_last_addr'].lower()
                        mo_1 = ucs.login_handle.query_dn(block_dn)
                        if mo_1:
                            kwargs = {}
                            kwargs['prefix'] = ip['ipv6_prefix']
                            kwargs['def_gw'] = ip['ipv6_default_gw']
                            kwargs['prim_dns'] = ip['ipv6_primary_dns']
                            kwargs['sec_dns'] = ip['ipv6_secondary_dns']
                            if (not mo_1.check_prop_match(**kwargs)):
                                exists = False
                        else:
                            exists = False

            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 = IppoolPool(
                            parent_mo_or_dn=module.params['org_dn'],
                            name=ip['name'],
                            descr=ip['descr'],
                            assignment_order=ip['order'])

                        if 'last_addr' in ip and 'first_addr' in ip:
                            mo_1 = IppoolBlock(parent_mo_or_dn=mo,
                                               to=ip['last_addr'],
                                               r_from=ip['first_addr'],
                                               subnet=ip['subnet_mask'],
                                               def_gw=ip['default_gw'],
                                               prim_dns=ip['primary_dns'],
                                               sec_dns=ip['secondary_dns'])

                        if 'ipv6_last_addr' in ip and 'ipv6_first_addr' in ip:
                            mo_1 = IppoolIpV6Block(
                                parent_mo_or_dn=mo,
                                to=ip['ipv6_last_addr'],
                                r_from=ip['ipv6_first_addr'],
                                prefix=ip['ipv6_prefix'],
                                def_gw=ip['ipv6_default_gw'],
                                prim_dns=ip['ipv6_primary_dns'],
                                sec_dns=ip['ipv6_secondary_dns'])
                        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)