Example #1
0
def set_vmedia_boot_policy(ucs_handle, sp_template_boot_policy_object,
                           org_name):
    sp_template_boot_policy_name = sp_template_boot_policy_object.name
    mo = LsbootPolicy(parent_mo_or_dn="org-root/org-" + org_name,
                      name=sp_template_boot_policy_name)
    LsbootVirtualMedia(parent_mo_or_dn=mo,
                       access="read-only-remote-cimc",
                       lun_id="0",
                       order="3")
    ucs_handle.add_mo(mo, True)
    ucs_handle.commit()

    if sp_template_boot_policy_name == "HyperFlex":
        mo = LsbootUsbFlashStorageImage(
            parent_mo_or_dn=
            "org-root/org-hxcluster/boot-policy-HyperFlex/storage/local-storage",
            order="3")
    elif sp_template_boot_policy_name == "HyperFlex-m5":
        mo = LsbootEmbeddedLocalDiskImage(
            parent_mo_or_dn="org-root/org-" + org_name + "/boot-policy-" +
            sp_template_boot_policy_name + "/storage/local-storage",
            order="3")
    ucs_handle.add_mo(mo, True)
    mo = LsbootVirtualMedia(parent_mo_or_dn="org-root/org-" + org_name +
                            "/boot-policy-" + sp_template_boot_policy_name,
                            access="read-only-remote-cimc",
                            order="1")
    ucs_handle.add_mo(mo, True)
    mo = LsbootVirtualMedia(parent_mo_or_dn="org-root/org-" + org_name +
                            "/boot-policy-" + sp_template_boot_policy_name,
                            access="read-only",
                            order="2")
    ucs_handle.add_mo(mo, True)
    ucs_handle.commit()
Example #2
0
def createKubeBootPolicy(handle, org):
    print "Creating Kube Boot Policy"
    from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy
    from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia
    from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
    from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage
    from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import LsbootDefaultLocalImage

    mo = LsbootPolicy(parent_mo_or_dn=org,
                      name="kube",
                      descr="Kuberenetes",
                      reboot_on_update="yes",
                      policy_owner="local",
                      enforce_vnic_name="yes",
                      boot_mode="legacy")
    mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo,
                              access="read-only-remote-cimc",
                              lun_id="0",
                              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 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_2_1, order="1")

    handle.add_mo(mo, modify_present=True)
    try:
        handle.commit()
    except UcsException as err:
        if err.error_code == "103":
            print "\talready exists"
Example #3
0
    def create_boot_policy(handle, org):
        from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy
        from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia
        from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
        from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage
        from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import LsbootDefaultLocalImage

        print "Creating KUBAM Boot Policy"
        mo_bp = LsbootPolicy(
            parent_mo_or_dn=org, name="kubam", descr="kubam", reboot_on_update="yes",
            policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy"
        )
        LsbootVirtualMedia(parent_mo_or_dn=mo_bp, access="read-only-remote-cimc", lun_id="0", order="2")
        mo_bs = LsbootStorage(parent_mo_or_dn=mo_bp, order="1")
        mo_bls = LsbootLocalStorage(parent_mo_or_dn=mo_bs, )
        LsbootDefaultLocalImage(parent_mo_or_dn=mo_bls, order="1")

        handle.add_mo(mo_bp, modify_present=True)
        try:
            handle.commit()
        except UcsException as err:
            if err.error_code == "103":
                print "\talready exists"
            else:
                return 1, err.error_descr
        return 0, None
Example #4
0
def _add_virtual_drive(parent_mo, order):
    LsbootVirtualMedia(parent_mo_or_dn=parent_mo, access="read-write-drive",
                       order=order)
Example #5
0
def _add_floppy_remote(parent_mo, order):
    LsbootVirtualMedia(parent_mo_or_dn=parent_mo, access="read-write-remote",
                       order=order)
Example #6
0
def _add_floppy_local(parent_mo, order):
    LsbootVirtualMedia(parent_mo_or_dn=parent_mo,
                       access="read-write-local",
                       order=order)
Example #7
0
def _add_cdrom_cimc(parent_mo, order):
    LsbootVirtualMedia(parent_mo_or_dn=parent_mo,
                       access="read-only-remote-cimc",
                       order=order)
Example #8
0
def _add_cdrom_local(parent_mo, order):
    LsbootVirtualMedia(parent_mo_or_dn=parent_mo,
                       access="read-only-local",
                       order=order)
Example #9
0
"""

from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia
import connection as Connection

UCS_HOST = Connection.UCS_HOST
UCS_USER = Connection.UCS_USER
UCS_PASS = Connection.UCS_PASS

HANDLE = UcsHandle(UCS_HOST, UCS_USER, UCS_PASS)
HANDLE.login()

BOOT_POLICY = LsbootVirtualMedia(
    parent_mo_or_dn="org-root/boot-policy-virt-media-add",
    access="read-only-remote-cimc",
    order="3"
)
HANDLE.add_mo(BOOT_POLICY, True)
HANDLE.commit()

# Get boot items (children) of Boot Policy
OBJECTS = HANDLE.query_children(in_dn="org-root/boot-policy-virt-media-add")

# Update boot items order
for mo in OBJECTS:
    if mo.access == "read-only-remote-cimc":
        mo.order = "1"
        print(mo)
        HANDLE.set_mo(mo)
    elif mo.access == "read-write":
Example #10
0
    handle.add_mo(mo)
    handle.commit()

    mo = VnicLanConnTempl(parent_mo_or_dn=my_Full_Path_Org, templ_type="updating-template", name="iSCSI-B", descr="iSCSI FI-B", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", mtu="9000", policy_owner="local", qos_policy_name="Nimble-QoS", ident_pool_name="iSCSI-B", cdn_source="vnic-name", nw_ctrl_policy_name="Nimble-iSCSI")
    mo_1 = VnicEtherIf(parent_mo_or_dn=mo, default_net="yes", name="iSCSI-B")
    handle.add_mo(mo)
    handle.commit()

#Create Local Disk Conf Policy (any-configuration)
mo = StorageLocalDiskConfigPolicy(parent_mo_or_dn=my_Full_Path_Org, protect_config="yes", name="Local_Disk_CP", descr="Local Disk Configuration Policy Desc", flex_flash_raid_reporting_state="enable", flex_flash_state="enable", policy_owner="local", mode="any-configuration")
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")
Example #11
0
def main():
    logging.basicConfig(level=logging.INFO)
    argument_spec = ucs_argument_spec
    argument_spec.update(
        name=dict(type='str', required=True),
        description=dict(type='str', default=''),
        state=dict(type='str',
                   default='present',
                   choices=['present', 'absent']),
        boot_mode=dict(type='str',
                       default='legacy',
                       choices=['legacy', 'uefi']),
        enforce_vnic_name=dict(type='str',
                               default='yes',
                               choices=['yes', 'no']),
        reboot_on_update=dict(type='str', default='no', choices=['yes', 'no']),
        boot_security=dict(type='str', default='no', choices=['yes', 'no']),
        boot_order=dict(type='list'),
    )

    module = AnsibleModule(
        argument_spec,
        supports_check_mode=True,
    )

    ucs = UCSModule(module)

    err = False

    # UCSModule creation above verifies ucsmsdk is present and exits on failure, so additional imports are done below.
    from ucsmsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity
    from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import LsbootDefaultLocalImage
    # from ucsmsdk.mometa.lsboot.LsbootDef import LsbootDef
    # from ucsmsdk.mometa.lsboot.LsbootEFIShell import LsbootEFIShell
    # from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalDiskImagePath import LsbootEmbeddedLocalDiskImagePath
    # from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalDiskImage import LsbootEmbeddedLocalDiskImage
    # from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalLunImage import LsbootEmbeddedLocalLunImage
    # from ucsmsdk.mometa.lsboot.LsbootIScsiImagePath import LsbootIScsiImagePath
    # from ucsmsdk.mometa.lsboot.LsbootIScsi import LsbootIScsi
    # from ucsmsdk.mometa.lsboot.LsbootLanImagePath import LsbootLanImagePath
    # from ucsmsdk.mometa.lsboot.LsbootLan import LsbootLan
    # from ucsmsdk.mometa.lsboot.LsbootLocalDiskImagePath import LsbootLocalDiskImagePath
    # from ucsmsdk.mometa.lsboot.LsbootLocalDiskImage import LsbootLocalDiskImage
    from ucsmsdk.mometa.lsboot.LsbootLocalHddImage import LsbootLocalHddImage

    # from ucsmsdk.mometa.lsboot.LsbootNvmeDiskSsd import LsbootNvmeDiskSsd
    # from ucsmsdk.mometa.lsboot.LsbootNvmePciSsd import LsbootNvmePciSsd
    # from ucsmsdk.mometa.lsboot.LsbootNvme import LsbootNvme
    from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy
    # from ucsmsdk.mometa.lsboot.LsbootSanCatSanImagePath import LsbootSanCatSanImagePath
    # from ucsmsdk.mometa.lsboot.LsbootSanCatSanImage import LsbootSanCatSanImage
    # from ucsmsdk.mometa.lsboot.LsbootSanImagePath import LsbootSanImagePath
    # from ucsmsdk.mometa.lsboot.LsbootSanImage import LsbootSanImage
    # from ucsmsdk.mometa.lsboot.LsbootSan import LsbootSan

    # from ucsmsdk.mometa.lsboot.LsbootUEFIBootParam import LsbootUEFIBootParam
    # from ucsmsdk.mometa.lsboot.LsbootUsbExternalImage import LsbootUsbExternalImage
    # from ucsmsdk.mometa.lsboot.LsbootUsbFlashStorageImage import LsbootUsbFlashStorageImage
    # from ucsmsdk.mometa.lsboot.LsbootUsbInternalImage import LsbootUsbInternalImage
    from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia

    changed = False
    try:
        mo_exists = False
        parent_props_match = False
        child_props_match = True
        dn_base = 'org-root'
        dn = dn_base + '/boot-policy-' + 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:
            boot_security_policy_enabled = False
            if module.params[PARAM_BOOT_SECURITY] == 'yes' and module.params[
                    PARAM_BOOT_MODE] == BOOT_MODE_UEFI:
                boot_security_policy_enabled = True
            boot_order_tree = build_boot_order_tree(
                dn, module.params[BOOT_ORDER], boot_security_policy_enabled)
            boot_order_matches = dict()

            if mo_exists:
                # check top-level mo props
                kwargs = dict(name=module.params['name'])
                kwargs['descr'] = module.params['description']
                kwargs[PARAM_BOOT_MODE] = module.params[PARAM_BOOT_MODE]
                kwargs['enforce_vnic_name'] = module.params[
                    'enforce_vnic_name']
                kwargs['reboot_on_update'] = module.params['reboot_on_update']

                if (mo.check_prop_match(**kwargs)):
                    parent_props_match = True
                    logging.info("parent props match: %s", parent_props_match)

                # verify boot order settings
                if module.params.get('boot_order'):
                    child_props_match = verify_boot_order_settings(
                        mo, dn, boot_security_policy_enabled,
                        boot_order_matches, boot_order_tree, ucs)

            if not (parent_props_match and child_props_match):
                if not module.check_mode:
                    # if some boot order entries need to be removed remove them first
                    check_and_remove_boot_order_entries(
                        mo_exists, child_props_match, boot_order_matches,
                        boot_order_tree, ucs)

                    if not parent_props_match:
                        mo = LsbootPolicy(
                            parent_mo_or_dn=dn_base,
                            name=module.params['name'],
                            descr=module.params['description'],
                            boot_mode=module.params['boot_mode'],
                            enforce_vnic_name=module.
                            params['enforce_vnic_name'],
                            reboot_on_update=module.params['reboot_on_update'])
                        ucs.login_handle.add_mo(mo, True)

                    for boot_order_dn in boot_order_tree.keys():
                        if not (boot_order_matches.get(boot_order_dn)
                                and boot_order_matches[boot_order_dn]):
                            new_order = boot_order_tree.get(boot_order_dn)
                            # boot security
                            if boot_order_dn == get_dn_path(
                                    dn, BOOT_SECURITY_DN):
                                # secure_boot='yes' if boot_security_policy_enabled == BOOT_SECURITY_YES else 'no'
                                # print("secure_boot", secure_boot)
                                mo_bsec = LsbootBootSecurity(
                                    parent_mo_or_dn=dn,
                                    secure_boot='yes'
                                    if boot_security_policy_enabled else 'no')
                                ucs.login_handle.add_mo(mo_bsec, True)
                            # local disk
                            elif boot_order_dn == get_dn_path(
                                    dn, LOCAL_DISK_DN):
                                logging.info("dn: %s order: %s", boot_order_dn,
                                             new_order)
                                mo_blocal_storage = create_local_storage(
                                    dn, new_order, ucs)
                                mo_blocal_image = LsbootDefaultLocalImage(
                                    parent_mo_or_dn=mo_blocal_storage,
                                    order=new_order)
                                ucs.login_handle.add_mo(mo_blocal_image, True)
                            # local lun
                            elif boot_order_dn == get_dn_path(
                                    dn, LOCAL_LUN_DN):
                                logging.info("dn: %s order: %s", boot_order_dn,
                                             new_order)
                                mo_blocal_storage = create_local_storage(
                                    dn, new_order, ucs)
                                mo_blocal_lun = LsbootLocalHddImage(
                                    parent_mo_or_dn=mo_blocal_storage,
                                    order=new_order)
                                ucs.login_handle.add_mo(mo_blocal_lun, True)
                                lun_images = get_params(
                                    module.params[BOOT_ORDER], LOCAL_LUN)
                                logging.info("dn: %s lun_image: %s",
                                             boot_order_dn, lun_images)
                                add_lun_local_image_path(
                                    mo_blocal_lun, lun_images, ucs)
                            # local CD/DVD
                            elif boot_order_dn == get_dn_path(
                                    dn, VIRTUAL_MEDIA_DN):
                                logging.info("dn: %s order: %s", boot_order_dn,
                                             new_order)
                                mo_bvmedia = LsbootVirtualMedia(
                                    parent_mo_or_dn=dn,
                                    order=new_order,
                                    access=ACCESS_READ_ONLY)
                                ucs.login_handle.add_mo(mo_bvmedia, True)
                            # cimc CD/DVD
                            elif boot_order_dn == get_dn_path(
                                    dn, CIMC_MEDIA_DVD_DN):
                                logging.info("dn: %s order: %s", boot_order_dn,
                                             new_order)
                                mo_boot_cimc_vmedia_dvd = LsbootVirtualMedia(
                                    parent_mo_or_dn=dn,
                                    order=new_order,
                                    access=ACCESS_READ_ONLY_REMOTE_CIMC)
                                ucs.login_handle.add_mo(
                                    mo_boot_cimc_vmedia_dvd, True)
                            # cimc HDD
                            elif boot_order_dn == get_dn_path(
                                    dn, CIMC_MEDIA_HDD_DN):
                                logging.info("dn: %s order: %s", boot_order_dn,
                                             new_order)
                                mo_boot_cimc_vmedia_hdd = LsbootVirtualMedia(
                                    parent_mo_or_dn=dn,
                                    order=new_order,
                                    access=ACCESS_READ_WRITE_REMOTE_CIMC)
                                ucs.login_handle.add_mo(
                                    mo_boot_cimc_vmedia_hdd, True)

                    ucs.login_handle.commit()
                    changed = True

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

    ucs.result['changed'] = changed
    if err:
        module.fail_json(**ucs.result)
    module.exit_json(**ucs.result)
Example #12
0
        from ucsmsdk.mometa.lsboot.LsbootLanImagePath import LsbootLanImagePath
        from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia
        from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
        from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage
        from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import LsbootDefaultLocalImage

        mo = LsbootPolicy(parent_mo_or_dn="org-root",
                          name="PXE_Boot",
                          descr="",
                          reboot_on_update="no",
                          policy_owner="local",
                          enforce_vnic_name="yes",
                          boot_mode="legacy")
        mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo,
                                  access="read-only",
                                  lun_id="0",
                                  mapping_name="",
                                  order="1")
        mo_2 = LsbootLan(parent_mo_or_dn=mo, prot="pxe", order="2")
        mo_2_1 = LsbootLanImagePath(parent_mo_or_dn=mo_2,
                                    prov_srv_policy_name="",
                                    img_sec_policy_name="",
                                    vnic_name="PXE",
                                    i_scsi_vnic_name="",
                                    boot_ip_policy_name="",
                                    img_policy_name="",
                                    type="primary")
        mo_3 = LsbootStorage(parent_mo_or_dn=mo, order="3")
        mo_3_1 = LsbootLocalStorage(parent_mo_or_dn=mo_3, )
        mo_3_1_1 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_3_1, order="3")
        handle.add_mo(mo)