예제 #1
0
파일: ucs_server.py 프로젝트: madpabz/KUBaM
    def create_service_profile_template(handle, org):
        from ucsmsdk.mometa.ls.LsServer import LsServer
        from ucsmsdk.mometa.vnic.VnicConnDef import VnicConnDef
        from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
        # from ucsmsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding

        print "Creating KUBAM Service Profile Template"
        mo = LsServer(
            parent_mo_or_dn=org,
            policy_owner="local",
            name="KUBAM",
            descr="KUBAM Service Profile Template",
            type="updating-template",
            # Boot using Kubernetes Boot policy: local Disk, then Remote DVD
            boot_policy_name="kubam",
            # Default Maintenance Policy
            maint_policy_name="default",
            # scrub policy
            scrub_policy_name="kubam",
            # Bios Policy
            bios_profile_name="kubam",
            # UUID Pool
            ident_pool_name="kubam",
            # disks we use.
            local_disk_policy_name="kubam",

            # storage_profile_name="kubam",
            # virtual media policy
            vmedia_policy_name="kubam"
        )
        # Create vNIC Connection Policy
        VnicConnDef(parent_mo_or_dn=mo, lan_conn_policy_name="kubam")
        # Create server pool and add to template.
        LsRequirement(parent_mo_or_dn=mo, name="kubam")

        # Add storage profile.
        # LstorageProfileBinding(parent_mo_or_dn=mo, storage_profile_name="kubam")
        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
        except Exception as e:
            return 1, e
        return 0, None
def configure_service_profile_template(ucs, module):
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.vnic.VnicConnDef import VnicConnDef
    from ucsmsdk.mometa.vnic.VnicIScsiNode import VnicIScsiNode
    from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
    from ucsmsdk.mometa.ls.LsPower import LsPower
    from ucsmsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding
    from ucsmsdk.mometa.mgmt.MgmtInterface import MgmtInterface
    from ucsmsdk.mometa.mgmt.MgmtVnet import MgmtVnet
    from ucsmsdk.mometa.vnic.VnicIpV4MgmtPooledAddr import VnicIpV4MgmtPooledAddr

    if not module.check_mode:
        try:
            # create if mo does not already exist
            mo = LsServer(
                parent_mo_or_dn=module.params['org_dn'],
                bios_profile_name=module.params['bios_policy'],
                boot_policy_name=module.params['boot_policy'],
                descr=module.params['description'],
                ext_ip_state='pooled',
                ext_ip_pool_name=module.params['mgmt_ip_pool'],
                # graphics_card_policy_name=module.params['graphics_card_policy'],
                host_fw_policy_name=module.params['host_firmware_package'],
                ident_pool_name=module.params['uuid_pool'],
                kvm_mgmt_policy_name=module.params['kvm_mgmt_policy'],
                local_disk_policy_name=module.params['local_disk_policy'],
                maint_policy_name=module.params['maintenance_policy'],
                mgmt_access_policy_name=module.params['ipmi_access_profile'],
                name=module.params['name'],
                power_policy_name=module.params['power_control_policy'],
                power_sync_policy_name=module.params['power_sync_policy'],
                scrub_policy_name=module.params['scrub_policy'],
                sol_policy_name=module.params['sol_policy'],
                stats_policy_name=module.params['threshold_policy'],
                type=module.params['template_type'],
                usr_lbl=module.params['user_label'],
                vmedia_policy_name=module.params['vmedia_policy'],
            )

            if module.params['storage_profile']:
                # Storage profile
                mo_1 = LstorageProfileBinding(
                    parent_mo_or_dn=mo,
                    storage_profile_name=module.params['storage_profile'],
                )

            if module.params['mgmt_interface_mode']:
                # Management Interface
                mo_1 = MgmtInterface(
                    parent_mo_or_dn=mo,
                    mode=module.params['mgmt_interface_mode'],
                    ip_v4_state='pooled',
                )
                mo_2 = MgmtVnet(
                    parent_mo_or_dn=mo_1,
                    id='1',
                    name=module.params['mgmt_vnet_name'],
                )
                VnicIpV4MgmtPooledAddr(
                    parent_mo_or_dn=mo_2,
                    name=module.params['mgmt_inband_pool_name'],
                )

            # LAN/SAN connectivity policy
            mo_1 = VnicConnDef(
                parent_mo_or_dn=mo,
                lan_conn_policy_name=module.params['lan_connectivity_policy'],
                san_conn_policy_name=module.params['san_connectivity_policy'],
            )

            if module.params['iqn_pool']:
                # IQN pool
                mo_1 = VnicIScsiNode(
                    parent_mo_or_dn=mo,
                    iqn_ident_pool_name=module.params['iqn_pool']
                )

            # power state
            admin_state = 'admin-' + module.params['power_state']
            mo_1 = LsPower(
                parent_mo_or_dn=mo,
                state=admin_state,
            )

            if module.params['server_pool']:
                # server pool
                mo_1 = LsRequirement(
                    parent_mo_or_dn=mo,
                    name=module.params['server_pool'],
                    qualifier=module.params['server_pool_qualification'],
                )

            ucs.login_handle.add_mo(mo, True)
            ucs.login_handle.commit()
        except Exception as e:  # generic Exception handling because SDK can throw a variety of exceptions
            ucs.result['msg'] = "setup error: %s " % str(e)
            module.fail_json(**ucs.result)

    ucs.result['changed'] = True
예제 #3
0
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")
HANDLE.add_mo(SP_TEMPLATE, modify_present=True)
HANDLE.commit()

HANDLE.logout()
예제 #4
0
def sp_template_modify(ucs_handle, name, type=None, resolve_remote=None,
						descr=None, usr_lbl=None, src_templ_name=None,
						ext_ip_state="pooled", ext_ip_pool_name=None,
						ident_pool_name=None, vcon_profile_name=None,
						agent_policy_name=None, bios_profile_name=None,
						boot_policy_name=None, dynamic_con_policy_name=None,
						host_fw_policy_name=None, kvm_mgmt_policy_name=None,
						local_disk_policy_name=None, maint_policy_name=None,
						mgmt_access_policy_name=None, mgmt_fw_policy_name=None,
						power_policy_name=None, scrub_policy_name=None,
						sol_policy_name=None, stats_policy_name=None,
						vmedia_policy_name=None,storage_profile_name=None,vnic_name=None,
						vnic_template_name=None,vnic_order=None,adapter_profile_name=None,
						server_pool_name=None,parent_dn="org-root"):
	"""
	This method Modifies Service profile template.

	Args:
		ucs_handle (ucs_handle)
		name(string): Name of SP template
		type : "initial-template", "updating-template"
		resolve_remote : "no", "yes"
		descr (string): Basic description
		src_templ_name (string): Name of Source template
		ext_ip_state= :none", "pooled", "static"
		ext_ip_pool_name (string): Name of IP Pool
		ident_pool_name (string): Name of Ident pool
		agent_policy_name (string): Name of agent policy
		bios_profile_name (string): Name of bios profile
		boot_policy_name (string): Name of boot policy
		dynamic_con_policy_name (string): Name of dynamic connection policy
		host_fw_policy_name (string):  Name of Host firmware.
		kvm_mgmt_policy_name (string): KVM management policy
		lan_conn_policy_name (string): LAN connection policy
		local_disk_policy_name (string): Local disk policy
		maint_policy_name (string): Maintenance policy
		mgmt_access_policy_name(string): Access Management policy
		mgmt_fw_policy_name (string): Firmware management policy
		power_policy_name (string): Power policy
		san_conn_policy_name (string): SAN connection policy
		scrub_policy_name (string): Scrub policy
		sol_policy_name (string): SOL policy
		stats_policy_name (string): Statistics Policy
		vcon_profile_name (string): Virtual Connection profile policy
		vmedia_policy_name (string): Virtual media policy
		parent_dn= Parent DN

	Returns:
		LsServer: Managed Object

	Raises:
		ValueError: If LsServer is not present

	Example:
		sp_template_modify(ucs_handle, name="sample_temp",
				local_disk_policy="sample_local1")
	"""
	dn = parent_dn + "/ls-" + name
	mo = ucs_handle.query_dn(dn)
	if not mo:
		raise ValueError("SP '%s' does not exist" % dn)

	if resolve_remote is not None:
		mo.resolve_remote = resolve_remote
	if descr is not None:
		mo.descr = descr
	if usr_lbl is not None:
		mo.usr_lbl = usr_lbl
	if src_templ_name is not None:
		mo.src_templ_name = src_templ_name
	if ext_ip_state is not None:
		mo.ext_ip_state = ext_ip_state
	if ext_ip_pool_name is not None:
		mo.ext_ip_pool_name = ext_ip_pool_name
	if ident_pool_name is not None:
		mo.ident_pool_name = ident_pool_name
	if vcon_profile_name is not None:
		mo.vcon_profile_name = vcon_profile_name
	if agent_policy_name is not None:
		mo.agent_policy_name = agent_policy_name
	if bios_profile_name is not None:
		mo.bios_profile_name = bios_profile_name
	if boot_policy_name is not None:
		mo.boot_policy_name = boot_policy_name
	if dynamic_con_policy_name is not None:
		mo.dynamic_con_policy_name = dynamic_con_policy_name
	if host_fw_policy_name is not None:
		mo.host_fw_policy_name = host_fw_policy_name
	if kvm_mgmt_policy_name is not None:
		mo.kvm_mgmt_policy_name = kvm_mgmt_policy_name
	if local_disk_policy_name is not None:
		mo.local_disk_policy_name = local_disk_policy_name
	if maint_policy_name is not None:
		mo.maint_policy_name = maint_policy_name
	if mgmt_access_policy_name is not None:
		mo.mgmt_access_policy_name = mgmt_access_policy_name
	if mgmt_fw_policy_name is not None:
		mo.mgmt_fw_policy_name = mgmt_fw_policy_name
	if power_policy_name is not None:
		mo.power_policy_name = power_policy_name
	if scrub_policy_name is not None:
		mo.scrub_policy_name = scrub_policy_name
	if sol_policy_name is not None:
		mo.sol_policy_name = sol_policy_name
	if stats_policy_name is not None:
		mo.stats_policy_name = stats_policy_name
	if vmedia_policy_name is not None:
		mo.vmedia_policy_name = vmedia_policy_name
	if server_pool_name is not None:
		mo_1 = LsRequirement(parent_mo_or_dn=mo, name=server_pool_name)
	if storage_profile_name is not None:
		mo_1 = LstorageProfileBinding(parent_mo_or_dn=mo, storage_profile_name=storage_profile_name)
	if(vnic_name <> '' and vnic_template_name <> ''):
		mo_1 = VnicEther(parent_mo_or_dn=mo, adaptor_profile_name=adapter_profile_name, order=vnic_order, name=vnic_name, nw_templ_name=vnic_template_name)
	ucs_handle.set_mo(mo)
	ucs_handle.commit()
	return mo
예제 #5
0
def sp_template_create(ucs_handle, name, type, resolve_remote, descr="",
					usr_lbl="", src_templ_name="", ext_ip_state="pooled",
					ext_ip_pool_name="", ident_pool_name="",
					agent_policy_name="",
					bios_profile_name="",
					boot_policy_name="",
					dynamic_con_policy_name="",
					host_fw_policy_name="",
					kvm_mgmt_policy_name="",
					lan_conn_policy_name="",
					local_disk_policy_name="",
					maint_policy_name="",
					mgmt_access_policy_name="",
					mgmt_fw_policy_name="",
					power_policy_name="",
					san_conn_policy_name="",
					scrub_policy_name="",
					sol_policy_name="",
					stats_policy_name="",
					vcon_profile_name="",
					vmedia_policy_name="",
					server_pool_name="",
					adapter_profile_name="",
					vnic_template_name="",
					vnic_name="",
					vnic_order="",
					storage_profile_name="",
					parent_dn="org-root"):
	"""
	This method creates Service profile template.
	Args:
        ucs_handle (ucs_handle)
        name(string): Name of SP template
        type : "initial-template", "updating-template"
        resolve_remote : "no", "yes"
        descr (string): Basic description
        src_templ_name (string): Name of Source template
        ext_ip_state= :none", "pooled", "static"
        ext_ip_pool_name (string): Name of IP Pool
        ident_pool_name (string): Name of Ident pool
        agent_policy_name (string): Name of agent policy
        bios_profile_name (string): Name of bios profile
        boot_policy_name (string): Name of boot policy
        dynamic_con_policy_name (string): Name of dynamic connection policy
        host_fw_policy_name (string):  Name of Host firmware.
        kvm_mgmt_policy_name (string): KVM management policy
        lan_conn_policy_name (string): LAN connection policy
        local_disk_policy_name (string): Local disk policy
        maint_policy_name (string): Maintenance policy
        mgmt_access_policy_name(string): Access Management policy
        mgmt_fw_policy_name (string): Firmware management policy
        power_policy_name (string): Power policy
        san_conn_policy_name (string): SAN connection policy
        scrub_policy_name (string): Scrub policy
        sol_policy_name (string): SOL policy
        stats_policy_name (string): Statistics Policy
        vcon_profile_name (string): Virtual Connection profile policy
        vmedia_policy_name (string): Virtual media policy
        server_pool_name (string): Server Pool
        parent_dn= Parent DN

	Returns:
		Service Profile: Managed Object

	Raises:
		ValueError: If OrgOrg is not present

	Example:
		sp_template_create(ucs_handle, name="sample_temp", type="initial-template",
		resolve_remote="yes",local_disk_policy="sample_local")
	"""
	from ucsmsdk.mometa.ls.LsServer import LsServer
	from ucsmsdk.mometa.vnic.VnicConnDef import VnicConnDef
	from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
	from ucsmsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding
	from ucsmsdk.mometa.vnic.VnicEther import VnicEther
	from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode
	from ucsmsdk.mometa.vnic.VnicFc import VnicFc
	from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf
	from ucsmsdk.mometa.fabric.FabricVCon import FabricVCon
	from ucsmsdk.mometa.ls.LsPower import LsPower

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

	mo = LsServer(parent_mo_or_dn=obj,
				name=name,
				type=type,
				resolve_remote=resolve_remote,
				descr=descr,
				usr_lbl=usr_lbl,
				src_templ_name=src_templ_name,
				ext_ip_state=ext_ip_state,
				ext_ip_pool_name=ext_ip_pool_name,
				ident_pool_name=ident_pool_name,
				vcon_profile_name=vcon_profile_name,
				agent_policy_name=agent_policy_name,
				bios_profile_name=bios_profile_name,
				boot_policy_name=boot_policy_name,
				dynamic_con_policy_name=dynamic_con_policy_name,
				host_fw_policy_name=host_fw_policy_name,
				kvm_mgmt_policy_name=kvm_mgmt_policy_name,
				local_disk_policy_name=local_disk_policy_name,
				maint_policy_name=maint_policy_name,
				mgmt_access_policy_name=mgmt_access_policy_name,
				mgmt_fw_policy_name=mgmt_fw_policy_name,
				power_policy_name=power_policy_name,
				scrub_policy_name=scrub_policy_name,
				sol_policy_name=sol_policy_name,
				stats_policy_name=stats_policy_name,
				vmedia_policy_name=vmedia_policy_name
				)
	if(storage_profile_name <> ""):
		mo_1 = LstorageProfileBinding(parent_mo_or_dn=mo, storage_profile_name=storage_profile_name)
	if(vnic_name <> "" and vnic_template_name <> ""):
		mo_1 = VnicEther(parent_mo_or_dn=mo, adaptor_profile_name=adapter_profile_name, order=vnic_order, name=vnic_name, nw_templ_name=vnic_template_name)
	if(server_pool_name <> ""):
		mo_1 = LsRequirement(parent_mo_or_dn=mo, name=server_pool_name)

	# Add vNIC Connection Policy to template
	VnicConnDef(parent_mo_or_dn=mo,
				lan_conn_policy_name=lan_conn_policy_name,
				san_conn_policy_name=san_conn_policy_name)

	ucs_handle.add_mo(mo, True)
	ucs_handle.commit()
	return mo
예제 #6
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        service_profile_name=dict(type='str', required=True),
        server_assignment=dict(type='str', choices=['server', 'pool']),
        server_dn=dict(type='str'),
        server_pool_name=dict(type='str'),
        restrict_migration=dict(type='str', default='no', choices=['yes', 'no']),
        state=dict(default='present', choices=['present', 'absent'], type='str'),
    )
    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'present', ['server_assignment']],
            ['server_assignment', 'server', ['server_dn']],
            ['server_assignment', 'pool', ['server_pool_name']],
        ],
        mutually_exclusive=[
            ['server_dn', 'server_pool_name'],
        ],
    )
    # UCSModule verifies ucsmsdk is present and exits on failure.  Imports are below ucs object creation.
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
    from ucsmsdk.mometa.ls.LsBinding import LsBinding
    from ucsmsdk.mometa.ls.LsServer import LsServer

    changed = False
    ucs.result['assign_state'] = 'unassigned'
    ucs.result['assoc_state'] = 'unassociated'
    try:
        ls_mo_exists = False
        pn_mo_exists = False
        pn_req_mo_exists = False
        props_match = False

        # logical server distinguished name is <org>/ls-<name> and physical node dn appends 'pn' or 'pn-req'
        ls_dn = module.params['org_dn'] + '/ls-' + module.params['service_profile_name']
        ls_mo = ucs.login_handle.query_dn(ls_dn)
        if ls_mo:
            ls_mo_exists = True
            pn_dn = ls_dn + '/pn'
            pn_mo = ucs.login_handle.query_dn(pn_dn)
            if pn_mo:
                pn_mo_exists = True

            pn_req_dn = ls_dn + '/pn-req'
            pn_req_mo = ucs.login_handle.query_dn(pn_req_dn)
            if pn_req_mo:
                pn_req_mo_exists = True

        if module.params['state'] == 'absent':
            if ls_mo_exists and ls_mo.assign_state != 'unassigned':
                if pn_mo_exists:
                    if not module.check_mode:
                        ucs.login_handle.remove_mo(pn_mo)
                        ucs.login_handle.commit()
                    changed = True
                elif pn_req_mo_exists:
                    if not module.check_mode:
                        ucs.login_handle.remove_mo(pn_req_mo)
                        ucs.login_handle.commit()
                    changed = True
        elif ls_mo_exists:
            # check if logical server is assigned and associated
            ucs.result['assign_state'] = ls_mo.assign_state
            ucs.result['assoc_state'] = ls_mo.assoc_state
            if module.params['server_assignment'] == 'pool' and pn_req_mo_exists:
                # check the current pool
                kwargs = dict(name=module.params['server_pool_name'])
                kwargs['restrict_migration'] = module.params['restrict_migration']
                if pn_req_mo.check_prop_match(**kwargs):
                    props_match = True
            elif pn_mo_exists:
                kwargs = dict(pn_dn=module.params['server_dn'])
                kwargs['restrict_migration'] = module.params['restrict_migration']
                if pn_mo.check_prop_match(**kwargs):
                    props_match = True

            if not props_match:
                if not module.check_mode:
                    # create if mo does not already exist in desired state
                    mo = LsServer(
                        parent_mo_or_dn=module.params['org_dn'],
                        name=module.params['service_profile_name'],
                    )
                    if module.params['server_assignment'] == 'pool':
                        if pn_mo_exists:
                            ucs.login_handle.remove_mo(pn_mo)

                        mo_1 = LsRequirement(
                            parent_mo_or_dn=mo,
                            name=module.params['server_pool_name'],
                            restrict_migration=module.params['restrict_migration'],
                        )
                    else:
                        mo_1 = LsBinding(
                            parent_mo_or_dn=mo,
                            pn_dn=module.params['server_dn'],
                            restrict_migration=module.params['restrict_migration'],
                        )
                        ucs.login_handle.add_mo(mo_1, True)
                        ucs.login_handle.commit()
            
                        pn_req_mo = ucs.login_handle.query_dn(pn_req_dn)
                        if pn_req_mo:
                            # profiles from templates will add a server pool, so remove and add the server again
                            ucs.login_handle.remove_mo(pn_req_mo)

                    ucs.login_handle.add_mo(mo_1, True)
                    ucs.login_handle.commit()
                    ls_mo = ucs.login_handle.query_dn(ls_dn)
                    if ls_mo:
                        ucs.result['assign_state'] = ls_mo.assign_state
                        ucs.result['assoc_state'] = ls_mo.assoc_state
                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)
handle.add_mo(mo_mac_pool_block, modify_present=True)
handle.commit()

# Create a Service Profile Template and associate to a Server Pool
from ucsmsdk.mometa.ls.LsServer import LsServer
from ucsmsdk.mometa.ls.LsRequirement import LsRequirement

mo_sp_template = LsServer(parent_mo_or_dn="org-root", type="initial-template", name="CommanderCode_PY_Mission_Templ")

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

filter_exp = '(name,"CommanderCode_PY_Mission_Templ")'
mo_sp_templ = handle.query_classid("lsServer",filter_str=filter_exp)

mo_sp_templ_ls_requirement = LsRequirement(parent_mo_or_dn=mo_sp_templ[0].dn, name="Python_Heroes_Server_Pool")
handle.add_mo(mo_sp_templ_ls_requirement, modify_present=True)

# Instantiate a Service Profile from the Service Profile template
mo_sp = LsServer(parent_mo_or_dn="org-root", src_templ_name="CommanderCode_PY_Mission_Templ", name="CommanderCode_PY_Mission_Server")
handle.add_mo(mo_sp, modify_present=True)
handle.commit()

# Retrieve the Server Pool and view the Server Pool Server allocation
filter_exp = '(name,"Python_Heroes_Server_Pool")'
mo_compute_pool = handle.query_classid("ComputePool",filter_str=filter_exp)
mo_compute_pooled_slots = handle.query_children(in_mo=mo_compute_pool[0], class_id="ComputePooledSlot")
for mo_compute_pooled_slot in mo_compute_pooled_slots:
    print(mo_compute_pooled_slot.poolable_dn, mo_compute_pooled_slot.assigned_to_dn)

# Logout of the UCS Manager
예제 #8
0
def setup_spt(server, module):
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
    from ucsmsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicConnDef import VnicConnDef

    ansible = module.params
    args_mo = _get_mo_params(ansible)

    changed = False

    for spt in args_mo['spt_list']:
        mo = server.query_dn(args_mo['org_dn'] + '/ls-' + spt['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
                    if not 'vmedia_policy' in spt:
                        spt['vmedia_policy'] = ''
                    if not 'scrub_policy' in spt:
                        spt['scrub_policy'] = ''

                    mo = LsServer(parent_mo_or_dn=args_mo['org_dn'],
                                  name=spt['name'],
                                  type=spt['template_type'],
                                  resolve_remote='yes',
                                  descr='',
                                  usr_lbl='',
                                  src_templ_name='',
                                  ext_ip_state='pooled',
                                  ext_ip_pool_name='ext-mgmt',
                                  ident_pool_name=spt['uuid_pool'],
                                  vcon_profile_name='',
                                  agent_policy_name='',
                                  bios_profile_name=spt['bios_policy'],
                                  boot_policy_name=spt['boot_policy'],
                                  dynamic_con_policy_name='',
                                  host_fw_policy_name=spt['host_fw_package'],
                                  kvm_mgmt_policy_name='',
                                  local_disk_policy_name='',
                                  maint_policy_name='',
                                  mgmt_access_policy_name='',
                                  mgmt_fw_policy_name='',
                                  power_policy_name='',
                                  scrub_policy_name=spt['scrub_policy'],
                                  sol_policy_name='',
                                  stats_policy_name='',
                                  vmedia_policy_name=spt['vmedia_policy'])
                    if 'server_pool' in spt:
                        mo_1 = LsRequirement(parent_mo_or_dn=mo,
                                             name=spt['server_pool'])
                    if 'storage_profile' in spt:
                        mo_1 = LstorageProfileBinding(
                            parent_mo_or_dn=mo,
                            storage_profile_name=spt['storage_profile'])
                    if 'san_connectivity_policy' in spt:
                        mo_1 = VnicConnDef(
                            parent_mo_or_dn=mo,
                            san_conn_policy_name=spt['san_connectivity_policy']
                        )
                    if 'vnic_list' in spt:
                        for vnic in spt['vnic_list']:
                            if (vnic['vnic_name'] <> ''
                                    and vnic['vnic_template'] <> ''):
                                mo_1 = VnicEther(
                                    parent_mo_or_dn=mo,
                                    adaptor_profile_name=vnic[
                                        'vnic_adapter_policy'],
                                    order=vnic['vnic_order'],
                                    name=vnic['vnic_name'],
                                    nw_templ_name=vnic['vnic_template'])

                    if 'lan_connectivity_policy' in spt:
                        mo_x = VnicConnDef(
                            parent_mo_or_dn=mo,
                            lan_conn_policy_name=spt['lan_connectivity_policy']
                        )
    # create server pool and add to template.
                    server.add_mo(mo, True)
                    server.commit()

    return changed
예제 #9
0
    mo_1 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="1", transport="ethernet", vnic_name="MGMT-A")
    mo_2 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="2", transport="ethernet", vnic_name="MGMT-B")
    mo_3 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="3", transport="ethernet", vnic_name="VM-A")
    mo_4 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="4", transport="ethernet", vnic_name="VM-B")
    mo_5 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="5", transport="fc", vnic_name="fc-a")
    mo_6 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="6", transport="fc", vnic_name="fc-b")
    mo_7 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", name="MGMT-A", order="1", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="MGMT-A", addr="derived")
    mo_8 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", name="MGMT-B", order="2", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="MGMT-B", addr="derived")
    mo_9 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", name="VM-A", order="3", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="VM-A", addr="derived")
    mo_10 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", name="VM-B", order="4", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="VM-B", addr="derived")
    mo_11 = VnicFc(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", addr="derived", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", pers_bind="disabled", order="5", pers_bind_clear="no", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", max_data_field_size="2048", nw_templ_name="fc-a", name="fc-a")
    mo_11_1 = VnicFcIf(parent_mo_or_dn=mo_11, name="")
    mo_12 = VnicFc(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", addr="derived", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", pers_bind="disabled", order="6", pers_bind_clear="no", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", max_data_field_size="2048", nw_templ_name="fc-b", name="fc-b")
    mo_12_1 = VnicFcIf(parent_mo_or_dn=mo_12, name="")
    mo_13 = VnicFcNode(parent_mo_or_dn=mo, ident_pool_name="WWNN_Pool", addr="pool-derived")
    mo_14 = LsRequirement(parent_mo_or_dn=mo, restrict_migration="no", name="Server_Pool", qualifier="")
    mo_15 = LsPower(parent_mo_or_dn=mo, state="admin-up")
    mo_16 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="1", inst_type="auto")
    mo_17 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="2", inst_type="auto")
    mo_18 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="3", inst_type="auto")
    mo_19 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="4", inst_type="auto")
    handle.add_mo(mo)
    handle.commit()

if(iSCSI and not FC):
    mo = LsServer(parent_mo_or_dn=my_Full_Path_Org, vmedia_policy_name="", ext_ip_state="none", bios_profile_name="", mgmt_fw_policy_name="", agent_policy_name="", mgmt_access_policy_name="", dynamic_con_policy_name="", kvm_mgmt_policy_name="", sol_policy_name="", uuid="0", descr="SPT Desc", stats_policy_name="default", policy_owner="local", ext_ip_pool_name="ext-mgmt", boot_policy_name="Boot_Policy", usr_lbl="", host_fw_policy_name="", vcon_profile_name="", ident_pool_name="UUID_POOL", src_templ_name="", type="updating-template", local_disk_policy_name="Local_Disk_CP", scrub_policy_name="", power_policy_name="default", maint_policy_name="User_Ack", name=my_SPT, resolve_remote="yes")
    mo_1 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="1", transport="ethernet", vnic_name="MGMT-A")
    mo_2 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="2", transport="ethernet", vnic_name="MGMT-B")
    mo_3 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="3", transport="ethernet", vnic_name="VM-A")
    mo_4 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="4", transport="ethernet", vnic_name="VM-B")
    mo_5 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="5", transport="ethernet", vnic_name="iSCSI-A")
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        name=dict(type='str', required=True),
        bios_policy=dict(type='str', default=''),
        boot_policy=dict(type='str', default='default'),
        description=dict(type='str', aliases=['descr'], default=''),
        mgmt_ip_pool=dict(type='str', default='ext-mgmt'),
        graphics_card_policy=dict(type='str', default=''),
        host_firmware_package=dict(type='str', default=''),
        uuid_pool=dict(type='str', default='default'),
        kvm_mgmt_policy=dict(type='str', default=''),
        local_disk_policy=dict(type='str', default=''),
        maintenance_policy=dict(type='str', default=''),
        ipmi_access_profile=dict(type='str', default=''),
        power_control_policy=dict(type='str', default='default'),
        power_sync_policy=dict(type='str', default=''),
        scrub_policy=dict(type='str', default=''),
        sol_policy=dict(type='str', default=''),
        threshold_policy=dict(type='str', default='default'),
        template_type=dict(type='str',
                           default='initial-template',
                           choices=['initial-template', 'updating-template']),
        user_label=dict(type='str', default=''),
        vmedia_policy=dict(type='str', default=''),
        storage_profile=dict(type='str', default=''),
        lan_connectivity_policy=dict(type='str', default=''),
        san_connectivity_policy=dict(type='str', default=''),
        server_pool=dict(type='str', default=''),
        server_pool_qualification=dict(type='str', default=''),
        power_state=dict(type='str', default='up', choices=['up', 'down']),
        mgmt_interface_mode=dict(type='str',
                                 default='',
                                 choices=['', 'in-band']),
        mgmt_vnet_name=dict(type='str', default=''),
        mgmt_inband_pool_name=dict(type='str', default=''),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
    )
    ucs = UCSModule(module)

    err = False

    # UCSModule creation above verifies ucsmsdk is present and exits on failure.  Additional imports are done below.
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.vnic.VnicConnDef import VnicConnDef
    from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
    from ucsmsdk.mometa.ls.LsPower import LsPower
    from ucsmsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding
    from ucsmsdk.mometa.mgmt.MgmtInterface import MgmtInterface
    from ucsmsdk.mometa.mgmt.MgmtVnet import MgmtVnet
    from ucsmsdk.mometa.vnic.VnicIpV4MgmtPooledAddr import VnicIpV4MgmtPooledAddr

    changed = False
    try:
        mo_exists = False
        props_match = False
        dn = module.params['org_dn'] + '/ls-' + module.params['name']

        mo = ucs.login_handle.query_dn(dn)
        if mo:
            mo_exists = True

        if module.params['state'] == 'absent':
            # mo must exist but all properties do not have to match
            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(bios_profile_name=module.params['bios_policy'])
                kwargs['boot_policy_name'] = module.params['boot_policy']
                kwargs['descr'] = module.params['description']
                kwargs['ext_ip_pool_name'] = module.params['mgmt_ip_pool']
                # kwargs['graphics_card_policy_name'] = module.params['graphics_card_policy']
                kwargs['host_fw_policy_name'] = module.params[
                    'host_firmware_package']
                kwargs['ident_pool_name'] = module.params['uuid_pool']
                kwargs['kvm_mgmt_policy_name'] = module.params[
                    'kvm_mgmt_policy']
                kwargs['local_disk_policy_name'] = module.params[
                    'local_disk_policy']
                kwargs['maint_policy_name'] = module.params[
                    'maintenance_policy']
                kwargs['mgmt_access_policy_name'] = module.params[
                    'ipmi_access_profile']
                kwargs['power_policy_name'] = module.params[
                    'power_control_policy']
                kwargs['power_sync_policy_name'] = module.params[
                    'power_sync_policy']
                kwargs['scrub_policy_name'] = module.params['scrub_policy']
                kwargs['sol_policy_name'] = module.params['sol_policy']
                kwargs['stats_policy_name'] = module.params['threshold_policy']
                kwargs['type'] = module.params['template_type']
                kwargs['usr_lbl'] = module.params['user_label']
                kwargs['vmedia_policy_name'] = module.params['vmedia_policy']

                if mo.check_prop_match(**kwargs):
                    # top-level props match, check next level mo/props
                    # code below should discontinue checks once any mismatch is found

                    # check storage profile 1st
                    child_dn = dn + '/profile-binding'
                    mo_1 = ucs.login_handle.query_dn(child_dn)
                    if mo_1:
                        kwargs = dict(storage_profile_name=module.
                                      params['storage_profile'])
                        if mo_1.check_prop_match(**kwargs):
                            props_match = True
                    elif not module.params['storage_profile']:
                        # no stroage profile mo or desired state
                        props_match = True

                    if props_match:
                        props_match = False
                        # LAN/SAN connectivity policies
                        child_dn = dn + '/conn-def'
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            kwargs = dict(lan_conn_policy_name=module.
                                          params['lan_connectivity_policy'])
                            kwargs['san_conn_policy_name'] = module.params[
                                'san_connectivity_policy']
                            if mo_1.check_prop_match(**kwargs):
                                props_match = True
                        elif not module.params[
                                'lan_connectivity_policy'] and not module.params[
                                    'san_connectivity_policy']:
                            # no mo and no desired state
                            props_match = True

                    if props_match:
                        props_match = False
                        # inband management policies
                        child_dn = dn + '/iface-in-band'
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            kwargs = dict(
                                mode=module.params['mgmt_interface_mode'])
                            if mo_1.check_prop_match(**kwargs):
                                child_dn = child_dn + '/network'
                                mo_2 = ucs.login_handle.query_dn(child_dn)
                                if mo_2:
                                    kwargs = dict(
                                        name=module.params['mgmt_vnet_name'])
                                    if mo_2.check_prop_match(**kwargs):
                                        child_dn = child_dn + '/ipv4-pooled-addr'
                                        mo_3 = ucs.login_handle.query_dn(
                                            child_dn)
                                        if mo_3:
                                            kwargs = dict(
                                                name=module.
                                                params['mgmt_inband_pool_name']
                                            )
                                            if mo_3.check_prop_match(**kwargs):
                                                props_match = True
                        elif not module.params['mgmt_interface_mode']:
                            # no mo and no desired state
                            props_match = True

                    if props_match:
                        props_match = False
                        # power state
                        child_dn = dn + '/power'
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            kwargs = dict(state=module.params['power_state'])
                            if mo_1.check_prop_match(**kwargs):
                                props_match = True
                        elif not module.params['power_state']:
                            # no mo and no desired state
                            props_match = True

                    if props_match:
                        props_match = False
                        # server pool
                        child_dn = dn + '/pn-req'
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            kwargs = dict(name=module.params['server_pool'])
                            kwargs['qualifier'] = module.params[
                                'server_pool_qualification']
                            if mo_1.check_prop_match(**kwargs):
                                props_match = True
                        elif not module.params['server_pool']:
                            # no pn-req object and no server pool name provided
                            props_match = True

            if not props_match:
                if not module.check_mode:
                    # create if mo does not already exist
                    mo = LsServer(
                        parent_mo_or_dn=module.params['org_dn'],
                        bios_profile_name=module.params['bios_policy'],
                        boot_policy_name=module.params['boot_policy'],
                        descr=module.params['description'],
                        ext_ip_state='pooled',
                        ext_ip_pool_name=module.params['mgmt_ip_pool'],
                        # graphics_card_policy_name=module.params['graphics_card_policy'],
                        host_fw_policy_name=module.
                        params['host_firmware_package'],
                        ident_pool_name=module.params['uuid_pool'],
                        kvm_mgmt_policy_name=module.params['kvm_mgmt_policy'],
                        local_disk_policy_name=module.
                        params['local_disk_policy'],
                        maint_policy_name=module.params['maintenance_policy'],
                        mgmt_access_policy_name=module.
                        params['ipmi_access_profile'],
                        name=module.params['name'],
                        power_policy_name=module.
                        params['power_control_policy'],
                        power_sync_policy_name=module.
                        params['power_sync_policy'],
                        scrub_policy_name=module.params['scrub_policy'],
                        sol_policy_name=module.params['sol_policy'],
                        stats_policy_name=module.params['threshold_policy'],
                        type=module.params['template_type'],
                        usr_lbl=module.params['user_label'],
                        vmedia_policy_name=module.params['vmedia_policy'],
                    )

                    if module.params['storage_profile']:
                        # Storage profile
                        mo_1 = LstorageProfileBinding(
                            parent_mo_or_dn=mo,
                            storage_profile_name=module.
                            params['storage_profile'],
                        )

                    if module.params['mgmt_interface_mode']:
                        # Management Interface
                        mo_1 = MgmtInterface(
                            parent_mo_or_dn=mo,
                            mode=module.params['mgmt_interface_mode'],
                            ip_v4_state='pooled',
                        )
                        mo_2 = MgmtVnet(
                            parent_mo_or_dn=mo_1,
                            id='1',
                            name=module.params['mgmt_vnet_name'],
                        )
                        mo_3 = VnicIpV4MgmtPooledAddr(
                            parent_mo_or_dn=mo_2,
                            name=module.params['mgmt_inband_pool_name'],
                        )

                    # LAN/SAN connectivity policy
                    mo_1 = VnicConnDef(
                        parent_mo_or_dn=mo,
                        lan_conn_policy_name=module.
                        params['lan_connectivity_policy'],
                        san_conn_policy_name=module.
                        params['san_connectivity_policy'],
                    )

                    # power state
                    admin_state = 'admin-' + module.params['power_state']
                    mo_1 = LsPower(
                        parent_mo_or_dn=mo,
                        state=admin_state,
                    )

                    if module.params['server_pool']:
                        # server pool
                        mo_1 = LsRequirement(
                            parent_mo_or_dn=mo,
                            name=module.params['server_pool'],
                            qualifier=module.
                            params['server_pool_qualification'],
                        )

                    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)
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        service_profile_name=dict(type='str', required=True),
        association_rn=dict(type='str', default='pn', choices=['pn', 'pn-req']),
        server_dn=dict(type='str'),
        server_pool_name=dict(type='str'),
        restrict_migration=dict(type='str', default='no', choices=['yes', 'no']),
        state=dict(default='present', choices=['present', 'absent'], type='str'),
    )
    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        mutually_exclusive=[
            ['server_dn', 'server_pool_name'],
        ],
    )
    # UCSModule verifies ucsmsdk is present and exits on failure.  Imports are below ucs object creation.
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
    from ucsmsdk.mometa.ls.LsBinding import LsBinding

    changed = False
    ucs.result['assign_state'] = 'unassigned'
    ucs.result['assoc_state'] = 'unassociated'
    try:
        ls_mo_exists = False
        pn_mo_exists = False
        props_match = False

        # logical server distinguished name is <org>/ls-<name> and physical node dn appends 'pn' or 'pn-req'
        ls_dn = module.params['org_dn'] + '/ls-' + module.params['service_profile_name']
        ls_mo = ucs.login_handle.query_dn(ls_dn)
        if ls_mo:
            ls_mo_exists = True

        if module.params['state'] == 'absent':
            if ls_mo_exists and ls_mo.assign_state != 'unassigned':
                # query pn then pn-req to find server association
                pn_dn = ls_dn + '/pn'
                pn_mo = ucs.login_handle.query_dn(pn_dn)
                if pn_mo:
                    pn_mo_exists = True
                else:
                    pn_dn = ls_dn + '/pn-req'
                    pn_mo = ucs.login_handle.query_dn(pn_dn)
                    if pn_mo:
                        pn_mo_exists = True

            if pn_mo_exists:
                if not module.check_mode:
                    ucs.login_handle.remove_mo(pn_mo)
                    ucs.login_handle.commit()
                changed = True
        else:
            if ls_mo_exists:
                # verify logical server is assigned and associated
                # when server slots are being pre-provisioned (assigned is false), this module always tries to change state
                ucs.result['assign_state'] = ls_mo.assign_state
                ucs.result['assoc_state'] = ls_mo.assoc_state
                if ls_mo.assign_state == 'assigned' and ls_mo.assoc_state == 'associated':
                    props_match = True

            if not props_match:
                if not module.check_mode:
                    # create if mo does not already exist in desired state
                    if module.params.get('server_dn'):
                        mo = LsBinding(
                            parent_mo_or_dn=ls_dn,
                            pn_dn=module.params['server_dn'],
                            restrict_migration=module.params['restrict_migration'],
                        )
                    else:
                        mo = LsRequirement(
                            parent_mo_or_dn=ls_dn,
                            name=module.params['server_pool_name'],
                            restrict_migration=module.params['restrict_migration'],
                        )

                    ucs.login_handle.add_mo(mo, True)
                    ucs.login_handle.commit()
                    ls_mo = ucs.login_handle.query_dn(ls_dn)
                    if ls_mo:
                        ucs.result['assign_state'] = ls_mo.assign_state
                        ucs.result['assoc_state'] = ls_mo.assoc_state
                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)
                                   	       scrub_policy_name="",
                                   	       sol_policy_name="",
                                   	       stats_policy_name="",
                                   	       vcon_profile_name=row['vNIC_placement'],
                                   	       vmedia_policy_name="",
                                   	       parent_dn=org)
	    # create the actual service profiles
            service_profile.sp_create_from_template(handle,
                                                    naming_prefix=profile_name,
                                                    name_suffix_starting_number="1",
                                                    number_of_instance=num_instances,
                                                    sp_template_name=template,
                                                    in_error_on_existing="true",
						    parent_dn=org)
            server_pool = row['Server-Pool'] if (row['Server-Pool']) else 'default'
	    for instance in range(1, num_instances + 1):
	        dn = "%s/ls-%s%d" % (org, profile_name, instance)
	        mo = LsRequirement(parent_mo_or_dn=dn, restrict_migration="no",
		                   name=server_pool, qualifier="")
	        handle.add_mo(mo, True)
	        handle.commit()
        handle.logout()

    except Exception, err:
        print "Exception:", str(err)
        import traceback, sys
        print '-'*60
        traceback.print_exc(file=sys.stdout)
        print '-'*60