Пример #1
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(
            "_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()
Пример #2
0
def _iscsi_device_add(parent_mo, order, vnic_name):
    from ucsmsdk.mometa.lsboot.LsbootIScsi import LsbootIScsi
    from ucsmsdk.mometa.lsboot.LsbootIScsiImagePath import LsbootIScsiImagePath

    mo = [mo for mo in parent_mo.child if mo.get_class_id() == "LsbootIScsi"]

    if mo and mo[0].child:
        child_count = len(mo[0].child)
        if child_count >= 2:
            raise UcsOperationError(
                "_iscsi_device_add", "Both instances of ISCSI Device are "
                "already added.")

        if not vnic_name:
            raise UcsOperationError("_iscsi_device_add",
                                    "Required parameter 'vnic_name' missing.")
        LsbootIScsiImagePath(parent_mo_or_dn=mo[0],
                             i_scsi_vnic_name=vnic_name,
                             type="secondary")
        return

    if not vnic_name:
        raise UcsOperationError("_iscsi_device_add",
                                "Required parameter 'vnic_name' missing.")

    mo_ = LsbootIScsi(parent_mo_or_dn=parent_mo, order=order)
    LsbootIScsiImagePath(parent_mo_or_dn=mo_,
                         i_scsi_vnic_name=vnic_name,
                         type="primary")
Пример #3
0
def _lan_device_add(parent_mo, order, vnic_name):
    from ucsmsdk.mometa.lsboot.LsbootLan import LsbootLan
    from ucsmsdk.mometa.lsboot.LsbootLanImagePath import LsbootLanImagePath

    mo = [mo for mo in parent_mo.child if mo.get_class_id() == "LsbootLan"]

    if mo and mo[0].child:
        child_count = len(mo[0].child)
        if child_count >= 2:
            raise UcsOperationError(
                "_lan_device_add", "Both instances of Lan Device are "
                "already added.")

        if not vnic_name:
            raise UcsOperationError("_local_device_add",
                                    "Required parameter 'vnic_name' missing.")

        LsbootLanImagePath(parent_mo_or_dn=mo[0],
                           vnic_name=vnic_name,
                           type="secondary")
        return

    if not vnic_name:
        raise UcsOperationError("Required Parameter 'vnic_name' missing.")

    mo_ = LsbootLan(parent_mo_or_dn=parent_mo, order=order, prot="pxe")
    LsbootLanImagePath(parent_mo_or_dn=mo_,
                       vnic_name=vnic_name,
                       type="primary")
Пример #4
0
def _compare_boot_policy(existing_boot_policy, expected_boot_policy):
    # check child count
    existing_bp_child = existing_boot_policy.child
    expected_bp_child = expected_boot_policy.child
    if len(existing_bp_child) != len(expected_bp_child):
        raise UcsOperationError("_compare_boot_policy",
                                "Child count mismatch.")

    existing_bp_devices = extract_device_from_bp_child(existing_bp_child)
    expected_bp_devices = extract_device_from_bp_child(expected_bp_child)

    for device_name in existing_bp_devices:
        if device_name not in expected_bp_devices:
            raise UcsOperationError("_compare_boot_policy",
                                    "Device does not already exist.")

        existing_bp_device = existing_bp_devices[device_name]
        expected_bp_device = expected_bp_devices[device_name]

        if device_name in _vmedia_devices:
            if not existing_bp_device.check_prop_match(
                    order=expected_bp_device.order):
                raise UcsOperationError(
                    "_compare_boot_policy",
                    "Order mismatch for device '%s'." %
                    device_name)
        elif device_name in _local_devices:
            if _local_devices[device_name][1] is None:
                if not existing_bp_device.check_prop_match(
                        order=expected_bp_device.order):
                    raise UcsOperationError(
                        "_compare_boot_policy",
                        "Order mismatch for device '%s'." %
                        device_name)
            elif device_name == "local_lun":
                _compare_local_lun(existing_bp_device,
                                   expected_bp_device)
            elif device_name == "local_jbod":
                _compare_local_jbod(existing_bp_device,
                                    expected_bp_device)
            elif device_name == "embedded_disk":
                _compare_embedded_disk(existing_bp_device,
                                       expected_bp_device)
        elif device_name == "lan":
            _compare_lan(existing_bp_device,
                         expected_bp_device)
        elif device_name == "san":
            _compare_san(existing_bp_device,
                         expected_bp_device)
        elif device_name == "iscsi":
            _compare_iscsi(existing_bp_device,
                           expected_bp_device)
Пример #5
0
def _local_embedded_disk_add(parent_mo, order, slot_number=None, type=None):
    from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalDiskImage import \
        LsbootEmbeddedLocalDiskImage
    from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalDiskImagePath import \
        LsbootEmbeddedLocalDiskImagePath

    mo = [
        mo for mo in parent_mo.child
        if mo.get_class_id() == "LsbootEmbeddedLocalDiskImage"
    ]
    if mo and not mo[0].child:
        raise UcsOperationError(
            "_local_embedded_disk_add",
            "Instance of Local Embedded Disk already "
            "added at order '%s'" % mo[0].order)
    if mo and mo[0].child:
        child_count = len(mo[0].child)
        if child_count >= 2:
            raise UcsOperationError(
                "_local_embedded_disk_add",
                "Both instance of Local Embedded Disk "
                "already added.")
        if mo[0].child[0].type == type:
            raise UcsOperationError(
                "_local_embedded_disk_add",
                "Instance of Local Embedded Disk  of "
                "type '%s' already added at  order '%s'." %
                (type, mo[0].order))

        if not slot_number or not type:
            raise UcsOperationError(
                "_local_embedded_disk_add",
                "Required parameter 'slot_number' or "
                "'type' missing.")

        LsbootEmbeddedLocalDiskImagePath(parent_mo_or_dn=mo[0],
                                         slot_number=slot_number,
                                         type=type)
        return

    mo = LsbootEmbeddedLocalDiskImage(parent_mo_or_dn=parent_mo, order=order)
    if not slot_number and not type:
        return
    if (slot_number and not type) or (not slot_number and type):
        raise UcsOperationError(
            "_local_embedded_disk_add",
            "Required parameter 'slot_number' or 'type'"
            " missing.")
    LsbootEmbeddedLocalDiskImagePath(parent_mo_or_dn=mo,
                                     slot_number=slot_number,
                                     type=type)
Пример #6
0
def boot_policy_get(handle, name, org_dn="org-root", caller="boot_policy_get"):
    """
    This method fetches boot policy.

    Args:
        handle (UcsHandle)
        name (string): Name of the boot policy.
        org_dn (string): Org DN.
        caller (string): Name of the caller method.

    Returns:
        LsbootPolicy: Managed Object

    Raises:
        UcsOperationError

    Example:
_       boot_policy_get(handle,
                        name="sample_boot",
                        org_dn="org-root/org-finance",
                        caller="boot_policy_modify")
    """

    dn = org_dn + "/boot-policy-" + name
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(caller, "BootPolicy '%s' does not exist" % dn)
    return mo
Пример #7
0
def radius_provider_group_get(handle,
                              name,
                              caller="radius_provider_group_get"):
    """
    gets radius provider group

    Args:
        handle (UcsHandle)
        name (string): radius provider group name

    Returns:
        AaaProviderGroup: managed object

    Raises:
        UcsOperationError: if AaaProviderGroup is not present

    Example:
        radius_provider_group_get(handle, name="test_prov_grp")
    """
    dn = _radius_dn + "/providergroup-" + name
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(
            caller, "Radius Provider Group'%s' does not exist" % dn)
    return mo
Пример #8
0
def callhome_anonymous_reporting_off(handle, user_acknowledged="yes"):
    """
    Sets anonymous reporting 'off'

    Args:
        handle (UcsHandle)
        user_acknowledged (string): valid values are "yes", "no"

    Returns:
        CallhomeAnonymousReporting : ManagedObject

    Raises:
        UcsOperationError: If CallhomeAnonymousReporting is not present

    Example:
        callhome_anonymous_reporting_off(handle)
    """
    dn = _base_dn + "anonymousreporting"
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError("callhome_anonymous_reporting_off",
                    "Callhome Anonymous Reporting '%s' does not exist." % dn)

    args = {'admin_state': "off",
            'user_acknowledged': user_acknowledged
            }

    mo.set_prop_multiple(**kwargs)
    handle.set_mo(mo)
    handle.commit()
    return mo
Пример #9
0
def callhome_system_inventory_send_now(handle):
    """
    Sends callhome system inventory now.

    Args:
        handle (UcsHandle)

    Returns:
        CallhomePeriodicSystemInventory : ManagedObject

    Raises:
        UcsOperationError: If CallhomePeriodicSystemInventory is not present

    Example:
        callhome_system_inventory_send_now(handle)
    """
    dn = _base_dn + "periodicsysteminventory"
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError("callhome_system_inventory_configure",
                        "Callhome system inventory '%s' does not exist." % dn)

    args = {'send_now': "yes"}

    mo.set_prop_multiple(**kwargs)
    handle.set_mo(mo)
    handle.commit()
    return mo
Пример #10
0
def callhome_profile_email_get(handle, profile_name, email,
                                caller="callhome_profile_email_get"):
    """
    Gets receipient email from callhome profile.

    Args:
        handle (UcsHandle)
        profile_name (string): name of callhome profile
        email (string): receipient email address
        caller (string): name of caller function

    Returns:
        CallhomeDest : ManagedObject

    Raises:
        UcsOperationError: If CallhomeDest is not present

    Example:
        callhome_profile_email_get(handle, profile_name="callhomeprofile",
                                    email="*****@*****.**")
    """
    profile_dn = _base_dn + "/profile-" + profile_name
    dn = profile_dn + "/email-" + email
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(caller,
                            "Callhome Profile Email '%s' does not exist" % dn)
    return mo
Пример #11
0
def locale_org_unassign(handle, locale_name, name):
    """
    unassigns a locale from org

    Args:
        handle (UcsHandle)
        locale_name(string): locale name
        name (string): name of org assignment

    Returns:
        None

    Raises:
        UcsOperationError: If AaaOrg is not present

    Example:
        locale_org_unassign(handle, locale_name="test_locale,
                            name="org_name")
    """
    locale_dn = _base_dn + "/locale-" + locale_name
    dn = locale_dn + "/org-" + name
    mo = handle.query_dn(dn)
    if not mo:
        raise UcsOperationError("locale_org_unassign",
                                "org '%s' not assigned to locale" % dn)

    handle.remove_mo(mo)
    handle.commit()
Пример #12
0
def callhome_anonymous_reporting_off(handle):
    """
    Sets anonymous reporting 'off'

    Args:
        handle (UcsHandle)

    Returns:
        CallhomeAnonymousReporting : ManagedObject

    Raises:
        UcsOperationError: If CallhomeAnonymousReporting is not present

    Example:
        callhome_anonymous_reporting_off(handle)
    """
    dn = _base_dn + "/anonymousreporting"
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(
            "callhome_anonymous_reporting_off",
            "Callhome Anonymous Reporting '%s' does not exist." % dn)

    args = {
        'admin_state': "off",
    }

    mo.set_prop_multiple(**args)
    handle.set_mo(mo)
    handle.commit()
    return mo
Пример #13
0
def trusted_point_get(handle, name, caller="trusted_point_get"):
    """
    Gets trusted point

    Args:
        handle (ucshandle)
        name (string): trusted point name
        caller (string): name of the caller function

    Returns:
        PkiTP: managed object

    Raises:
        UcsOperationError: if PkiTP is not present

    Example:
        key_ring = trusted_point_get(handle, name="mytrustedpoint")
    """

    dn = _tp_base_dn + "/tp-" + name
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(caller,
                                "Trusted Point '%s' does not exist" % dn)
    return mo
Пример #14
0
def ldap_provider_group_provider_get(handle,
                                     group_name,
                                     name,
                                     caller="ldap_provider_group_provider_get"
                                     ):
    """
    Gets provider for ldap provider group

    Args:
        handle (UcsHandle)
        group_name (string): ldap provider group name
        name (string): ldap provider name
        caller (string): name of the caller function

    Returns:
        AaaProviderRef : managed object

    Raises:
        UcsOperationError: if AaaProviderRef is not present

    Example:
        ldap_provider_group_provider_get(handle,
                                         group_name="test_ldap_provider_group",
                                         name="test_provider")
    """
    provider_group_dn = _ldap_dn + "providergroup-" + group_name
    provider_ref_dn = provider_group_dn + "/provider-ref-" + name
    mo = handle.query_dn(provider_ref_dn)
    if mo is None:
        raise UcsOperationError(
            caller,
            "Ldap Provider Reference '%s' does not exist" % provider_ref_dn)
    return mo
Пример #15
0
def ldap_group_locale_get(handle,
                          ldap_group_name,
                          name,
                          caller="ldap_group_locale_get"):
    """
    Gets the locale for the respective ldap group map

    Args:
        handle (UcsHandle)
        ldap_group_name (string): name of ldap group
        name (string):  locale name
        caller (string): name of the caller function

    Returns:
        AaaUserLocale : managed object

    Raises:
        UcsOperationError: if AaaUserLocale is not present

    Example:
        ldap_group_locale_get(handle,
                              ldap_group_name="test_ldap_grp_map",
                              name="locale1")
    """
    dn = _ldap_dn + "/ldapgroup-" + ldap_group_name + "/locale-" + name
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(
            caller, "Ldap Group Map Locale '%s' does not exist" % dn)
    return mo
Пример #16
0
def _compare_iscsi(existing_iscsi, expected_iscsi):
    _device_compare(existing_iscsi, 'iscsi', order=expected_iscsi.order)

    existing_child = existing_iscsi.child
    expected_child = expected_iscsi.child
    if len(existing_child) != len(expected_child):
        raise UcsOperationError("_compare_boot_policy",
                                "Child count mismatch for 'iscsi'.")
    if len(existing_child) == 0:
        return
    if len(existing_child) == 1:
        _device_compare(existing_child[0],
                        'iscsi',
                        type=expected_iscsi.type,
                        i_scsi_vnic_name=expected_iscsi.i_scsi_vnic_name)
    if len(existing_child) == 2:
        existing_child_primary, existing_child_secondary =\
            _child_pri_sec_filter(existing_child)

        expected_child_primary, expected_child_secondary =\
            _child_pri_sec_filter(expected_child)

        _device_compare(
            existing_child_primary,
            'iscsi',
            type=expected_child_primary.type,
            i_scsi_vnic_name=expected_child_primary.i_scsi_vnic_name)
        _device_compare(
            existing_child_secondary,
            'iscsi',
            type=expected_child_secondary.type,
            i_scsi_vnic_name=expected_child_secondary.i_scsi_vnic_name)
Пример #17
0
def boot_policy_create(handle,
                       name,
                       org_dn="org-root",
                       reboot_on_update="no",
                       enforce_vnic_name="yes",
                       boot_mode="legacy",
                       policy_owner="local",
                       descr=None,
                       **kwargs):
    """
    creates boot policy

    Args:
        handle (UcsHandle)
        name (string): boot policy name
        org_dn (string): org dn
        reboot_on_update (string): valid values are "yes", "no"
        enforce_vnic_name (string): valid values are "yes", "no"
        boot_mode (string): "legacy" or "uefi"
        policy_owner (string): "local" or "pending-policy" or  "policy"
        descr (string): Basic description.
        **kwargs: Any additional key-value pair of managed object(MO)'s
                  property and value, which are not part of regular args.
                  This should be used for future version compatibility.

    Returns:
        LsbootPolicy: managed object

    Raises:
        UcsOperationError: if OrgOrg is not present

    Example:
        boot_policy_create(handle,
                           name="sample_boot",
                           org_dn="org-root/org-finance",
                           reboot_on_update="yes",
                           enforce_vnic_name="yes",
                           boot_mode="legacy",
                           descr="sample description")
    """
    from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy

    obj = handle.query_dn(org_dn)
    if not obj:
        raise UcsOperationError(
            "boot_policy_create", "Org '%s' does not \
                                 exist" % org_dn)

    mo = LsbootPolicy(parent_mo_or_dn=obj,
                      name=name,
                      reboot_on_update=reboot_on_update,
                      enforce_vnic_name=enforce_vnic_name,
                      boot_mode=boot_mode,
                      policy_owner=policy_owner,
                      descr=descr)

    mo.set_prop_multiple(**kwargs)
    handle.add_mo(mo, modify_present=True)
    handle.commit()
    return mo
Пример #18
0
def tacacsplus_provider_group_provider_get(
        handle,
        group_name,
        name,
        caller="tacacsplus_provider_group_provider_get"):
    """
    checks if a tacacsplus provider added to a tacacsplus provider group

    Args:
        handle (UcsHandle)
        group_name (string): tacacsplus provider group name
        name (string): tacacsplus provider name
        caller (string): name of the caller function

    Returns:
        AaaProviderRef: managed object

    Raises:
        UcsOperationError: if AaaProviderRef is not present

    Example:
        tacacsplus_provider_group_provider_get(handle,
                                    group_name="test_prov_grp",
                                    name="test_tacac_prov")
    """
    provider_group_dn = _tacacs_dn + "/providergroup-" + group_name
    provider_ref_dn = provider_group_dn + "/provider-ref-" + name
    mo = handle.query_dn(provider_ref_dn)
    if mo is None:
        raise UcsOperationError(
            caller, "Tacacsplus Provider Reference '%s' does not exist" %
            provider_ref_dn)
    return mo
Пример #19
0
def callhome_disable(handle):
    """
    Disables call home alert.

    Args:
        handle (UcsHandle)

    Returns:
        CallhomeEp : ManagedObject

    Raises:
        UcsOperationError: If CallhomeEp is not present

    Example:
        callhome_disable(handle)
    """
    mo = handle.query_dn(_base_dn)
    if not mo:
        raise UcsOperationError("callhome_disable",
                                 "Call home not available.")

    args = {'admin_state': "off"}

    mo.set_prop_multiple(**args)
    handle.set_mo(mo)
    handle.commit()
    return mo
Пример #20
0
def _get_inventory_csv(inventory, file_name, spec=inventory_spec):
    import csv
    if file_name is None:
        raise UcsOperationError("Inventory collection",
                                "file_name is a required parameter")
    f = csv.writer(open(file_name, "w"))

    x = inventory
    for comp in spec:
        f.writerow([comp.upper()])
        props = spec[comp]["props"]
        keys = [y['prop'] for y in props]
        keys.insert(0, "Host")
        f.writerow(keys)

        for ip in x:
            if comp not in x[ip]:
                continue
            host_component = x[ip][comp]
            if len(host_component) == 0:
                continue
            for entry in host_component:
                row_val = []
                for key in keys:
                    if key not in entry:
                        continue
                    row_val.append(entry[key])
                row_val.insert(0, ip)
                f.writerow(row_val)

        f.writerow([])
        f.writerow([])
Пример #21
0
def syslog_local_console_disable(handle):
    """
    disables system logs on local console

    Args:
        handle (UcsHandle)

    Returns:
        CommSyslogConsole: managed object

    Raises:
        UcsOperationError: if CommSyslogConsole is not present

    Example:
        syslog_local_console_disable(handle)
    """
    from ucsmsdk.mometa.comm.CommSyslogConsole import \
        CommSyslogConsoleConsts

    dn = _syslog_dn + "/console"
    mo = handle.query_dn(dn)
    if not mo:
        raise UcsOperationError("syslog_local_console_disable",
                                "syslog console does not exist.")

    args = {'admin_state': CommSyslogConsoleConsts.ADMIN_STATE_DISABLED}

    mo.set_prop_multiple(**args)
    handle.set_mo(mo)
    handle.commit()
    return mo
Пример #22
0
def syslog_remote_disable(handle, name):
    """
    disables system logs on remote server

    Args:
        handle (UcsHandle)
        name (string): remote server type
         valid values are "primary", "secondary", "tertiary"

    Returns:
        CommSyslogClient: managed object

    Raises:
        UcsOperationError: if CommSyslogClient is not present

    Example:
        syslog_remote_disable(handle, name="primary")
    """
    from ucsmsdk.mometa.comm.CommSyslogClient import \
        CommSyslogClientConsts

    dn = _syslog_dn + "/client-" + name
    mo = handle.query_dn(dn)
    if not mo:
        raise UcsOperationError("syslog_remote_disable",
                                "Remote Destination '%s' does not exist" % dn)

    args = {'admin_state': CommSyslogClientConsts.ADMIN_STATE_DISABLED}

    mo.set_prop_multiple(**args)
    handle.set_mo(mo)
    handle.commit()
    return mo
Пример #23
0
def radius_provider_group_provider_get(
        handle, group_name, name, caller="radius_provider_group_provider_get"):
    """
    gets provider  under a radius provider group

    Args:
        handle (UcsHandle)
        group_name (string): radius provider group name
        name (string): radius provider name

    Returns:
        AaaProviderRef: managed object

    Raises:
        UcsOperationError: if AaaProviderRef is not present

    Example:
        radius_provider_group_provider_get(handle,
                                    group_name="test_radius_provider_group",
                                    name="test_radius_provider")
    """
    provider_group_dn = _radius_dn + "/providergroup-" + group_name
    provider_ref_dn = provider_group_dn + "/provider-ref-" + name
    mo = handle.query_dn(provider_ref_dn)
    if mo is None:
        raise UcsOperationError(
            caller,
            "Radius Provider Reference '%s' does not exist" % provider_ref_dn)
    return mo
Пример #24
0
def _compare_san_sub_child(existing_sub_child, expected_sub_child):

    if len(existing_sub_child) != len(expected_sub_child):
        raise UcsOperationError("_compare_boot_policy",
                                "sub child count mismatch for 'san'.")

    if len(existing_sub_child) == 0:
        return
    if len(existing_sub_child) == 1:
        _device_compare(existing_sub_child[0],
                        'san',
                        type=expected_san.type,
                        wwn=expected_sub_child.wwn,
                        lun=expected_sub_child.lun)
    if len(existing_sub_child) == 2:
        existing_sub_child_primary, existing_sub_child_secondary =\
            _child_pri_sec_filter(existing_sub_child)

        expected_sub_child_primary, expected_sub_child_secondary =\
            _child_pri_sec_filter(expected_sub_child)

        _device_compare(existing_sub_child_primary,
                        'san',
                        type=expected_sub_child_primary.type,
                        wwn=expected_sub_child_primary.wwn,
                        lun=expected_sub_child_primary.lun)
        _device_compare(existing_sub_child_secondary,
                        'san',
                        type=expected_sub_child_secondary.type,
                        wwn=expected_sub_child_secondary.wwn,
                        lun=expected_sub_child_secondary.lun)
Пример #25
0
def _compare_lan(existing_lan, expected_lan):
    _device_compare(existing_lan, 'lan', order=expected_lan.order)

    existing_child = existing_lan.child
    expected_child = expected_lan.child
    if len(existing_child) != len(expected_child):
        raise UcsOperationError("_compare_boot_policy",
                                "Child count mismatch for 'lan'.")
    if len(existing_child) == 0:
        return
    if len(existing_child) == 1:
        _device_compare(existing_child[0],
                        'lan',
                        type=expected_lan.type,
                        vnic_name=expected_lan.vnic_name)
    if len(existing_child) == 2:
        existing_child_primary, existing_child_secondary =\
            _child_pri_sec_filter(existing_child)

        expected_child_primary, expected_child_secondary =\
            _child_pri_sec_filter(expected_child)

        _device_compare(existing_child_primary,
                        'lan',
                        type=expected_child_primary.type,
                        vnic_name=expected_child_primary.vnic_name)
        _device_compare(existing_child_secondary,
                        'lan',
                        type=expected_child_secondary.type,
                        vnic_name=expected_child_secondary.vnic_name)
Пример #26
0
def _compare_embedded_disk(existing_disk, expected_disk):
    _device_compare(existing_disk, 'embedded_disk', order=expected_disk.order)

    existing_child = existing_disk.child
    expected_child = expected_disk.child
    if len(existing_child) != len(expected_child):
        raise UcsOperationError("_compare_boot_policy",
                                "Child count mismatch for 'embedded_disk'.")
    if len(existing_child) == 0:
        return
    if len(existing_child) == 1:
        _device_compare(existing_child[0],
                        'embedded_disk',
                        type=expected_disk.type,
                        slot_number=expected_disk.slot_number)
    if len(existing_child) == 2:
        existing_child_primary, existing_child_secondary =\
            _child_pri_sec_filter(existing_child)

        expected_child_primary, expected_child_secondary =\
            _child_pri_sec_filter(expected_child)

        _device_compare(existing_child_primary,
                        'embedded_disk',
                        type=expected_child_primary.type,
                        slot_number=expected_child_primary.slot_number)
        _device_compare(existing_child_secondary,
                        'embedded_disk',
                        type=expected_child_secondary.type,
                        slot_number=expected_child_secondary.slot_number)
Пример #27
0
def boot_policy_get(handle, name, org_dn="org-root", caller="boot_policy_get"):
    """
    gets boot policy.

    Args:
        handle (UcsHandle)
        name (string): boot policy name
        org_dn (string): org dn
        caller (string): caller method name

    Returns:
        LsbootPolicy: managed object

    Raises:
        UcsOperationError: if LsbootPolicy is not present

    Example:
_       boot_policy_get(handle,
                        name="sample_boot",
                        org_dn="org-root/org-finance",
                        caller="boot_policy_modify")
    """
    dn = org_dn + "/boot-policy-" + name
    mo = handle.query_dn(dn)
    if mo is None:
        raise UcsOperationError(caller, "BootPolicy '%s' does not exist" % dn)
    return mo
Пример #28
0
def _san_image_add(parent_mo, type, vnic_name):
    from ucsmsdk.mometa.lsboot.LsbootSanCatSanImage import \
        LsbootSanCatSanImage
    if not (vnic_name and type):
        raise UcsOperationError("Required Parameter 'vnic_name' or "
                                "'type' missing.")
    return LsbootSanCatSanImage(parent_mo_or_dn=parent_mo,
                                vnic_name=vnic_name,
                                type=type)
Пример #29
0
def _get_inventory_html(inventory, file_name, spec=inventory_spec):
    if file_name is None:
        raise UcsOperationError("Inventory collection",
                                "file_name is a required parameter")
    f = open(file_name, "w")

    html = ""
    html += "<html>\n"

    html += "<head>\n"
    html += _get_search_script()
    html += "</head>\n"
    html += "<body>\n"
    html += """
    <br>
    <input type="text" id="searchInput" onkeyup="myFunction()" placeholder="Search..">
    </br>
    """

    x = inventory
    for comp in spec:
        html += '<table border="1">'
        html += "<br><br>" + comp.upper()

        props = spec[comp]["props"]
        keys = [y['prop'] for y in props]
        keys.insert(0, "Host")
        html += '<tr style="background-color: gainsboro;">'
        for key in keys:
            html += "<th>" + key + "</th>"
        html += '</tr>'

        for ip in x:
            if comp not in x[ip]:
                continue
            host_component = x[ip][comp]
            if len(host_component) == 0:
                continue
            for entry in host_component:
                row_val = []
                for key in keys:
                    if key not in entry:
                        continue
                    row_val.append(entry[key])
                row_val.insert(0, ip)
                html += "<tr>"
                for each in row_val:
                    if each is None:
                        each = ""
                    html += "<td>" + each + "</td>"
                html += "</tr>"

    html += "</table>\n"
    html += "</body>"
    html += "</html>"
    f.write(html)
    f.close()
Пример #30
0
def _local_lun_add(parent_mo, order, lun_name=None, type=None):
    from ucsmsdk.mometa.lsboot.LsbootLocalHddImage import LsbootLocalHddImage
    from ucsmsdk.mometa.lsboot.LsbootLocalLunImagePath import \
        LsbootLocalLunImagePath

    mo = [mo for mo in parent_mo.child
          if mo.get_class_id() == "LsbootLocalHddImage"]
    if mo and not mo[0].child:
        raise UcsOperationError(
            "_local_lun_add",
            "Instance of Local Lun already added at order '%s'" %
            mo[0].order)
    if mo and mo[0].child:
        child_count = len(mo[0].child)
        if child_count >= 2:
            raise UcsOperationError(
                "_local_lun_add",
                "Both instance of Local Lun already added.")
        if mo[0].child[0].type == type:
            raise UcsOperationError(
                "_local_lun_add",
                "Instance of Local Lun of type '%s' already added at  order '%s'." %
                (type,
                 mo[0].order))

        if not lun_name or not type:
            raise UcsOperationError(
                "_local_lun_add",
                "Required parameter 'lun_name' or 'type' missing.")

        LsbootLocalLunImagePath(parent_mo_or_dn=mo[0], lun_name=lun_name,
                                type=type)
        return

    mo = LsbootLocalHddImage(parent_mo_or_dn=parent_mo, order=order)
    if not lun_name and not type:
        return
    if (lun_name and not type) or (not lun_name and type):
        raise UcsOperationError(
            "_local_lun_add",
            "Required parameter 'lun_name' or 'type' missing.")
    LsbootLocalLunImagePath(parent_mo_or_dn=mo,
                            lun_name=lun_name,
                            type=type)