Example #1
0
def createKubeUUIDPools(handle, org):
    print "Creating Kube UUID Pools"
    from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool
    from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock
    mo = UuidpoolPool(parent_mo_or_dn=org, policy_owner="local", prefix="derived", descr="Kubernetes Pool", assignment_order="default", name="kube")
    mo_1 = UuidpoolBlock(parent_mo_or_dn=mo, to="C888-888888888100", r_from="C888-888888888001")
    handle.add_mo(mo)
    try: 
        handle.commit()
    except UcsException as err:
        if err.error_code == "103":
            print "\talready exists"
Example #2
0
    def create_uuid_pools(handle, org):
        from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool
        from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock

        print "Creating UUID Pools"
        mo = UuidpoolPool(
            parent_mo_or_dn=org, policy_owner="local", prefix="derived",
            descr="KUBAM Pool", assignment_order="default", name="kubam"
        )
        UuidpoolBlock(parent_mo_or_dn=mo, to="C888-888888888100", r_from="C888-888888888001")
        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
Example #3
0
def main():
    handle = UcsHandle("192.168.254.200","ucspe","ucspe", secure=False)
    handle.login()

    ## Acknolwedge Chassis
    mo = EquipmentChassis(parent_mo_or_dn="sys", admin_state="re-acknowledge", id="5")
    handle.add_mo(mo, True)
    handle.commit()

    ## Update MAC Pool
    mo = MacpoolBlock(parent_mo_or_dn="org-root/mac-pool-default", r_from="00:25:B5:00:00:00", to="00:25:B5:00:00:C7")
    handle.add_mo(mo)
    handle.commit()

    ## Update UUID Pools
    handle.query_dn("org-root/uuid-pool-default")
    mo = UuidpoolBlock(parent_mo_or_dn="org-root/uuid-pool-default", r_from="0000-000000000001", to="0000-0000000000C8")
    handle.add_mo(mo)
    handle.commit()

    ## Setup Fabric Ethernet Uplink A Side
    mo = FabricEthLan(parent_mo_or_dn="fabric/lan", id="A")
    mo_1 = FabricEthLanEp(parent_mo_or_dn=mo, admin_speed="10gbps", admin_state="enabled", auto_negotiate="yes", eth_link_profile_name="default", fec="auto", flow_ctrl_policy="default", name="", port_id="1", slot_id="1", usr_lbl="")
    handle.add_mo(mo, True)
    handle.commit()

    ## Setup Fabric Ethernet Uplink A Side
    mo = FabricEthLan(parent_mo_or_dn="fabric/lan", id="B")
    mo_1 = FabricEthLanEp(parent_mo_or_dn=mo, admin_speed="10gbps", admin_state="enabled", auto_negotiate="yes", eth_link_profile_name="default", fec="auto", flow_ctrl_policy="default", name="", port_id="1", slot_id="1", usr_lbl="")
    handle.add_mo(mo, True)
    handle.commit()

    ## Setup Service Profile Template
    mo = LsServer(parent_mo_or_dn="org-root", ident_pool_name="default", name="globotemplate", type="initial-template", uuid="00000000-0000-0000-0000-000000000000")
    handle.add_mo(mo)
    handle.commit()

    handle.logout()
Example #4
0
def setup_uuid(server, module):
    from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool
    from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock

    ansible = module.params
    args_mo = _get_mo_params(ansible)

    changed = False

    mo = server.query_dn(args_mo['org_dn'] + '/uuid-pool-' +
                         args_mo['uuid_pool']['name'])
    if mo:
        exists = True
    else:
        exists = False

    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 = UuidpoolPool(parent_mo_or_dn=args_mo['org_dn'],
                                  name=args_mo['uuid_pool']['name'])
                if (args_mo['uuid_pool']['to'] <> ''
                        and args_mo['uuid_pool']['from'] <> ''):
                    mo_1 = UuidpoolBlock(parent_mo_or_dn=mo,
                                         to=args_mo['uuid_pool']['to'],
                                         r_from=args_mo['uuid_pool']['from'])
                server.add_mo(mo)
                server.commit()

    return changed
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        name=dict(type='str', required=True),
        description=dict(type='str', aliases=['descr'], default=''),
        order=dict(type='str',
                   default='default',
                   choices=['default', 'sequential']),
        prefix=dict(type='str', default=''),
        first_uuid=dict(type='str'),
        last_uuid=dict(type='str'),
        state=dict(default='present',
                   choices=['present', 'absent'],
                   type='str'),
    )
    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.uuidpool.UuidpoolPool import UuidpoolPool
    from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock

    ucs.result['changed'] = False
    try:
        mo_exists = False
        props_match = False
        # dn is <org_dn>/uuid-pool-<name>
        dn = module.params['org_dn'] + '/uuid-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()
                ucs.result['changed'] = True
        else:
            if mo_exists:
                # check top-level mo props
                kwargs = dict(assignment_order=module.params['order'])
                kwargs['descr'] = module.params['description']
                if module.params['prefix']:
                    kwargs['prefix'] = module.params['prefix']
                if mo.check_prop_match(**kwargs):
                    # top-level props match, check next level mo/props
                    if module.params['last_uuid'] and module.params[
                            'first_uuid']:
                        # uuid address block specified, check properties
                        block_dn = dn + '/block-from-' + module.params[
                            'first_uuid'].upper(
                            ) + '-to-' + module.params['last_uuid'].upper()
                        mo_1 = ucs.login_handle.query_dn(block_dn)
                        if mo_1:
                            props_match = True
                    else:
                        # no UUID address block specified, but top-level props matched
                        props_match = True

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

                    if module.params['last_uuid'] and module.params[
                            'first_uuid']:
                        mo_1 = UuidpoolBlock(
                            parent_mo_or_dn=mo,
                            to=module.params['last_uuid'],
                            r_from=module.params['first_uuid'],
                        )

                    ucs.login_handle.add_mo(mo, True)
                    ucs.login_handle.commit()
                ucs.result['changed'] = True

    except Exception as e:
        err = True
        ucs.result['msg'] = "setup error: %s " % str(e)

    if err:
        module.fail_json(**ucs.result)
    module.exit_json(**ucs.result)
Example #6
0
def uuid_pool(input):
	name = input['name']
	descr=input['descr']
	to=input['to']
	r_from=input['r_from']
	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/uuid-pool-"+name)
		mo_block=ucs_handle.query_dn("org-root/uuid-pool-"+name+"/block-from-"+r_from+"-to-"+to)
	except:
		print("Could not query children of uuid suffix pool")


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

	if state == "present":
		if mo:
			if ( mo.descr == descr ):
				if(to <> "" and r_from <> ""):
					if(mo_block):
						results['name']=name;
						results['expected'] = True;
						results['changed'] = False;
						results['present'] = True;
					else:
						mo_1= UuidpoolBlock(parent_mo_or_dn=mo, to=to, r_from=r_from)				
						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:
					modified_mo =   UuidpoolPool(parent_mo_or_dn="org-root", name=name, descr=descr)
					if(to <> "" and r_from <> ""):
						mo_1= UuidpoolBlock(parent_mo_or_dn=modified_mo, to=to, r_from=r_from)					
					ucs_handle.add_mo(modified_mo,True)
					ucs_handle.commit()
					results['name']=name;
					results['present'] = True;
					results['removed'] = False;
					results['changed'] = True

		   		except Exception,e:
					print(e)

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

		else:
			try:
				mo =  UuidpoolPool(parent_mo_or_dn="org-root", name=name, descr=descr)
				if(to <> "" and r_from <> ""):			
					mo_1= UuidpoolBlock(parent_mo_or_dn=mo, to=to, r_from=r_from)
				ucs_handle.add_mo(mo)
				ucs_handle.commit()
				results['name']=name;
				results['present'] = False;
				results['created'] = True;
				results['changed'] = True;


			except:
				print("uuid suffix pool creation failed")
Example #7
0
mo = OrgOrg(parent_mo_or_dn="org-root", name=my_Org, descr="Sub Organization")
handle.add_mo(mo)
handle.commit()

#Create Production VLANs
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()
Example #8
0
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")
mo_1 = MacpoolBlock(parent_mo_or_dn=mo, to=fabric_b_to_var, r_from=fabric_b_from_var)
handle.add_mo(mo)

#ENABLE CDP
mo = handle.query_dn("org-root/nwctrl-default")
mo.policy_owner = "local"