コード例 #1
0
def sp_power_off(ucs_handle, sp_name, parent_dn="org-root"):
    """
    This function will power off a service profile

    Args:
        ucs_handle (ucs_handle)

        sp_name (string): Service Profile  name.
        parent_dn (string): Org.

    Returns:
        None

    Raises:
        ValueError: If LsServer is not present

    Example:
        sp_power_off(ucs_handle, sp_name="sample_sp", parent_dn="org-root")
        sp_power_off(ucs_handle, sp_name="sample_sp", parent_dn="org-root/sub-org")
    """

    from ucsmsdk.mometa.ls.LsPower import LsPowerConsts
    from ucsmsdk.mometa.ls.LsPower import LsPower

    dn = parent_dn + "/ls-" + sp_name
    mo = ucs_handle.query_dn(dn)
    if not mo:
        raise ValueError("sp '%s' does not exist" % dn)

    LsPower(parent_mo_or_dn=mo, state=LsPowerConsts.STATE_DOWN)
    ucs_handle.set_mo(mo)
    ucs_handle.commit()
コード例 #2
0
ファイル: power.py プロジェクト: yaroslav525/ucsm_apis
def _service_profile_power_set(handle,
                               chassis_id=None,
                               blade_id=None,
                               rack_id=None,
                               state=None):

    dn = _server_dn_get(chassis_id=chassis_id,
                        blade_id=blade_id,
                        rack_id=rack_id)
    blade_mo = handle.query_dn(dn)
    if blade_mo is None:
        raise UcsOperationError(
            "_service_profile_power_set: Failed to set server power",
            "server %s does not exist" % (dn))

    if not blade_mo.assigned_to_dn:
        raise UcsOperationError(
            "_service_profile_power_set: Failed to set server power",
            "server %s is not associated to a service profile" % (dn))

    if blade_mo.association != "associated":
        raise UcsOperationError(
            "_service_profile_power_set: Failed to set server power",
            "server %s is still in process of associating a service profile\
            OR there might be faults.Please wait or check.Current association\
            state is %s" % (dn, blade_mo.association))

    sp_mo = handle.query_dn(blade_mo.assigned_to_dn)
    LsPower(parent_mo_or_dn=sp_mo, state=state)
    handle.set_mo(sp_mo)
    handle.commit()
コード例 #3
0
ファイル: ucs_server.py プロジェクト: madpabz/KUBaM
    def power_server(handle, server, action):
        """
        Takes in a service profile and applies the appropriate power
        action to the service profile. The service profile should be
        the full organization of the server. e.g:
        "org-root/ls-miner04"
        """
        st = ""
        if action == "off":
            st = "admin-down"
        elif action == "on":
            st = "admin-up"
        elif action == "hardreset":
            st = "cycle-immediate"
        elif action == "softreset":
            st = "cycle-wait"
        else:
            raise KubamError("Power method {0} is not a valid power action.".format(action))


        if action in ["on", "off"] and server["service_profile"] == "":
            raise KubamError("Can not power {0}, no service profile associated with {1}".format(action, server["dn"]))

        from ucsmsdk.mometa.ls.LsPower import LsPower
        mo = LsPower(parent_mo_or_dn=server["service_profile"],
                     state=st)
        handle.add_mo(mo, True)
        try:
            handle.commit()
        except UcsException as err:
            raise KubamError("{0}".format(err))
コード例 #4
0
def server_power_get(handle,
                     chassis_id=None,
                     blade_id=None,
                     rack_id=None,
                     state=None,
                     oper_power=None):
    dn = _server_dn_get(chassis_id=chassis_id,
                        blade_id=blade_id,
                        rack_id=rack_id)
    blade_mo = handle.query_dn(dn)
    if blade_mo is None:
        UcsOperationError("server_power_get: Failed to get server power",
                          "sever %s does not exist" % (dn))

    sp_mo = handle.query_dn(blade_mo.oper_power)
    LsPower(parent_mo_or_dn=sp_mo, state=oper_power)
コード例 #5
0
def _powerStatus(dn, handle):
    blade_mo = handle.query_dn(dn)
    if blade_mo is None:
        raise UcsException(
            "service_profile_power_set: Failed to set element power",
            "sever %s does not exist" % (dn))
    elif blade_mo._class_id == "LsServer":
        sp_mo = blade_mo
    elif blade_mo.assigned_to_dn is None or blade_mo.assigned_to_dn == "":
        raise UcsException(
            "service_profile_power_set: Failed to set element power",
            "sever %s is not associated to a service profile" % (dn))
    else:
        sp_mo = handle.query_dn(blade_mo.assigned_to_dn)
    powerLs = LsPower(sp_mo)
    handle.set_mo(sp_mo)
    handle.commit()
    data = powerLs.state
    return data
コード例 #6
0
def _service_profile_power_set(handle, dn=None, state=None):
    blade_mo = handle.query_dn(dn)
    if blade_mo is None:
        raise UcsException(
            "service_profile_power_set: Failed to set element power",
            "sever %s does not exist" % (dn))
    elif blade_mo._class_id == "LsServer":
        sp_mo = blade_mo
    elif blade_mo.assigned_to_dn is None or blade_mo.assigned_to_dn == "":
        raise UcsException(
            "service_profile_power_set: Failed to set element power",
            "sever %s is not associated to a service profile" % (dn))
    else:
        sp_mo = handle.query_dn(blade_mo.assigned_to_dn)
    if state == "off":
        state = LsPowerConsts.STATE_DOWN
    elif state == "on":
        state = LsPowerConsts.STATE_UP
    elif state == "cycle-immediate":
        state = LsPowerConsts.STATE_CYCLE_IMMEDIATE
    elif state == "cycle-wait":
        state = LsPowerConsts.STATE_CYCLE_WAIT
    elif state == "bmc-reset-immediate":
        state = LsPowerConsts.STATE_BMC_RESET_IMMEDIATE
    elif state == "ipmi-reset":
        state = LsPowerConsts.STATE_IPMI_RESET
    elif state == "hard-reset-immediate":
        state = LsPowerConsts.STATE_HARD_RESET_IMMEDIATE
    elif state == "soft-shut-down":
        state = LsPowerConsts.STATE_SOFT_SHUT_DOWN
    else:
        raise UcsException(
            "server_power_set: Failed to set server power",
            "action '{0}' is not valid. Choose one of the following: "
            "'on', 'off', 'cycle-wait','cycle-immediate', 'bmc-reset-immediate',"
            " 'ipmi-reset', 'hard-reset-immediate', 'soft-shut-down' ".format(state))
    data = LsPower(
        parent_mo_or_dn=sp_mo,
        state=state)
    handle.set_mo(sp_mo)
    handle.commit()
    return data
コード例 #7
0
def _service_profile_power_set(handle,
                               chassis_id=None,
                               blade_id=None,
                               rack_id=None,
                               state=None):
    dn = _server_dn_get(chassis_id=chassis_id,
                        blade_id=blade_id,
                        rack_id=rack_id)
    blade_mo = handle.query_dn(dn)
    if blade_mo is None:
        raise UcsOperationError("server_power_set: Failed to set server power",
                                "server %s does not exist" % (dn))

    if blade_mo.assigned_to_dn is None:
        raise UcsOperationError(
            "server_power_set: Failed to set server power",
            "server %s is not associated to a service profile" % (dn))

    sp_mo = handle.query_dn(blade_mo.assigned_to_dn)
    LsPower(parent_mo_or_dn=sp_mo, state=state)
    handle.set_mo(sp_mo)
    handle.commit()
コード例 #8
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()
コード例 #9
0
def configure_service_profile_template(ucs, module):
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.vnic.VnicConnDef import VnicConnDef
    from ucsmsdk.mometa.vnic.VnicIScsiNode import VnicIScsiNode
    from ucsmsdk.mometa.ls.LsRequirement import LsRequirement
    from ucsmsdk.mometa.ls.LsPower import LsPower
    from ucsmsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding
    from ucsmsdk.mometa.mgmt.MgmtInterface import MgmtInterface
    from ucsmsdk.mometa.mgmt.MgmtVnet import MgmtVnet
    from ucsmsdk.mometa.vnic.VnicIpV4MgmtPooledAddr import VnicIpV4MgmtPooledAddr

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

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

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

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

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

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

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

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

    ucs.result['changed'] = True
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(
        org_dn=dict(type='str', default='org-root'),
        name=dict(type='str', required=True),
        source_template=dict(type='str', required=True),
        user_label=dict(type='str', default=''),
        power_state=dict(type='str', choices=['up', 'down']),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
    )

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

    err = False

    # UCSModule creation above verifies ucsmsdk is present and exits on failure.  Additional imports are done below.
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.ls.LsPower import LsPower

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

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

        if module.params['state'] == 'absent':
            # mo must exist but all properties do not have to match
            if mo_exists:
                if not module.check_mode:
                    ucs.login_handle.remove_mo(mo)
                    ucs.login_handle.commit()
                changed = True
        else:
            if mo_exists:
                # check top-level mo props
                kwargs = dict(src_templ_name=module.params['source_template'])
                kwargs['usr_lbl'] = module.params['user_label']
                # service profiles are of type 'instance'
                kwargs['type'] = 'instance'

                if mo.check_prop_match(**kwargs):
                    # top-level props match
                    if module.params.get('power_state'):
                        child_dn = dn + '/power'
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            kwargs = dict(state=module.params['power_state'])
                            if mo_1.check_prop_match(**kwargs):
                                props_match = True
                    else:
                        # no power state provided, use existing state as match
                        props_match = True

            if not props_match:
                if not module.check_mode:
                    # create if mo does not already exist
                    mo = LsServer(
                        parent_mo_or_dn=module.params['org_dn'],
                        name=module.params['name'],
                        src_templ_name=module.params['source_template'],
                        type='instance',
                        usr_lbl=module.params['user_label'],
                    )
                    if module.params.get('power_state'):
                        admin_state = 'admin-' + module.params['power_state']
                        mo_1 = LsPower(
                            parent_mo_or_dn=mo,
                            state=admin_state,
                        )

                    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)
コード例 #11
0
ファイル: hx_reset.py プロジェクト: michzimm/hx_reset
def sp_power_action(ucs_handle, sp_dn, action):
    mo = LsPower(parent_mo_or_dn=sp_dn, state=action)
    ucs_handle.add_mo(mo, True)
    ucs_handle.commit()
コード例 #12
0
    mo_2 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="2", transport="ethernet", vnic_name="MGMT-B")
    mo_3 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="3", transport="ethernet", vnic_name="VM-A")
    mo_4 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="4", transport="ethernet", vnic_name="VM-B")
    mo_5 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="5", transport="fc", vnic_name="fc-a")
    mo_6 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", admin_host_port="ANY", order="6", transport="fc", vnic_name="fc-b")
    mo_7 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", name="MGMT-A", order="1", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="MGMT-A", addr="derived")
    mo_8 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", name="MGMT-B", order="2", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="MGMT-B", addr="derived")
    mo_9 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", name="VM-A", order="3", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="VM-A", addr="derived")
    mo_10 = VnicEther(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", nw_ctrl_policy_name="", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", name="VM-B", order="4", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", mtu="1500", nw_templ_name="VM-B", addr="derived")
    mo_11 = VnicFc(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", addr="derived", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", pers_bind="disabled", order="5", pers_bind_clear="no", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", max_data_field_size="2048", nw_templ_name="fc-a", name="fc-a")
    mo_11_1 = VnicFcIf(parent_mo_or_dn=mo_11, name="")
    mo_12 = VnicFc(parent_mo_or_dn=mo, cdn_prop_in_sync="yes", addr="derived", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", pers_bind="disabled", order="6", pers_bind_clear="no", qos_policy_name="", adaptor_profile_name="VMWare", ident_pool_name="", cdn_source="vnic-name", max_data_field_size="2048", nw_templ_name="fc-b", name="fc-b")
    mo_12_1 = VnicFcIf(parent_mo_or_dn=mo_12, name="")
    mo_13 = VnicFcNode(parent_mo_or_dn=mo, ident_pool_name="WWNN_Pool", addr="pool-derived")
    mo_14 = LsRequirement(parent_mo_or_dn=mo, restrict_migration="no", name="Server_Pool", qualifier="")
    mo_15 = LsPower(parent_mo_or_dn=mo, state="admin-up")
    mo_16 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="1", inst_type="auto")
    mo_17 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="2", inst_type="auto")
    mo_18 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="3", inst_type="auto")
    mo_19 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="4", inst_type="auto")
    handle.add_mo(mo)
    handle.commit()

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

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

    err = False

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

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

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

        if module.params['state'] == 'absent':
            # mo must exist but all properties do not have to match
            if mo_exists:
                if not module.check_mode:
                    ucs.login_handle.remove_mo(mo)
                    ucs.login_handle.commit()
                changed = True
        else:
            if mo_exists:
                # check top-level mo props
                kwargs = dict(bios_profile_name=module.params['bios_policy'])
                kwargs['boot_policy_name'] = module.params['boot_policy']
                kwargs['descr'] = module.params['description']
                kwargs['ext_ip_pool_name'] = module.params['mgmt_ip_pool']
                # kwargs['graphics_card_policy_name'] = module.params['graphics_card_policy']
                kwargs['host_fw_policy_name'] = module.params[
                    'host_firmware_package']
                kwargs['ident_pool_name'] = module.params['uuid_pool']
                kwargs['kvm_mgmt_policy_name'] = module.params[
                    'kvm_mgmt_policy']
                kwargs['local_disk_policy_name'] = module.params[
                    'local_disk_policy']
                kwargs['maint_policy_name'] = module.params[
                    'maintenance_policy']
                kwargs['mgmt_access_policy_name'] = module.params[
                    'ipmi_access_profile']
                kwargs['power_policy_name'] = module.params[
                    'power_control_policy']
                kwargs['power_sync_policy_name'] = module.params[
                    'power_sync_policy']
                kwargs['scrub_policy_name'] = module.params['scrub_policy']
                kwargs['sol_policy_name'] = module.params['sol_policy']
                kwargs['stats_policy_name'] = module.params['threshold_policy']
                kwargs['type'] = module.params['template_type']
                kwargs['usr_lbl'] = module.params['user_label']
                kwargs['vmedia_policy_name'] = module.params['vmedia_policy']

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

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

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

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

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

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

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

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

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

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

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

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

                    ucs.login_handle.add_mo(mo, True)
                    ucs.login_handle.commit()
                changed = True

    except Exception as e:
        err = True
        ucs.result['msg'] = "setup error: %s " % str(e)

    ucs.result['changed'] = changed
    if err:
        module.fail_json(**ucs.result)
    module.exit_json(**ucs.result)
コード例 #14
0
fault_server = []

while reboot_count < num_of_reboot:
    handle.logout()
    handle.login()
    print("=======================================")
    print("PERFORMING REBOOT %s" % (reboot_count+1))
    print("=======================================\n")
    print(time.ctime())
    if not servers_to_reboot:
        print("There are no servers to reboot, re-run the test with servers to reboot")
        handle.logout()
        exit()
    for server in servers_to_reboot:
        print("REBOOTING SERVER %s WITH SP %s" % (server.dn, server.assigned_to_dn))
        mo = LsPower(parent_mo_or_dn=server.assigned_to_dn, state="hard-reset-immediate")
        handle.set_mo(mo)
        handle.commit()

    time.sleep(240)
    print("\nCHECKING FAULTS AFTER REBOOT...")
    faults = check_fault(handle, servers_to_reboot)
    if faults:
        print("Faults observers, waiting to see if UCSM clears...")
        time.sleep(90)
        faults = check_fault(handle, servers_to_reboot)
        if faults:
            print("THE FOLLOWING FAULTS ARE OBSERVED")
            for fault in faults:
                print(fault.descr)
                print("FAILURE REPORTED AFTER %s REBOOTS, CHECK SYSTEM FOR FAULTS", (reboot_count+1))
コード例 #15
0
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(service_profile_name=dict(type='str', required=True),
                         power_state=dict(type='str',
                                          required=True,
                                          choices=['up', 'down']),
                         force=dict(type='bool'),
                         delegate_to=dict(type='str', default='localhost'))

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=False,
        mutually_exclusive=[],
    )

    # UCSModule verifies ucsmsdk is present and exits on failure.
    # Imports are below for UCS object creation.
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.ls.LsPower import LsPower

    ucs = UCSModule(module)
    err = False
    query_result = []

    ucs.result['changed'] = False

    try:
        filter_string = '(name, "{:s}", type="eq")'.format(
            module.params['service_profile_name'])

        service_profiles = ucs.login_handle.query_classid(
            class_id="lsServer", filter_str=filter_string)

        if len(service_profiles) == 0:
            raise Exception('Service profile {:s} does not exist'.format(
                module.params['service_profile_name']))
        elif len(service_profiles) > 1:
            raise Exception('Service profile name {:s} is not unique'.format(
                module.params['service_profile_name']))

        service_profile = service_profiles[0]

        children = ucs.login_handle.query_children(in_mo=service_profile,
                                                   class_id="lsPower")

        power = children[0]

        if power.state == module.params[
                'power_state'] and not module.params['force']:
            ucs.result['changed'] = False
            module.exit_json(**ucs.result)

        if module.params['power_state'] == 'up':
            new_power = LsPower(parent_mo_or_dn=service_profile,
                                state="admin-up")
        else:
            new_power = LsPower(parent_mo_or_dn=service_profile,
                                state="soft-shut-down")

        ucs.login_handle.add_mo(new_power, True)

        ucs.login_handle.commit()
        ucs.result['changed'] = True

    except Exception as e:
        err = True
        ucs.result['msg'] = "setup error: %s " % str(e)

    if err:
        module.fail_json(**ucs.result)

    module.exit_json(**ucs.result)