示例#1
0
    def add_servers_to_pool(handle, servers, org):
        from ucsmsdk.mometa.compute.ComputePool import ComputePool
        from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot
        from ucsmsdk.mometa.compute.ComputePooledRackUnit import ComputePooledRackUnit

        print "Adding servers to KUBAM Pool"
        mo = ComputePool(parent_mo_or_dn=org, policy_owner="local", name="kubam", descr="")
        handle.query_classid("computeBlade")
        if "blades" in servers:
            for s in servers["blades"]:
                # Don't reset disks, leave them the way they are.
                # reset_disks(handle, s)
                chassis, slot = s.split("/")
                ComputePooledSlot(parent_mo_or_dn=mo, slot_id=str(slot), chassis_id=str(chassis))
        if "rack_servers" in servers:
            for r in servers["rack_servers"]:
                ComputePooledRackUnit(parent_mo_or_dn=mo, id=r)
        handle.add_mo(mo, True)
        try:
            handle.commit()
        except UcsException as err:
            if err.error_code == "103":
                print "\talready exists"
            else:
                return 1, err.error_descr
        return 0, None
示例#2
0
def server_pool_create(handle, name, descr="", parent_dn="org-root"):
    """
    This method creates ComputePool.

    Args:
        handle (UcsHandle)
        name (string): Name of the ComputePool.
        descr (string): Basic description.
        parent_dn (string): Parent of Org.

    Returns:
       ComputePool: Managed Object

    Example:
        server_pool_create(handle, name="sample_compute_pool",
        parent_dn="org-root/org-sub")

    """

    obj = handle.query_dn(parent_dn)
    if not obj:
        raise ValueError("org '%s' does not exist" % parent_dn)

    mo = ComputePool(parent_mo_or_dn=obj, name=name, descr=descr)
    handle.add_mo(mo, modify_present=True)
    handle.commit()
    return mo
示例#3
0
def addServersToKubePool(handle, servers, org):
    print "Adding servers to Kubernetes Pool"
    from ucsmsdk.mometa.compute.ComputePool import ComputePool
    from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot
    from ucsmsdk.mometa.compute.ComputePooledRackUnit import ComputePooledRackUnit
    from ucsmsdk.mometa.compute.ComputeRackUnit import ComputeRackUnit
    from ucsmsdk.mometa.fabric.FabricComputeSlotEp import FabricComputeSlotEp
    mo = ComputePool(parent_mo_or_dn=org,
                     policy_owner="local",
                     name="Kubernetes",
                     descr="")
    for s in servers:
        reset_disks(handle, s)
        if type(s) is FabricComputeSlotEp:
            ComputePooledSlot(parent_mo_or_dn=mo,
                              slot_id=re.sub("slot-", "", s.slot_id),
                              chassis_id=str(s.chassis_id))
        if type(s) is ComputeRackUnit:
            ComputePooledRackUnit(parent_mo_or_dn=mo,
                                  id=re.sub("rack-unit-", "", s.rn))
        handle.add_mo(mo, True)
    try:
        handle.commit()
    except UcsException as err:
        if err.error_code == "103":
            print "\talready exists"
示例#4
0
def createKubeServerPool(handle, org):
    print "Creating Kubernetes Compute Pool"
    from ucsmsdk.mometa.compute.ComputePool import ComputePool
    mo = ComputePool(parent_mo_or_dn=org, policy_owner="local", name="Kubernetes", descr="")
    handle.add_mo(mo)
    try: 
        handle.commit()
    except UcsException as err:
        if err.error_code == "103":
            print "\talready exists"
示例#5
0
def test_valid_server_pool_add_rack_unit(query_mock, add_mo_mock, commit_mock):
    query_mock.return_value = ComputePool(parent_mo_or_dn="org-root",
                                          name="test-pool")
    add_mo_mock.return_value = True
    commit_mock.return_value = True
    handle = UcsHandle('169.254.1.1', 'admin', 'password')

    # Scenario: Default parameters
    pool_retval = server_pool_add_rack_unit(handle, 16)
    # Verify we were passed back the correct object type
    assert isinstance(pool_retval, ComputePooledRackUnit)
    # Verify the ID we gave it was assigned correctly
    assert pool_retval.id == str(16)
示例#6
0
    def create_server_pool(handle, org):
        from ucsmsdk.mometa.compute.ComputePool import ComputePool

        mo = ComputePool(parent_mo_or_dn=org, policy_owner="local", name="kubam", descr="")
        handle.add_mo(mo)
        try:
            handle.commit()
        except UcsException as err:
            if err.error_code == "103":
                print "\talready exists"
            else:
                return 1, err.error_descr
        return 0, None
def setup_serverpool(server, module):
    from ucsmsdk.mometa.compute.ComputePool import ComputePool
    from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot
    from ucsmsdk.mometa.compute.ComputePooledRackUnit import ComputePooledRackUnit
    from ucsmsdk.mometa.compute.ComputeRackUnit import ComputeRackUnit
    from ucsmsdk.mometa.fabric.FabricComputeSlotEp import FabricComputeSlotEp

    ansible = module.params
    args_mo = _get_mo_params(ansible)

    changed = False
    exists = False
    for pool in args_mo['pool_list']:
        mo = server.query_dn(args_mo['org_dn'] + '/compute-pool-' +
                             pool['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
                    if not "descr" in pool:
                        pool["descr"] = ""
                    nmo = ComputePool(parent_mo_or_dn=args_mo['org_dn'],
                                      name=pool["name"],
                                      descr=pool["descr"])
                    if "servers" in pool:
                        for ser in pool["servers"]:
                            ComputePooledRackUnit(parent_mo_or_dn=nmo,
                                                  id=str(ser))
                    if "blades" in pool:
                        for b in pool["blades"]:
                            ComputePooledSlot(parent_mo_or_dn=nmo,
                                              slot_id=re.sub("\/\d", "", b),
                                              chassis_id=re.sub("\d\/", "", b))

                    server.add_mo(nmo, True)
                    server.commit()
    return changed
示例#8
0
def addServersToKubePool(handle, servers, org):
    print "Adding servers to Kubernetes Pool"
    from ucsmsdk.mometa.compute.ComputePool import ComputePool
    from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot
    from ucsmsdk.mometa.compute.ComputePooledRackUnit import ComputePooledRackUnit
    mo = ComputePool(parent_mo_or_dn=org, policy_owner="local", name="Kubernetes", descr="")
    blades = handle.query_classid("computeBlade")
    if "blades" in servers:
        for s in servers["blades"]:
            reset_disks(handle, s)
            chassis, slot = s.split("/")
            ComputePooledSlot(parent_mo_or_dn=mo, slot_id=str(slot), chassis_id=str(chassis))
    if "rack_servers" in servers:
        for r in servers["rack_servers"]:
            ComputePooledRackUnit(parent_mo_or_dn=mo, id=r)
    handle.add_mo(mo, True)
    try: 
        handle.commit()
    except UcsException as err:
        if err.error_code == "103":
            print "\talready exists"
        else:
            return 1, err.error_descr
    return 0, ""
示例#9
0
Purpose:
    UCS Manager Create UCS Server Pool and associate to template
Author:
    John McDonough ([email protected]) github: (@movinalot)
    Cisco Systems, Inc.
"""

from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.compute.ComputePool import ComputePool
from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot
from ucsmsdk.mometa.ls.LsRequirement import LsRequirement

HANDLE = UcsHandle("sandbox-ucsm1.cisco.com", "admin", "password")
HANDLE.login()

SERVER_POOL = ComputePool(parent_mo_or_dn="org-root/org-devnet",
                          name="devcore_pool")

HANDLE.add_mo(SERVER_POOL, modify_present=True)

for blade in HANDLE.query_classid("computeBlade",
                                  filter_str='(chassis_id, "7")'):
    SERVER = ComputePooledSlot(parent_mo_or_dn=SERVER_POOL,
                               chassis_id=blade.chassis_id,
                               slot_id=blade.slot_id)
    HANDLE.add_mo(SERVER, modify_present=True)

HANDLE.commit()

SP_TEMPLATE = LsRequirement(
    parent_mo_or_dn="org-root/org-devnet/ls-devcore_template",
    name="devcore_pool")
## Mission: Programming Cisco Compute - Python Basic and Advanced
## Mission Exercise 2 - Solution

# Get a handle and login to UCS Manager
from ucsmsdk.ucshandle import UcsHandle
handle = UcsHandle("198.18.133.91", "admin", "password")
handle.login()

# Import Classes ComputePool and ComputePooledSlot
from ucsmsdk.mometa.compute.ComputePool import ComputePool
from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot

# Create a ComputePool Object
mo_pool = ComputePool(parent_mo_or_dn="org-root", name="Python_Heroes_Server_Pool")

handle.add_mo(mo_pool, modify_present=True)
handle.commit()

# Retrieve the ComputePool object and add Servers
filter_exp = '(name,"Python_Heroes_Server_Pool")'
mo_compute_pool = handle.query_classid("computePool",filter_str=filter_exp)

for slot_num in 1,2,3,4:
   mo_compute_pooled_slot = ComputePooledSlot(parent_mo_or_dn=mo_compute_pool[0].dn, chassis_id="2", slot_id=str(slot_num))
   handle.add_mo(mo_compute_pooled_slot, modify_present=True)

handle.commit()

# Logout of the UCS Manager
handle.logout()
示例#11
0
k = 1
while k < len(VLAN_ID):
    mo = FabricVlan(parent_mo_or_dn="fabric/lan", sharing="none", name=VLAN_Name[k], id=VLAN_ID[k], mcast_policy_name="", policy_owner="local", default_net="no", pub_nw_name="", compression_type="included")
    handle.add_mo(mo)
    handle.commit()
    print k
    k = k+1

#Create UUID Pool
mo = UuidpoolPool(parent_mo_or_dn=my_Full_Path_Org, policy_owner="local", prefix="derived", descr="UUID Pool", assignment_order="sequential", name="UUID_POOL")
mo_1 = UuidpoolBlock(parent_mo_or_dn=mo, to="0001-000000000100", r_from="0001-000000000001")
handle.add_mo(mo)
handle.commit()

#Create a Server Pool
mo = ComputePool(parent_mo_or_dn=my_Full_Path_Org, policy_owner="local", name="Server_Pool", descr="Server Pool")
mo_1 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="1", chassis_id="1")
mo_2 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="2", chassis_id="1")
mo_3 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="3", chassis_id="1")
mo_4 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="4", chassis_id="1")
mo_5 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="5", chassis_id="1")
#mo_6 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="6", chassis_id="1")
#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()
示例#12
0
#Remove UUID Pool
##### Start-Of-PythonScript #####

#mo = handle.query_dn("org-root/org-Sub_Org_Test/uuid-pool-UUID_POOL")
#handle.remove_mo(mo)
#handle.commit()
##### End-Of-PythonScript #####

#Create Server Pool
##### Start-Of-PythonScript #####

from ucsmsdk.mometa.compute.ComputePool import ComputePool
from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot

mo = ComputePool(parent_mo_or_dn="org-root/org-Sub_Org_Test",
                 policy_owner="local",
                 name="Server_Pool",
                 descr="Server Pool")
mo_1 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="1", chassis_id="1")
mo_2 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="2", chassis_id="1")
mo_3 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="3", chassis_id="1")
mo_4 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="4", chassis_id="1")
mo_5 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="5", chassis_id="1")
mo_6 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="7", chassis_id="1")
mo_7 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="8", chassis_id="1")
handle.add_mo(mo)
handle.commit()

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

#Delete Server Pool
##### Start-Of-PythonScript #####
示例#13
0
def server_pool(input):
    name = input['name']
    descr = input['descr']
    pooled_servers = input['pooled_servers']
    state = input['state']
    ip = input['ip']
    username = input['username']
    password = input['password']
    mo = ""
    mo_block = ""
    results = {}
    ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password)))
    ###-------CHECK IF MO EXISTS---------------------------------

    try:
        mo = ucs_handle.query_dn("org-root/compute-pool-" + name)
    except:
        results['error'] = "Could not query children of serverpool"

###----if expected state is "present"------------------------

    if state == "present":
        if mo:
            if (mo.descr == descr):
                if (len(pooled_servers) != 0):
                    local_mo_exists = True
                    for obj in pooled_servers:
                        mo_exists = pooled_server_exists(
                            ucs_handle, name, obj['chassis_id'],
                            obj['slot_id'])
                        local_mo_exists = (local_mo_exists and mo_exists)
                    if (local_mo_exists):
                        results['name'] = name
                        results['expected'] = True
                        results['changed'] = False
                        results['present'] = True
                    else:
                        for obj in pooled_servers:
                            mo_exists = pooled_server_exists(
                                ucs_handle, name, obj['chassis_id'],
                                obj['slot_id'])
                            if (mo_exists == False):
                                mo_1 = ComputePooledSlot(
                                    parent_mo_or_dn=mo,
                                    slot_id=obj['slot_id'],
                                    chassis_id=obj['chassis_id'])
                        ucs_handle.add_mo(mo, True)
                        ucs_handle.commit()
                        results['name'] = name
                        results['present'] = True
                        results['removed'] = False
                        results['changed'] = True
                else:
                    results['name'] = name
                    results['expected'] = True
                    results['changed'] = False
                    results['present'] = True

            else:
                try:
                    mo = ComputePool(parent_mo_or_dn="org-root",
                                     name=name,
                                     descr=descr)
                    if (len(pooled_servers) != 0):
                        local_mo_exists = True
                        for obj in pooled_servers:
                            mo_exists = pooled_server_exists(
                                ucs_handle, name, obj['chassis_id'],
                                obj['slot_id'])
                            local_mo_exists = (local_mo_exists and mo_exists)
                        if (local_mo_exists == False):
                            for obj in pooled_servers:
                                mo_exists = pooled_server_exists(
                                    ucs_handle, name, obj['chassis_id'],
                                    obj['slot_id'])
                                if (mo_exists == False):
                                    mo_1 = ComputePooledSlot(
                                        parent_mo_or_dn=mo,
                                        slot_id=obj['slot_id'],
                                        chassis_id=obj['chassis_id'])
                    ucs_handle.add_mo(mo, True)
                    ucs_handle.commit()

                    results['name'] = name
                    results['present'] = True
                    results['removed'] = False
                    results['changed'] = True

                except Exception as e:
                    results[
                        'error'] = "modification of server pool failed " + str(
                            e)

###----------if not, create boot policy with desired config ----------------

        else:
            try:
                mo = ComputePool(parent_mo_or_dn="org-root",
                                 name=name,
                                 descr=descr)
                if (len(pooled_servers) <> 0):
                    for obj in pooled_servers:
                        mo_1 = ComputePooledSlot(parent_mo_or_dn=mo,
                                                 slot_id=obj['slot_id'],
                                                 chassis_id=obj['chassis_id'])
                ucs_handle.add_mo(mo)
                ucs_handle.commit()
                results['name'] = name
                results['present'] = False
                results['created'] = True
                results['changed'] = True

            except Exception as e:
                results['error'] = "Server pool creation failed " + str(e)


###------if expected state is "absent"----------------------------

    if state == "absent":

        if mo:

            try:
                ucs_handle.remove_mo(mo)
                results['name'] = name
                results['present'] = False
                results['removed'] = True
                ucs_handle.commit()

            except Exception as e:
                results['error'] = "Removal server pool mo failed" + str(e)

        else:
            results['name'] = name
            results['removed'] = False
            results['present'] = False
    ucs_handle = pickle.dumps(ucs_handle)
    ucs_logout.main(ucs_handle)
    return results
示例#14
0
#256 MAC Addresses in each pool
fabric_a_from_var = "00:25:b5:33:A0:00"
fabric_a_to_var = "00:25:b5:33:A0:FF"
fabric_b_from_var = "00:25:b5:33:B0:00"
fabric_b_to_var = "00:25:b5:33:B0:FF"
wwnn_from_var = "20:00:00:25:B5:33:00:00"
wwnn_to_var = "20:00:00:25:B5:33:00:FF"
wwpn_a_from_var = "20:00:00:25:B5:33:A0:00"
wwpn_a_to_var = "20:00:00:25:B5:33:A0:FF"
wwpn_b_from_var = "20:00:00:25:B5:33:B0:00"
wwpn_b_to_var = "20:00:00:25:B5:33:B0:FF"

############################
#Create Server Pool ESX For Template
mo = ComputePool(parent_mo_or_dn="org-root", policy_owner="local", name="ESX", descr="")
#mo_1 = ComputePooledSlot(parent_mo_or_dn=mo, slot_id="2", chassis_id=“1”)
#mo_2 = …
handle.add_mo(mo)

#Create UUID Pool
mo = UuidpoolBlock(parent_mo_or_dn="org-root/uuid-pool-default", to="0303-000000000100", r_from="0303-000000000001")
handle.add_mo(mo)

#FABRIC_A
mo = MacpoolPool(parent_mo_or_dn="org-root", policy_owner="local", descr="", assignment_order="sequential", name="Fabric_A")
mo_1 = MacpoolBlock(parent_mo_or_dn=mo, to=fabric_a_to_var, r_from=fabric_a_from_var)
handle.add_mo(mo)

#FABRIC_B
mo = MacpoolPool(parent_mo_or_dn="org-root", policy_owner="local", descr="", assignment_order="sequential", name="Fabric_B")
示例#15
0
                          assignment_order="default",
                          name="UUID_Pool")
        mo_1 = UuidpoolBlock(parent_mo_or_dn=mo,
                             to="0000-000000000020",
                             r_from="0000-000000000001")
        handle.add_mo(mo)

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

        from ucsmsdk.mometa.compute.ComputePool import ComputePool
        from ucsmsdk.mometa.compute.ComputePooledSlot import ComputePooledSlot

        mo = ComputePool(parent_mo_or_dn="org-root",
                         policy_owner="local",
                         name="Openstack_Controller_Pool",
                         descr="")
        for pool_parms in settings_file['controller_pool']:
            mo_1 = ComputePooledSlot(parent_mo_or_dn=mo,
                                     chassis_id=pool_parms['chassis'],
                                     slot_id=pool_parms['slot'])
        handle.add_mo(mo)

        handle.commit()

        mo = ComputePool(parent_mo_or_dn="org-root",
                         policy_owner="local",
                         name="Openstack_Compute_Pool",
                         descr="")
        for pool_parms in settings_file['compute_pool']:
            mo_1 = ComputePooledSlot(parent_mo_or_dn=mo,