Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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 setup_vhba_template(server, module):
    from ucsmsdk.mometa.vnic.VnicSanConnTempl import VnicSanConnTempl
    from ucsmsdk.mometa.vnic.VnicFcIf import VnicFcIf

    ansible = module.params
    args_mo = _get_mo_params(ansible)

    changed = False

    for vhba in args_mo['vhba_list']:
        exists = False
        mo = server.query_dn(args_mo['org_dn'] + '/san-conn-templ-' +
                             vhba['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 = VnicSanConnTempl(parent_mo_or_dn=args_mo['org_dn'],
                                          ident_pool_name=vhba['wwpn_pool'],
                                          name=vhba['name'],
                                          switch_id=vhba['fabric'])
                    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name=vhba['vsan'])
                    server.add_mo(mo, True)
                    server.commit()

    return changed
Exemplo n.º 4
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 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)
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'),
        fabric=dict(type='str', default='A', choices=['A', 'B']),
        redundancy_type=dict(type='str',
                             default='none',
                             choices=['none', 'primary', 'secondary']),
        vsan=dict(type='str', default='default'),
        template_type=dict(type='str',
                           default='initial-template',
                           choices=['initial-template', 'updating-template']),
        max_data=dict(type='str', default='2048'),
        wwpn_pool=dict(type='str', default='default'),
        qos_policy=dict(type='str'),
        pin_group=dict(type='str'),
        stats_policy=dict(type='str', default='default'),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
        vhba_template_list=dict(type='list'),
    )

    # Note that use of vhba_template_list is an experimental feature which allows multiple resource updates with a single UCSM connection.
    # Support for vhba_template_list may change or be removed once persistent UCS connections are supported.
    # Either vhba_template_list or name is required (user can specify either a list of single resource).

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
        required_one_of=[['vhba_template_list', 'name']],
        mutually_exclusive=[['vhba_template_list', 'name']],
    )
    ucs = UCSModule(module)

    err = False

    from ucsmsdk.mometa.vnic.VnicSanConnTempl import VnicSanConnTempl
    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 vhba_template_list below.

        if module.params['vhba_template_list']:
            # directly use the list (single resource and list are mutually exclusive
            vhba_template_list = module.params['vhba_template_list']
        else:
            # single resource specified, create list from the current params
            vhba_template_list = [module.params]
        for vhba_template in vhba_template_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 vhba_template.get('descr'):
                vhba_template['descr'] = ''
            if not vhba_template.get('fabric'):
                vhba_template['fabric'] = 'A'
            if not vhba_template.get('redundancy_type'):
                vhba_template['redundancy_type'] = 'none'
            if not vhba_template.get('vsan'):
                vhba_template['vsan'] = 'default'
            if not vhba_template.get('template_type'):
                vhba_template['template_type'] = 'initial-template'
            if not vhba_template.get('max_data'):
                vhba_template['max_data'] = '2048'
            if not vhba_template.get('wwpn_pool'):
                vhba_template['wwpn_pool'] = 'default'
            if not vhba_template.get('qos_policy'):
                vhba_template['qos_policy'] = ''
            if not vhba_template.get('pin_group'):
                vhba_template['pin_group'] = ''
            if not vhba_template.get('stats_policy'):
                vhba_template['stats_policy'] = 'default'
            # dn is <org_dn>/san-conn-templ-<name>
            dn = module.params['org_dn'] + '/san-conn-templ-' + vhba_template[
                'name']

            mo = ucs.login_handle.query_dn(dn)
            if mo:
                mo_exists = True
                # check top-level mo props
                kwargs = dict(descr=vhba_template['descr'])
                kwargs['switch_id'] = vhba_template['fabric']
                kwargs['redundancy_pair_type'] = vhba_template[
                    'redundancy_type']
                kwargs['templ_type'] = vhba_template['template_type']
                kwargs['max_data_field_size'] = vhba_template['max_data']
                kwargs['ident_pool_name'] = vhba_template['wwpn_pool']
                kwargs['qos_policy_name'] = vhba_template['qos_policy']
                kwargs['pin_to_group_name'] = vhba_template['pin_group']
                kwargs['stats_policy_name'] = vhba_template['stats_policy']
                if (mo.check_prop_match(**kwargs)):
                    # top-level props match, check next level mo/props
                    child_dn = dn + '/if-default'
                    mo_1 = ucs.login_handle.query_dn(child_dn)
                    if mo_1:
                        kwargs = dict(name=vhba_template['vsan'])
                        if (mo_1.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 = VnicSanConnTempl(
                            parent_mo_or_dn=module.params['org_dn'],
                            name=vhba_template['name'],
                            descr=vhba_template['descr'],
                            switch_id=vhba_template['fabric'],
                            redundancy_pair_type=vhba_template[
                                'redundancy_type'],
                            templ_type=vhba_template['template_type'],
                            max_data_field_size=vhba_template['max_data'],
                            ident_pool_name=vhba_template['wwpn_pool'],
                            qos_policy_name=vhba_template['qos_policy'],
                            pin_to_group_name=vhba_template['pin_group'],
                            stats_policy_name=vhba_template['stats_policy'],
                        )

                        mo_1 = VnicFcIf(
                            parent_mo_or_dn=mo,
                            name=vhba_template['vsan'],
                        )

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

#Create Boot Policy (boot from SD)
mo = LsbootPolicy(parent_mo_or_dn=my_Full_Path_Org, name="Boot_Policy", descr="Boot Policy Desc", reboot_on_update="no", policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy")
mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-write-drive", lun_id="0", mapping_name="", order="2")
mo_2 = LsbootStorage(parent_mo_or_dn=mo, order="1")
mo_2_1 = LsbootLocalStorage(parent_mo_or_dn=mo_2, )
mo_2_1_1 = LsbootUsbFlashStorageImage(parent_mo_or_dn=mo_2_1, order="1")
handle.add_mo(mo)
handle.commit()

#Create HBA Template
if(FC):
    mo = VnicSanConnTempl(parent_mo_or_dn=my_Full_Path_Org, templ_type="updating-template", name="fc-a", descr="", stats_policy_name="default", switch_id="A", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_Pool-A", max_data_field_size="2048")
    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name="default")
    handle.add_mo(mo)
    handle.commit()

    mo = VnicSanConnTempl(parent_mo_or_dn=my_Full_Path_Org, templ_type="updating-template", name="fc-b", descr="", stats_policy_name="default", switch_id="B", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_Pool-B", max_data_field_size="2048")
    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name="default")
    handle.add_mo(mo)
    handle.commit()

#Configuring Uplink ports
#FI-A Port-3
mo = FabricEthLanEp(parent_mo_or_dn="fabric/lan/A", eth_link_profile_name="default", name="", flow_ctrl_policy="default", admin_speed="10gbps", auto_negotiate="yes", usr_lbl="", slot_id="1", admin_state="enabled", port_id="3")
handle.add_mo(mo)
handle.commit()
#FI-A Port-4
mo = FabricEthLanEp(parent_mo_or_dn="fabric/lan/A", eth_link_profile_name="default", name="", flow_ctrl_policy="default", admin_speed="10gbps", auto_negotiate="yes", usr_lbl="", slot_id="1", admin_state="enabled", port_id="4")
Exemplo n.º 8
0
    mo = FcpoolInitiators(parent_mo_or_dn="org-root", name="WWPN_B", policy_owner="local", descr="", assignment_order="sequential", purpose="port-wwn-assignment")
    mo_1 = FcpoolBlock(parent_mo_or_dn=mo, to=wwpn_b_to_var, r_from=wwpn_b_from_var)
    handle.add_mo(mo)

    vsananame = str(raw_input("What is the Fabric A VSAN Name?"))
    vsananumber = str(raw_input("What is the Fabric A VSAN Number?"))
    mo = FabricVsan(parent_mo_or_dn="fabric/san/A", name=vsananame, fcoe_vlan=vsananumber, policy_owner="local", fc_zone_sharing_mode="coalesce", zoning_state="disabled", id=vsananumber)
    handle.add_mo(mo)
    vsanbname = str(raw_input("What is the Fabric B VSAN Name?"))
    vsanbnumber = str(raw_input("What is the Fabric B VSAN Number?"))
    mo = FabricVsan(parent_mo_or_dn="fabric/san/B", name=vsanbname, fcoe_vlan=vsanbnumber, policy_owner="local", fc_zone_sharing_mode="coalesce", zoning_state="disabled", id=vsanbnumber)
    handle.add_mo(mo)

#CREATE VHBA TEMPLATE
    mo = VnicSanConnTempl(parent_mo_or_dn="org-root", templ_type="updating-template", name="FC_A", descr="", stats_policy_name="default", switch_id="A", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_A", max_data_field_size="2048")
    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name=vsananame)
    handle.add_mo(mo)

    mo = VnicSanConnTempl(parent_mo_or_dn="org-root", templ_type="updating-template", name="FC_B", descr="", stats_policy_name="default", switch_id="B", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_B", max_data_field_size="2048")
    mo_1 = VnicFcIf(parent_mo_or_dn=mo, name=vsanbname)
    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")
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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
Exemplo n.º 11
0
def vhba_template(input):
    vhba_template = input
    results = {}
    ucs_handle = pickle.loads(
        str(
            ucs_login.main(vhba_template['ip'], vhba_template['username'],
                           vhba_template['password'])))

    # set default params
    if not vhba_template.get('descr'):
        vhba_template['descr'] = ''
    if not vhba_template.get('fabric'):
        vhba_template['fabric'] = 'A'
    if not vhba_template.get('redundancy_type'):
        vhba_template['redundancy_type'] = 'none'
    if not vhba_template.get('vsan'):
        vhba_template['vsan'] = 'default'
    if not vhba_template.get('template_type'):
        vhba_template['template_type'] = 'initial-template'
    if not vhba_template.get('max_data'):
        vhba_template['max_data'] = '2048'
    if not vhba_template.get('wwpn_pool'):
        vhba_template['wwpn_pool'] = 'default'
    if not vhba_template.get('qos_policy'):
        vhba_template['qos_policy'] = ''
    if not vhba_template.get('pin_group'):
        vhba_template['pin_group'] = ''
    if not vhba_template.get('stats_policy'):
        vhba_template['stats_policy'] = 'default'
    if not vhba_template.get('org_dn'):
        vhba_template['org_dn'] = 'org-root'

    changed = False
    if vhba_template['state'] == 'present':
        results['expected'] = True
    else:
        results['expected'] = False
    results['name'] = vhba_template['name']
    try:
        exists = False
        # dn is <org_dn>/san-conn-templ-<name>
        dn = vhba_template['org_dn'] + '/san-conn-templ-' + vhba_template[
            'name']

        mo = ucs_handle.query_dn(dn)
        if mo:
            # check top-level mo props
            kwargs = {}
            kwargs['descr'] = vhba_template['descr']
            kwargs['switch_id'] = vhba_template['fabric']
            kwargs['redundancy_pair_type'] = vhba_template['redundancy_type']
            kwargs['templ_type'] = vhba_template['template_type']
            kwargs['max_data_field_size'] = vhba_template['max_data']
            kwargs['ident_pool_name'] = vhba_template['wwpn_pool']
            kwargs['qos_policy_name'] = vhba_template['qos_policy']
            kwargs['pin_to_group_name'] = vhba_template['pin_group']
            kwargs['stats_policy_name'] = vhba_template['stats_policy']
            if (mo.check_prop_match(**kwargs)):
                # top-level props match, check next level mo/props
                child_dn = dn + '/if-default'
                mo_1 = ucs_handle.query_dn(child_dn)
                if mo_1:
                    kwargs = {}
                    kwargs['name'] = vhba_template['vsan']
                    if (mo_1.check_prop_match(**kwargs)):
                        exists = True

        if vhba_template['state'] == 'absent':
            if exists:
                if not vhba_template['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 vhba_template['check_exists']:
                    # create if mo does not already exist
                    mo = VnicSanConnTempl(
                        parent_mo_or_dn=vhba_template['org_dn'],
                        name=vhba_template['name'],
                        descr=vhba_template['descr'],
                        switch_id=vhba_template['fabric'],
                        redundancy_pair_type=vhba_template['redundancy_type'],
                        templ_type=vhba_template['template_type'],
                        max_data_field_size=vhba_template['max_data'],
                        ident_pool_name=vhba_template['wwpn_pool'],
                        qos_policy_name=vhba_template['qos_policy'],
                        pin_to_group_name=vhba_template['pin_group'],
                        stats_policy_name=vhba_template['stats_policy'])

                    mo_1 = VnicFcIf(parent_mo_or_dn=mo,
                                    name=vhba_template['vsan'])

                    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