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") 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="")
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 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()
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
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)