Ejemplo n.º 1
0
def createLanConnPolicy(handle, org):
    print "Creating Kubernetes LAN connectivity policy"
    from ucsmsdk.mometa.vnic.VnicLanConnPolicy import VnicLanConnPolicy
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    mo = VnicLanConnPolicy(parent_mo_or_dn=org, policy_owner="local", name="kube", descr="Kubernetes LAN Connectivity Policy")
    mo_1 = VnicEther(parent_mo_or_dn=mo, addr="derived", nw_ctrl_policy_name="", admin_vcon="any", stats_policy_name="default", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="Linux", ident_pool_name="", order="1", nw_templ_name="kubeA", name="eth0")
    mo_2 = VnicEther(parent_mo_or_dn=mo, addr="derived", nw_ctrl_policy_name="", admin_vcon="any", stats_policy_name="default", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="Linux", ident_pool_name="", order="2", nw_templ_name="kubeB", name="eth1")
    try: 
        handle.add_mo(mo)
        handle.commit()
    except UcsException as err:
        if err.error_code == "103":
            print "\tLAN connectivity policy 'kube' already exists"
Ejemplo n.º 2
0
def add_vnic(handle, parent_dn,  name, 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="", mtu="1500", qos_policy_name="",
             adaptor_profile_name="", ident_pool_name="", order="1", nw_templ_name="", addr="derived"):

    """
    Adds vNIC to LAN Connectivity Policy

    Args:
        handle
        parent_dn
        name
        nw_ctrl_policy_name
        admin_host_port
        admin_vcon
        stats_policy_name
        admin_cdn_name
        switch_id
        pin_to_group_name
        mtu
        qos_policy_name
        adaptor_profile_name
        ident_pool_name
        order
        nw_templ_name
        addr

    Returns:
        None

    Example:
        add_vnic(handle, "org-root/lan-conn-pol-samp_conn_pol2", "test_vnic", "vinbs_nw", "ANY",
                "any", "default", "wqdwq", "A", "", "1500")
    """

    from ucsmsdk.mometa.vnic.VnicEther import VnicEther

    obj = handle.query_dn(parent_dn)
    if obj:
        mo_1 = VnicEther(parent_mo_or_dn=obj,
                         nw_ctrl_policy_name=nw_ctrl_policy_name,
                         name=name,
                         admin_host_port=admin_host_port,
                         admin_vcon=admin_vcon,
                         stats_policy_name=stats_policy_name,
                         admin_cdn_name=admin_cdn_name,
                         switch_id=switch_id,
                         pin_to_group_name=pin_to_group_name,
                         mtu=mtu,
                         qos_policy_name=qos_policy_name,
                         adaptor_profile_name=adaptor_profile_name,
                         ident_pool_name=ident_pool_name,
                         order=order,
                         nw_templ_name=nw_templ_name,
                         addr=addr)

        handle.add_mo(mo_1, modify_present=True)
        handle.commit()
    else:
        log.info(parent_dn + " MO is not available")
def configure_lan_connectivity(ucs, module, dn):
    from ucsmsdk.mometa.vnic.VnicLanConnPolicy import VnicLanConnPolicy
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicIScsiLCP import VnicIScsiLCP
    from ucsmsdk.mometa.vnic.VnicVlan import VnicVlan

    if not module.check_mode:
        try:
            # create if mo does not already exist
            mo = VnicLanConnPolicy(
                parent_mo_or_dn=module.params['org_dn'],
                name=module.params['name'],
                descr=module.params['description'],
            )

            if module.params.get('vnic_list'):
                for vnic in module.params['vnic_list']:
                    if vnic['state'] == 'absent':
                        child_dn = dn + '/ether-' + vnic['name']
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            ucs.login_handle.remove_mo(mo_1)
                    else:  # state == 'present'
                        mo_1 = VnicEther(
                            addr='derived',
                            parent_mo_or_dn=mo,
                            name=vnic['name'],
                            adaptor_profile_name=vnic['adapter_policy'],
                            nw_templ_name=vnic['vnic_template'],
                            order=vnic['order'],
                        )

            if module.params.get('iscsi_vnic_list'):
                for iscsi_vnic in module.params['iscsi_vnic_list']:
                    if iscsi_vnic['state'] == 'absent':
                        child_dn = dn + '/iscsi-' + iscsi_vnic['name']
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            ucs.login_handle.remove_mo(mo_1)
                    else:  # state == 'present'
                        mo_1 = VnicIScsiLCP(
                            parent_mo_or_dn=mo,
                            name=iscsi_vnic['name'],
                            adaptor_profile_name=iscsi_vnic[
                                'iscsi_adapter_policy'],
                            vnic_name=iscsi_vnic['overlay_vnic'],
                            addr=iscsi_vnic['mac_address'],
                        )
                        VnicVlan(
                            parent_mo_or_dn=mo_1,
                            vlan_name=iscsi_vnic['vlan_name'],
                        )

            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
def create_service_profile(name, handle):
    # Service Profile
    sp = LsServer(parent_mo_or_dn="org-root", name=name)
    # Vnic eth0
    vnic_eth0 = VnicEther(parent_mo_or_dn=sp, name="eth0")
    VnicEtherIf(parent_mo_or_dn=vnic_eth0, default_net="yes", name="default")
    # Vnic eth1
    vnic_eth1 = VnicEther(parent_mo_or_dn=sp, name="eth1")
    VnicEtherIf(parent_mo_or_dn=vnic_eth1, default_net="yes", name="default")
    VnicFcNode(parent_mo_or_dn=sp, ident_pool_name="", addr="pool-derived")
    handle.add_mo(sp)
    try:
        handle.commit()
    except:
        print "Error creating Service Profile"
        sys.exit(1)
    handle.logout()
Ejemplo n.º 5
0
def setup_lan_connectivity(server, module):
    from ucsmsdk.mometa.vnic.VnicLanConnPolicy import VnicLanConnPolicy
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther

    ansible = module.params
    args_mo  =  _get_mo_params(ansible)

    changed = False

    for lan_conn in args_mo['lan_conn_list']:
        exists = False
        mo = server.query_dn(args_mo['org_dn']+'/lan-conn-pol-'+lan_conn['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
	            mo = VnicLanConnPolicy(parent_mo_or_dn=args_mo['org_dn'],
	                                   name=lan_conn['name'])
                    for vnic in lan_conn['vnic_list']:
                        mo_2 = VnicEther(parent_mo_or_dn=mo,
                                      addr="derived",
		                      adaptor_profile_name=vnic['adapter_policy'],
			              order=vnic['order'],
			              name=vnic['name'],
			              nw_templ_name=vnic['vnic_template'])

                    server.add_mo(mo, True)
                    server.commit()
    
    return changed
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
def run(job, resource, *args, **kwargs):
    username = conn.username
    password = conn.password

    organization = "{{ organization }}"
    service_profile_template = "{{ service_profile_template }}"
    create_sp_from_sp_template = "{{ create_sp_from_sp_template }}"
    service_profile_name = "{{ service_profile_name }}"
    service_profile_description = "{{ service_profile_description }}"
    use_blade_servers = "{{ use_blade_servers }}"
    chassis = "{{ chassis }}"
    ucs_server_dn = "{{ ucs_server_dn }}"
    ucs_rack_server = "{{ rack_server }}"
    mac_pool_name = "{{ mac_pool_name }}"

    service_profile_server_dn, _ = CustomField.objects.get_or_create(
        name="service_profile_server_dn",
        label="Service Profile Server DN",
        type="STR",
        show_on_servers=True)

    handler.login()
    ucs_event_handler = UcsEventHandle(handler)

    # create SP in an org
    set_progress(f"Creating service profile named {service_profile_name}")
    if create_sp_from_sp_template == "True":
        dn_set = ucscbasetype.DnSet()
        dn_set.child_add(Dn(value=f"{service_profile_name}"))

        xml_element = mf.ls_instantiate_n_named_template(
            cookie=handler.cookie,
            dn=service_profile_template,
            in_error_on_existing="true",
            in_name_set=dn_set,
            in_target_org=organization)
        handler.process_xml_elem(xml_element)
    else:
        mo = LsServer(parent_mo_or_dn=organization,
                      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=service_profile_description,
                      stats_policy_name="default",
                      policy_owner="local",
                      ext_ip_pool_name="ext-mgmt",
                      boot_policy_name="",
                      usr_lbl="",
                      host_fw_policy_name="",
                      vcon_profile_name="",
                      ident_pool_name="",
                      src_templ_name="",
                      local_disk_policy_name="",
                      scrub_policy_name="",
                      power_policy_name="default",
                      maint_policy_name="",
                      name=service_profile_name,
                      resolve_remote="yes")
        mo_1 = LsbootDef(parent_mo_or_dn=mo,
                         descr="",
                         reboot_on_update="no",
                         adv_boot_order_applicable="no",
                         policy_owner="local",
                         enforce_vnic_name="yes",
                         boot_mode="legacy")
        mo_1_1 = LsbootStorage(parent_mo_or_dn=mo_1, order="1")
        mo_1_1_1 = LsbootLocalStorage(parent_mo_or_dn=mo_1_1, )
        mo_1_1_1_1 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_1_1_1,
                                             order="1")
        mo_2 = VnicEther(parent_mo_or_dn=mo,
                         nw_ctrl_policy_name="",
                         name="eth0",
                         admin_host_port="ANY",
                         admin_vcon="any",
                         stats_policy_name="default",
                         admin_cdn_name="",
                         switch_id="A",
                         pin_to_group_name="",
                         mtu="1500",
                         qos_policy_name="",
                         adaptor_profile_name="",
                         ident_pool_name=mac_pool_name,
                         order="unspecified",
                         nw_templ_name="",
                         addr="derived")
        mo_2_1 = VnicEtherIf(parent_mo_or_dn=mo_2,
                             default_net="yes",
                             name="default")
        mo_3 = VnicFcNode(parent_mo_or_dn=mo,
                          ident_pool_name="",
                          addr="pool-derived")
        handler.add_mo(mo)

    # Associate a server to a service profile.
    if use_blade_servers == "True":
        set_progress(
            f"Associating service profile {service_profile_name} with {ucs_server_dn}"
        )
        mo = LsBinding(
            parent_mo_or_dn=f"{organization}/ls-{service_profile_name}",
            pn_dn=ucs_server_dn,
            restrict_migration="no")
    else:
        set_progress(
            f"Associating service profile {service_profile_name} with {ucs_rack_server}"
        )
        mo = LsBinding(
            parent_mo_or_dn=f"{organization}/ls-{service_profile_name}",
            pn_dn=ucs_rack_server,
            restrict_migration="no")

    handler.add_mo(mo)
    handler.commit()
    mo = handler.query_dn(f"{organization}/ls-{service_profile_name}")

    # Save the service profile dn
    resource.service_profile_server_dn = f"{organization}/ls-{service_profile_name}"
    resource.name = service_profile_name
    resource.save()

    return "SUCCESS", f"Created service profile named {service_profile_name}", ""
Ejemplo n.º 9
0
def test_001_policy():
    from ucsmsdk.mometa.flowctrl.FlowctrlItem import FlowctrlItem

    # #####################################
    # Create a Flow Control Policy
    # #####################################
    mo = FlowctrlItem(parent_mo_or_dn="fabric/lan/flowctrl", snd="off",
                      rcv="off", name="test", prio="on")
    handle.add_mo(mo)
    handle.commit()

    # #####################################
    # Delete Flow Control Policy
    # #####################################
    obj = handle.query_dn("fabric/lan/flowctrl/policy-test")
    handle.remove_mo(obj)
    handle.commit()

    # #####################################
    # Create Dynamic vNIC Connection Policy
    # #####################################
    from ucsmsdk.mometa.vnic.VnicDynamicConPolicy import VnicDynamicConPolicy

    mo = VnicDynamicConPolicy(parent_mo_or_dn="org-root", name="test",
                              descr="test", adaptor_profile_name="Linux",
                              policy_owner="local",
                              protection="protected-pref-b", dynamic_eth="54")
    handle.add_mo(mo)
    handle.commit()

    # #####################################
    # Delete Dynamic vNIC Connection Policy
    # #####################################
    obj = handle.query_dn("org-root/dynamic-con-test")
    handle.remove_mo(obj)
    handle.commit()

    # #####################################
    # Create LACP Policy
    # #####################################
    from ucsmsdk.mometa.fabric.FabricLacpPolicy import FabricLacpPolicy

    mo = FabricLacpPolicy(parent_mo_or_dn="org-root", fast_timer="fast",
                          policy_owner="local", suspend_individual="true",
                          name="test", descr="")
    handle.add_mo(mo)
    handle.commit()

    # #####################################
    # Modify LACP Policy
    # #####################################
    obj = handle.query_dn("org-root/lacp-test")
    obj.fast_timer = "normal"
    obj.suspend_individual = "false"
    obj.policy_owner = "local"
    obj.descr = ""
    handle.set_mo(obj)
    handle.commit()

    # #####################################
    # Delete LACP Policy
    # #####################################
    obj = handle.query_dn("org-root/lacp-test")
    handle.remove_mo(obj)
    handle.commit()

    # #####################################
    # Create LAN Connectivity Policy
    # #####################################
    from ucsmsdk.mometa.vnic.VnicLanConnPolicy import VnicLanConnPolicy
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicEtherIf import VnicEtherIf

    mo = VnicLanConnPolicy(parent_mo_or_dn="org-root", policy_owner="local",
                           name="test", descr="test_policy")
    mo_1 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="default",
                     name="test", admin_host_port="ANY", admin_vcon="any",
                     stats_policy_name="default", admin_cdn_name="",
                     switch_id="A", pin_to_group_name="", mtu="1500",
                     qos_policy_name="qos-1", adaptor_profile_name="Linux",
                     ident_pool_name="mac-pool-1", order="1", nw_templ_name="",
                     addr="derived")
    mo_1_1 = VnicEtherIf(parent_mo_or_dn=mo_1, default_net="yes",
                         name="default")
    handle.add_mo(mo)
    handle.commit()

    # #####################################
    # Delete LAN Connectivity Policy
    # #####################################
    obj = handle.query_dn("org-root/lan-conn-pol-test")
    handle.remove_mo(obj)
    handle.commit()

    # #####################################
    # Create QoS Policy
    # #####################################
    from ucsmsdk.mometa.epqos.EpqosDefinition import EpqosDefinition
    from ucsmsdk.mometa.epqos.EpqosEgress import EpqosEgress

    mo = EpqosDefinition(parent_mo_or_dn="org-root", policy_owner="local",
                         name="test", descr="")
    mo_1 = EpqosEgress(parent_mo_or_dn=mo, rate="line-rate",
                       host_control="none", name="", prio="best-effort",
                       burst="10240")
    handle.add_mo(mo)
    handle.commit()

    # #####################################
    # Delete QoS Policy
    # #####################################
    obj = handle.query_dn("org-root/ep-qos-test")
    handle.remove_mo(obj)
    handle.commit()
Ejemplo n.º 10
0
def add_vnic(handle,
             parent_dn,
             name,
             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="",
             mtu="1500",
             qos_policy_name="",
             adaptor_profile_name="",
             ident_pool_name="",
             order="1",
             nw_templ_name="",
             addr="derived"):
    """
    Adds vNIC to LAN Connectivity Policy

    Args:
        handle (UcsHandle)
        parent_dn (string): dn of VnicLanConnPolicy
        name (string): name of vnic
        nw_ctrl_policy_name (string): network control policy name
        admin_host_port (number): admin host port
        admin_vcon (string): ["1", "2", "3", "4", "any"]
        stats_policy_name (string): stats policy name
        admin_cdn_name (string): admin cdn name
        switch_id (string): ["A", "A-B", "B", "B-A", "NONE"]
        pin_to_group_name (string): pin to group name
        mtu (number):1500-9000
        qos_policy_name (string): qos policy name
        adaptor_profile_name (string): adaptor profile name
        ident_pool_name (string): ident pool name
        order (string):["unspecified"], ["0-256"]
        nw_templ_name (string): network template name
        addr (string): address

    Returns:
        VnicEther: Managed Object

    Raises:
        ValueError: If VnicLanConnPolicy object is not present

    Example:
        add_vnic(handle, "org-root/lan-conn-pol-samp_conn_pol2", "test_vnic",
                "vinbs_nw", "ANY", "any", "default", "wqdwq", "A", "", "1500")
    """

    from ucsmsdk.mometa.vnic.VnicEther import VnicEther

    obj = handle.query_dn(parent_dn)
    if obj:
        mo = VnicEther(parent_mo_or_dn=obj,
                       nw_ctrl_policy_name=nw_ctrl_policy_name,
                       name=name,
                       admin_host_port=admin_host_port,
                       admin_vcon=admin_vcon,
                       stats_policy_name=stats_policy_name,
                       admin_cdn_name=admin_cdn_name,
                       switch_id=switch_id,
                       pin_to_group_name=pin_to_group_name,
                       mtu=mtu,
                       qos_policy_name=qos_policy_name,
                       adaptor_profile_name=adaptor_profile_name,
                       ident_pool_name=ident_pool_name,
                       order=order,
                       nw_templ_name=nw_templ_name,
                       addr=addr)

        handle.add_mo(mo, modify_present=True)
        handle.commit()
        return mo
    else:
        raise ValueError(parent_dn + " MO is not available")
Ejemplo n.º 11
0
                mo = handle.query_dn(dn)
                if not mo:
                    mo = VnicLanConnPolicy(parent_mo_or_dn=org,
                                           policy_owner="local",
                                           name=row['LAN_Policy'],
                                           descr="")
                # add vnic and set vcon and vcon order.  Policy is always "Linux"
                mo_1 = VnicEther(parent_mo_or_dn=mo,
                                 cdn_prop_in_sync="yes",
                                 nw_ctrl_policy_name="",
                                 admin_host_port="ANY",
                                 admin_vcon="1",
                                 stats_policy_name="default",
                                 admin_cdn_name="",
                                 switch_id="NONE",
                                 pin_to_group_name="",
                                 name=row['vNIC_Name'],
                                 order=row['vNIC_Order'],
                                 qos_policy_name="",
                                 adaptor_profile_name="Linux",
                                 ident_pool_name="",
                                 cdn_source="vnic-name",
                                 mtu="1500",
                                 nw_templ_name=row['LAN_Policy_vNIC_Template'],
                                 addr="derived")

                handle.add_mo(mo, modify_present=True)
                handle.commit()
        handle.logout()

    except Exception, err:
        print "Exception:", str(err)
Ejemplo n.º 12
0
mo = FabricEthLanPc(parent_mo_or_dn="fabric/lan/B", name="PC-51", descr="", flow_ctrl_policy="default", admin_speed="10gbps", auto_negotiate="yes", admin_state="enabled", oper_speed="10gbps", port_id="51", lacp_policy_name="default")
mo_1 = FabricEthLanPcEp(parent_mo_or_dn=mo, eth_link_profile_name="default", name="", auto_negotiate="yes", slot_id="1", admin_state="enabled", port_id="3")
mo_2 = FabricEthLanPcEp(parent_mo_or_dn=mo, eth_link_profile_name="default", name="", auto_negotiate="yes", slot_id="1", admin_state="enabled", port_id="4")
handle.add_mo(mo)
handle.commit()

#Create Service Profile Template
if (FC and not iSCSI):
    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 Description", 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="initial-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="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)
Ejemplo n.º 13
0
x = combgen(12, 101)
p = OrderedDict(sorted(x.out3.items()))

p1 = {}
for (sp, eth), vlan in p.items():
    try:
        p1['sp' + str(sp)].append((eth, vlan))
    except:
        p1['sp' + str(sp)] = [(eth, vlan)]

handle = UcsHandle('10.127.97.156', 'admin', 'nbv12345')
handle.login()

for sp, eth_vlan in p1.items():
    mo = LsServer(parent_mo_or_dn="org-root", name="x{}".format(sp))
    for ev in eth_vlan:
        mo_1 = VnicEther(parent_mo_or_dn=mo,
                         switch_id="A-B",
                         ident_pool_name="default",
                         addr="derived",
                         name="{}".format('eth' + str(ev[0])),
                         mtu="9000")
        for _ in ev[1]:
            VnicEtherIf(parent_mo_or_dn=mo_1, name="x{}".format(_))

    handle.add_mo(mo)
    handle.commit()

handle.logout()
print "loggedout"
Ejemplo n.º 14
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=''),
        vnic_list=dict(type='list'),
        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.vnic.VnicLanConnPolicy import VnicLanConnPolicy
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicEtherIf import VnicEtherIf

    changed = False
    try:
        mo_exists = False
        props_match = False
        # dn is <org_dn>/lan-conn-pol-<name>
        dn = module.params['org_dn'] + '/lan-conn-pol-' + 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:
            # set default params.  Done here to set values for lists which can't be done in the argument_spec
            if module.params.get('vnic_list'):
                for vnic in module.params['vnic_list']:
                    if not vnic.get('adapter_policy'):
                        vnic['adapter_policy'] = ''
                    if not vnic.get('order'):
                        vnic['order'] = 'unspecified'
            if mo_exists:
                # check top-level mo props
                kwargs = dict(descr=module.params['description'])
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    if not module.params.get('vnic_list'):
                        props_match = True
                    else:
                        # check vnicEther props
                        for vnic in module.params['vnic_list']:
                            child_dn = dn + '/ether-' + vnic['name']
                            mo_1 = ucs.login_handle.query_dn(child_dn)
                            if mo_1:
                                kwargs = dict(
                                    adaptor_profile_name=vnic['adapter_policy']
                                )
                                kwargs['order'] = vnic['order']
                                kwargs['nw_templ_name'] = vnic['vnic_template']
                                if (mo_1.check_prop_match(**kwargs)):
                                    props_match = True

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

                    if module.params.get('vnic_list'):
                        for vnic in module.params['vnic_list']:
                            mo_1 = VnicEther(
                                addr='derived',
                                parent_mo_or_dn=mo,
                                name=vnic['name'],
                                adaptor_profile_name=vnic['adapter_policy'],
                                nw_templ_name=vnic['vnic_template'],
                                order=vnic['order'],
                            )

                    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)
Ejemplo n.º 15
0
    handle.add_mo(mo)

else :
    print "Last Step"
    

#Create Service Profile Template ESX
mo = LsServer(parent_mo_or_dn="org-root", 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="", stats_policy_name="default", policy_owner="local", ext_ip_pool_name="ext-mgmt", boot_policy_name="default", usr_lbl="", host_fw_policy_name="", vcon_profile_name="", ident_pool_name="default", src_templ_name="", type="updating-template", local_disk_policy_name="default", scrub_policy_name="", power_policy_name="default", maint_policy_name="User-Ack", name="ESX", resolve_remote="yes")
mo_1 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="1", transport="ethernet", vnic_name="VMDATA_A")
mo_2 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="2", transport="ethernet", vnic_name="VMDATA_B")
mo_3 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="3", transport="ethernet", vnic_name="vMotion_A")
mo_4 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="4", transport="ethernet", vnic_name="vMotion_B")
mo_5 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="5", transport="ethernet", vnic_name="mgmt_A")
mo_6 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="6", transport="ethernet", vnic_name="mgmt_B")
mo_7 = VnicDefBeh(parent_mo_or_dn=mo, name="", descr="", policy_owner="local", action="none", type="vhba", nw_templ_name="")
mo_8 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="VMDATA_A", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="1", nw_templ_name="VMDATA_A", addr="derived")
mo_9 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="VMDATA_B", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="B", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="2", nw_templ_name="VMDATA_B", addr="derived")
mo_11 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="vMotion_A", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="3", nw_templ_name="vMotion_A", addr="derived")
mo_12 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="vMotion_B", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="B", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="4", nw_templ_name="vMotion_B", addr="derived")
mo_13 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="mgmt_A", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="5", nw_templ_name="mgmt_A", addr="derived")
mo_14 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="mgmt_B", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="B", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="6", nw_templ_name="mgmt_B", addr="derived")
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")
if vnamenfs != "no":
    mo_20 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="7", transport="ethernet", vnic_name="NFS_A")
    mo_21 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="8", transport="ethernet", vnic_name="NFS_B")
    mo_22 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="NFS_A", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="7", nw_templ_name="NFS_A", addr="derived")
    mo_23 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="NFS_B", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", switch_id="B", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="8", nw_templ_name="NFS_B", addr="derived")
Ejemplo n.º 16
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
Ejemplo n.º 17
0
def test_002_sp_expert():
    '''
        This case is generated based on SP expert mode creation wizard.
    '''
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.ls.LsVConAssign import LsVConAssign
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicEtherIf import VnicEtherIf
    from ucsmsdk.mometa.vnic.VnicFc import VnicFc
    from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode
    from ucsmsdk.mometa.storage.StorageIniGroup import StorageIniGroup
    from ucsmsdk.mometa.vnic.VnicFcGroupDef import VnicFcGroupDef
    from ucsmsdk.mometa.storage.StorageInitiator import StorageInitiator
    from ucsmsdk.mometa.ls.LsPower import LsPower
    from ucsmsdk.mometa.fabric.FabricVCon import FabricVCon

    mo = LsServer(parent_mo_or_dn="org-root",
                  vmedia_policy_name="",
                  ext_ip_state="none",
                  bios_profile_name="SRIOV",
                  mgmt_fw_policy_name="",
                  agent_policy_name="",
                  mgmt_access_policy_name="",
                  dynamic_con_policy_name="",
                  kvm_mgmt_policy_name="",
                  sol_policy_name="",
                  uuid="00000000-0000-0000-0000-0000000000bb",
                  descr="",
                  stats_policy_name="default",
                  policy_owner="local",
                  ext_ip_pool_name="ext-mgmt",
                  boot_policy_name="default",
                  usr_lbl="",
                  host_fw_policy_name="",
                  vcon_profile_name="",
                  ident_pool_name="",
                  src_templ_name="",
                  local_disk_policy_name="default",
                  scrub_policy_name="",
                  power_policy_name="default",
                  maint_policy_name="",
                  name="test_sp",
                  resolve_remote="yes")
    mo_1 = LsVConAssign(parent_mo_or_dn=mo,
                        admin_vcon="any",
                        order="1",
                        transport="ethernet",
                        vnic_name="eth0")
    mo_2 = LsVConAssign(parent_mo_or_dn=mo,
                        admin_vcon="any",
                        order="2",
                        transport="fc",
                        vnic_name="fc0")
    mo_3 = VnicEther(parent_mo_or_dn=mo,
                     nw_ctrl_policy_name="",
                     name="eth0",
                     admin_host_port="ANY",
                     admin_vcon="any",
                     stats_policy_name="default",
                     admin_cdn_name="",
                     switch_id="A",
                     pin_to_group_name="",
                     mtu="1500",
                     qos_policy_name="",
                     adaptor_profile_name="",
                     ident_pool_name="default",
                     order="1",
                     nw_templ_name="",
                     addr="derived")
    mo_3_1 = VnicEtherIf(parent_mo_or_dn=mo_3,
                         default_net="yes",
                         name="default")
    mo_4 = VnicFc(parent_mo_or_dn=mo,
                  addr="derived",
                  name="fc0",
                  admin_host_port="ANY",
                  admin_vcon="any",
                  stats_policy_name="default",
                  admin_cdn_name="",
                  switch_id="A",
                  pin_to_group_name="",
                  pers_bind="disabled",
                  pers_bind_clear="no",
                  qos_policy_name="",
                  adaptor_profile_name="",
                  ident_pool_name="",
                  order="2",
                  nw_templ_name="",
                  max_data_field_size="2048")
    mo_4_1 = VnicFcIf(parent_mo_or_dn=mo_4, name="default")
    mo_5 = VnicFcNode(parent_mo_or_dn=mo,
                      ident_pool_name="",
                      addr="20:00:00:25:B5:00:00:00")
    mo_6 = StorageIniGroup(parent_mo_or_dn=mo,
                           name="test",
                           descr="",
                           group_policy_name="",
                           policy_name="",
                           policy_owner="local",
                           rmt_disk_cfg_name="")
    mo_6_1 = VnicFcGroupDef(parent_mo_or_dn=mo_6,
                            storage_conn_policy_name="",
                            policy_owner="local",
                            name="",
                            descr="",
                            stats_policy_name="default")
    mo_6_2 = StorageInitiator(parent_mo_or_dn=mo_6,
                              policy_owner="local",
                              name="fc0",
                              descr="")
    mo_7 = LsPower(parent_mo_or_dn=mo, state="admin-up")
    mo_8 = FabricVCon(parent_mo_or_dn=mo,
                      placement="physical",
                      fabric="NONE",
                      share="shared",
                      select="all",
                      transport="ethernet,fc",
                      id="1",
                      inst_type="auto")
    mo_9 = FabricVCon(parent_mo_or_dn=mo,
                      placement="physical",
                      fabric="NONE",
                      share="shared",
                      select="all",
                      transport="ethernet,fc",
                      id="2",
                      inst_type="auto")
    mo_10 = FabricVCon(parent_mo_or_dn=mo,
                       placement="physical",
                       fabric="NONE",
                       share="shared",
                       select="all",
                       transport="ethernet,fc",
                       id="3",
                       inst_type="auto")
    mo_11 = 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()

    obj = handle.query_dn("org-root/ls-test_sp")
    handle.remove_mo(obj)
    handle.commit()
def sp_create():
    # ###########################################
    # Create the SP that will be associated later
    # ###########################################
    log.debug("sp_create")
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.lsboot.LsbootDef import LsbootDef
    from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
    from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage
    from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import\
        LsbootDefaultLocalImage
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicEtherIf import VnicEtherIf
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode

    mo = LsServer(parent_mo_or_dn="org-root",
                  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="",
                  stats_policy_name="default",
                  policy_owner="local",
                  ext_ip_pool_name="ext-mgmt",
                  boot_policy_name="",
                  usr_lbl="",
                  host_fw_policy_name="",
                  vcon_profile_name="",
                  ident_pool_name="",
                  src_templ_name="",
                  local_disk_policy_name="",
                  scrub_policy_name="",
                  power_policy_name="default",
                  maint_policy_name="",
                  name="test_sp",
                  resolve_remote="yes")
    mo_1 = LsbootDef(parent_mo_or_dn=mo,
                     descr="",
                     reboot_on_update="no",
                     adv_boot_order_applicable="no",
                     policy_owner="local",
                     enforce_vnic_name="yes",
                     boot_mode="legacy")
    mo_1_1 = LsbootStorage(parent_mo_or_dn=mo_1, order="1")
    mo_1_1_1 = LsbootLocalStorage(parent_mo_or_dn=mo_1_1, )
    mo_1_1_1_1 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_1_1_1, order="1")
    mo_2 = VnicEther(parent_mo_or_dn=mo,
                     nw_ctrl_policy_name="",
                     name="eth0",
                     admin_host_port="ANY",
                     admin_vcon="any",
                     stats_policy_name="default",
                     admin_cdn_name="",
                     switch_id="A",
                     pin_to_group_name="",
                     mtu="1500",
                     qos_policy_name="",
                     adaptor_profile_name="",
                     ident_pool_name="",
                     order="unspecified",
                     nw_templ_name="",
                     addr="derived")
    mo_2_1 = VnicEtherIf(parent_mo_or_dn=mo_2,
                         default_net="yes",
                         name="default")
    mo_3 = VnicFcNode(parent_mo_or_dn=mo,
                      ident_pool_name="",
                      addr="pool-derived")
    handle.add_mo(mo)
    handle.commit()