def create(): from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy from ucsmsdk.mometa.vnic.VnicFc import VnicFc from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode mo = VnicSanConnPolicy(parent_mo_or_dn="org-root", policy_owner="local", name="TestSANConPolicy", descr="TestSANConPolicy") mo_1 = VnicFc(parent_mo_or_dn=mo, addr="derived", name="TestWWPNForSAN", 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="test001", order="1", nw_templ_name="", max_data_field_size="2048") mo_1_1 = VnicFcIf(parent_mo_or_dn=mo_1, name="default") mo_2 = VnicFcNode(parent_mo_or_dn=mo, ident_pool_name="WWNtestPool", addr="pool-derived") handle.add_mo(mo) handle.commit()
def modify_Fc(): from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy from ucsmsdk.mometa.vnic.VnicFc import VnicFc mo = VnicSanConnPolicy(parent_mo_or_dn="org-root", policy_owner="local", name="TestSANConPolicy", descr="Test SAN Connectivity Policy Change Test") mo_1 = VnicFc(parent_mo_or_dn=mo, addr="derived", name="TestvHBA001", 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="WWPNTEST001", order="1", nw_templ_name="", max_data_field_size="2048") handle.add_mo(mo, True) handle.commit()
def setup_san_connectivity(server, module): from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode from ucsmsdk.mometa.vnic.VnicFc import VnicFc from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf ansible = module.params args_mo = _get_mo_params(ansible) changed = False for san_conn in args_mo['san_conn_list']: exists = False mo = server.query_dn(args_mo['org_dn']+'/san-conn-pol-'+san_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 = VnicSanConnPolicy(parent_mo_or_dn=args_mo['org_dn'], name=san_conn['name']) mo_1 = VnicFcNode(parent_mo_or_dn=mo, ident_pool_name=san_conn['wwnn_pool'], addr='pool-derived') for vhba in san_conn['vhba_list']: mo_2 = VnicFc(parent_mo_or_dn=mo, adaptor_profile_name=vhba['adapter_policy'], order=vhba['order'], name=vhba['name'], nw_templ_name=vhba['vhba_template']) mo_2_1 = VnicFcIf(parent_mo_or_dn=mo_2, name='default') server.add_mo(mo, True) server.commit() return changed
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 main(): argument_spec = ucs_argument_spec argument_spec.update( org_dn=dict(type='str', default='org-root'), name=dict(type='str'), descr=dict(type='str'), wwnn_pool=dict(type='str', default='default'), vhba_list=dict(type='list'), state=dict(type='str', default='present', choices=['present', 'absent']), san_connectivity_list=dict(type='list'), ) # Note that use of san_connectivity_list is an experimental feature which allows multiple resource updates with a single UCSM connection. # Support for san_connectivity_list may change or be removed once persistent UCS connections are supported. # Either san_connectivity_list or name is required (user can specify either a list or single resource). module = AnsibleModule( argument_spec, supports_check_mode=True, required_one_of=[ ['san_connectivity_list', 'name'], ], mutually_exclusive=[ ['san_connectivity_list', 'name'], ], ) ucs = UCSModule(module) err = False from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode from ucsmsdk.mometa.vnic.VnicFc import VnicFc from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf changed = False try: # Only documented use is a single resource, but to also support experimental # feature allowing multiple updates all params are converted to a san_connectivity_list below. if module.params['san_connectivity_list']: # directly use the list (single resource and list are mutually exclusive san_connectivity_list = module.params['san_connectivity_list'] else: # single resource specified, create list from the current params san_connectivity_list = [module.params] for san_connectivity in san_connectivity_list: mo_exists = False props_match = False # set default params. Done here to set values for lists which can't be done in the argument_spec if not san_connectivity.get('descr'): san_connectivity['descr'] = '' if not san_connectivity.get('wwnn_pool'): san_connectivity['wwnn_pool'] = 'default' if san_connectivity.get('vhba_list'): for vhba in san_connectivity['vhba_list']: if not vhba.get('adapter_policy'): vhba['adapter_policy'] = '' if not vhba.get('order'): vhba['order'] = 'unspecified' # dn is <org_dn>/san-conn-pol-<name> dn = module.params['org_dn'] + '/san-conn-pol-' + san_connectivity[ 'name'] mo = ucs.login_handle.query_dn(dn) if mo: mo_exists = True # check top-level mo props kwargs = dict(descr=san_connectivity['descr']) if (mo.check_prop_match(**kwargs)): # top-level props match, check next level mo/props # vnicFcNode object child_dn = dn + '/fc-node' mo_1 = ucs.login_handle.query_dn(child_dn) if mo_1: kwargs = dict( ident_pool_name=san_connectivity['wwnn_pool']) if (mo_1.check_prop_match(**kwargs)): if not san_connectivity.get('vhba_list'): props_match = True else: # check vnicFc props for vhba in san_connectivity['vhba_list']: child_dn = dn + '/fc-' + vhba['name'] mo_2 = ucs.login_handle.query_dn(child_dn) kwargs = {} kwargs['adaptor_profile_name'] = vhba[ 'adapter_policy'] kwargs['order'] = vhba['order'] kwargs['nw_templ_name'] = vhba[ 'vhba_template'] if (mo_2.check_prop_match(**kwargs)): props_match = 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 not props_match: if not module.check_mode: # create if mo does not already exist mo = VnicSanConnPolicy( parent_mo_or_dn=module.params['org_dn'], name=san_connectivity['name'], descr=san_connectivity['descr'], ) mo_1 = VnicFcNode( parent_mo_or_dn=mo, ident_pool_name=san_connectivity['wwnn_pool'], addr='pool-derived', ) if san_connectivity.get('vhba_list'): for vhba in san_connectivity['vhba_list']: mo_2 = VnicFc( parent_mo_or_dn=mo, name=vhba['name'], adaptor_profile_name=vhba[ 'adapter_policy'], nw_templ_name=vhba['vhba_template'], order=vhba['order'], ) mo_2_1 = VnicFcIf( parent_mo_or_dn=mo_2, name='default', ) 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)
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) 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_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") if needfc == "yes": mo_24 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="1", transport="fc", vnic_name="FC_A") mo_25 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="2", transport="fc", vnic_name="FC_B") mo_26 = VnicFc(parent_mo_or_dn=mo, addr="derived", name="FC_A", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", pers_bind_clear="no", switch_id="A", pin_to_group_name="", pers_bind="disabled", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="1", nw_templ_name="FC_A", max_data_field_size="2048") mo_26_1 = VnicFcIf(parent_mo_or_dn=mo_26, name="") mo_27 = VnicFc(parent_mo_or_dn=mo, addr="derived", name="FC_B", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", pers_bind_clear="no", switch_id="A", pin_to_group_name="", pers_bind="disabled", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", order="2", nw_templ_name="FC_B", max_data_field_size="2048") mo_27_1 = VnicFcIf(parent_mo_or_dn=mo_27, name="") mo_28 = VnicFcNode(parent_mo_or_dn=mo, ident_pool_name="UCS_WWNN", addr="pool-derived") handle.add_mo(mo) handle.commit() else : handle.add_mo(mo) handle.commit() print "Completed Successfully" quit() else : if needfc == "yes": mo_24 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="1", transport="fc", vnic_name="FC_A") mo_25 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="2", transport="fc", vnic_name="FC_B")
def main(): argument_spec = ucs_argument_spec argument_spec.update(san_connectivity_list=dict(type='list'), org_dn=dict(type='str', default='org-root'), name=dict(type='str'), descr=dict(type='str'), wwnn_pool=dict(type='str', default='default'), vhba_list=dict(type='list'), state=dict(type='str', default='present', choices=['present', 'absent'])) module = AnsibleModule( argument_spec, supports_check_mode=True, required_one_of=[['san_connectivity_list', 'name']], mutually_exclusive=[['san_connectivity_list', 'name']]) ucs = UCSModule(module) err = False from ucsmsdk.mometa.vnic.VnicSanConnPolicy import VnicSanConnPolicy from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode from ucsmsdk.mometa.vnic.VnicFc import VnicFc from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf changed = False try: if module.params['san_connectivity_list']: # directly use the list (single resource and list are mutually exclusive san_connectivity_list = module.params['san_connectivity_list'] else: # single resource specified, create list from the current params san_connectivity_list = [module.params] for san_connectivity in san_connectivity_list: exists = False # set default params. Done here to set values for lists which can't be done in the argument_spec if not san_connectivity.get('descr'): san_connectivity['descr'] = '' if not san_connectivity.get('wwnn_pool'): san_connectivity['wwnn_pool'] = 'default' for vhba in san_connectivity['vhba_list']: if not vhba.get('adapter_policy'): vhba['adapter_policy'] = '' # dn is <org_dn>/san-conn-pol-<name> dn = module.params['org_dn'] + '/san-conn-pol-' + san_connectivity[ 'name'] mo = ucs.login_handle.query_dn(dn) if mo: # check top-level mo props kwargs = {} kwargs['descr'] = san_connectivity['descr'] if (mo.check_prop_match(**kwargs)): # top-level props match, check next level mo/props # vnicFcNode object child_dn = dn + '/fc-node' mo_1 = ucs.login_handle.query_dn(child_dn) if mo_1: kwargs = {} kwargs['ident_pool_name'] = san_connectivity[ 'wwnn_pool'] if (mo_1.check_prop_match(**kwargs)): if len(san_connectivity['vhba_list']) == 0: exists = True else: # check vnicFc props for vhba in san_connectivity['vhba_list']: child_dn = dn + '/fc-' + vhba['name'] mo_2 = ucs.login_handle.query_dn(child_dn) kwargs = {} kwargs['adaptor_profile_name'] = vhba[ 'adapter_policy'] kwargs['order'] = vhba['order'] kwargs['nw_templ_name'] = vhba[ 'vhba_template'] if (mo_2.check_prop_match(**kwargs)): exists = True if module.params['state'] == 'absent': if exists: if not module.check_mode: ucs.login_handle.remove_mo(mo) ucs.login_handle.commit() changed = True else: if not exists: if not module.check_mode: # create if mo does not already exist mo = VnicSanConnPolicy( parent_mo_or_dn=module.params['org_dn'], name=san_connectivity['name'], descr=san_connectivity['descr']) mo_1 = VnicFcNode( parent_mo_or_dn=mo, ident_pool_name=san_connectivity['wwnn_pool'], addr='pool-derived') for vhba in san_connectivity['vhba_list']: mo_2 = VnicFc( parent_mo_or_dn=mo, name=vhba['name'], adaptor_profile_name=vhba['adapter_policy'], nw_templ_name=vhba['vhba_template'], order=vhba['order']) mo_2_1 = VnicFcIf(parent_mo_or_dn=mo_2, name='default') 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 san_connectivity(input): san_connectivity = input results = {} ucs_handle = pickle.loads( str( ucs_login.main(san_connectivity['ip'], san_connectivity['username'], san_connectivity['password']))) # set default params if not san_connectivity.get('descr'): san_connectivity['descr'] = '' if not san_connectivity.get('wwnn_pool'): san_connectivity['wwnn_pool'] = 'default' if not san_connectivity.get('org_dn'): san_connectivity['org_dn'] = 'org-root' for vhba in san_connectivity['vhba_list']: if not vhba.get('adapter_policy'): vhba['adapter_policy'] = '' changed = False if san_connectivity['state'] == 'present': results['expected'] = True else: results['expected'] = False results['name'] = san_connectivity['name'] try: exists = False # dn is <org_dn>/san-conn-pol-<name> dn = san_connectivity['org_dn'] + '/san-conn-pol-' + san_connectivity[ 'name'] mo = ucs_handle.query_dn(dn) if mo: # check top-level mo props kwargs = {} kwargs['descr'] = san_connectivity['descr'] if (mo.check_prop_match(**kwargs)): # top-level props match, check next level mo/props # vnicFcNode object child_dn = dn + '/fc-node' mo_1 = ucs_handle.query_dn(child_dn) if mo_1: kwargs = {} kwargs['ident_pool_name'] = san_connectivity['wwnn_pool'] if (mo_1.check_prop_match(**kwargs)): if len(san_connectivity['vhba_list']) == 0: exists = True else: # check vnicFc props for vhba in san_connectivity['vhba_list']: child_dn = dn + '/fc-' + vhba['name'] mo_2 = ucs.login_handle.query_dn(child_dn) kwargs = {} kwargs['adaptor_profile_name'] = vhba[ 'adapter_policy'] kwargs['order'] = vhba['order'] kwargs['nw_templ_name'] = vhba['vhba_template'] if (mo_2.check_prop_match(**kwargs)): exists = True if san_connectivity['state'] == 'absent': if exists: if not san_connectivity['check_exists']: ucs_handle.remove_mo(mo) ucs_handle.commit() changed = True results['removed'] = True else: # create/modify for state 'present' results['removed'] = False if not exists: if not san_connectivity['check_exists']: # create if mo does not already exist mo = VnicSanConnPolicy( parent_mo_or_dn=san_connectivity['org_dn'], name=san_connectivity['name'], descr=san_connectivity['descr']) mo_1 = VnicFcNode( parent_mo_or_dn=mo, ident_pool_name=san_connectivity['wwnn_pool'], addr='pool-derived') for vhba in san_connectivity['vhba_list']: mo_2 = VnicFc( parent_mo_or_dn=mo, name=vhba['name'], adaptor_profile_name=vhba['adapter_policy'], nw_templ_name=vhba['vhba_template'], order=vhba['order']) mo_2_1 = VnicFcIf(parent_mo_or_dn=mo_2, name='default') ucs_handle.add_mo(mo, True) ucs_handle.commit() changed = True results['created'] = True except Exception as e: err = True results['msg'] = "setup error: %s " % str(e) results['changed'] = changed results['present'] = exists ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return results