예제 #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"
예제 #2
0
파일: ucs_server.py 프로젝트: madpabz/KUBaM
    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
예제 #3
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
예제 #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),
        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)
예제 #5
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")
예제 #6
0
#Create Sub Organization
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()
예제 #7
0
                policy_owner="local",
                default_net="no",
                pub_nw_name="",
                compression_type="included")
handle.add_mo(mo)
handle.commit()

#Create UUID Pool
##### Start-Of-PythonScript #####

from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool
from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock

mo = UuidpoolPool(parent_mo_or_dn="org-root/org-Sub_Org_Test",
                  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()
##### End-Of-PythonScript #####

#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()
예제 #8
0
        is_secure = True
        if settings_file['secure'] == "False":
            is_secure = False
        handle = ucshandle.UcsHandle(settings_file['ip'],
                                     settings_file['user'],
                                     settings_file['pw'],
                                     secure=is_secure)
        handle.login()
        ##### Start-Of-PythonScript #####

        from ucsmsdk.mometa.uuidpool.UuidpoolPool import UuidpoolPool
        from ucsmsdk.mometa.uuidpool.UuidpoolBlock import UuidpoolBlock

        mo = UuidpoolPool(parent_mo_or_dn="org-root",
                          policy_owner="local",
                          prefix="derived",
                          descr="",
                          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",