Ejemplo n.º 1
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"
Ejemplo n.º 2
0
def _device_add(handle, boot_policy, devices):
    from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
    from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage

    _validate_device_combination(devices)

    ls_boot_storage_exist = False
    for device in devices:
        device_name = device["device_name"]
        device_order = str(device["device_order"])
        device_props = {key: value for key, value in device.iteritems()
                        if key not in ["device_name", "device_order"]}
        if device_name in _local_devices:
            if not ls_boot_storage_exist:
                lsboot_storage = LsbootStorage(parent_mo_or_dn=boot_policy)
                lsboot_local_storage = LsbootLocalStorage(
                    parent_mo_or_dn=lsboot_storage)
                ls_boot_storage_exist = True
            _local_device_add(lsboot_local_storage, device_name,
                              device_order, **device_props)
        elif device_name in _vmedia_devices:
            _vmedia_device_add(boot_policy, device_name, device_order)
        elif device_name == "lan":
            _lan_device_add(boot_policy, device_order, **device_props)
        elif device_name == "san":
            _san_device_add(boot_policy, device_order, **device_props)
        elif device_name == "iscsi":
            _iscsi_device_add(boot_policy, device_order, **device_props)
        elif device_name == "efi":
            _efi_shell_device_add()
        else:
            raise UcsOpeartionError(
                "_device_add",
                " Invalid Device <%s>" %
                device_name)
Ejemplo n.º 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
Ejemplo n.º 4
0
def create_local_storage(dn, new_order, ucs):
    from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
    from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage

    mo_bstorage = LsbootStorage(parent_mo_or_dn=dn, order=new_order)
    ucs.login_handle.add_mo(mo_bstorage, True)
    mo_blocal_storage = LsbootLocalStorage(parent_mo_or_dn=mo_bstorage, )
    ucs.login_handle.add_mo(mo_blocal_storage, True)
    return mo_blocal_storage
Ejemplo n.º 5
0
def _add_device(handle, parent_mo, boot_device):
    count = 0
    children = handle.query_children(parent_mo)
    for child in children:
        if hasattr(child, 'order'):
            order = getattr(child, 'order')
            if order not in boot_device:
                log.debug("Deleting boot device from boot policy: %s",
                          child.dn)
                handle.remove_mo(child)

    for k in boot_device.keys():
        log.debug("Add boot device: order=%s, %s", k, boot_device[k])
        if boot_device[k] in ["cdrom-local", "cdrom"]:
            _add_cdrom_local(parent_mo, k)
        elif boot_device[k] == "cdrom-cimc":
            _add_cdrom_cimc(parent_mo, k)
        elif boot_device[k] == "cdrom-remote":
            _add_cdrom_remote(parent_mo, k)
        elif boot_device[k] in [
                "lun", "local-disk", "sd-card", "usb-internal", "usb-external"
        ]:
            if count == 0:
                mo = LsbootStorage(parent_mo_or_dn=parent_mo, order=k)
                mo_1 = LsbootLocalStorage(parent_mo_or_dn=mo)
                count += 1
            if boot_device[k] == "lun":
                _add_local_lun(mo_1, k)
            elif boot_device[k] == "local-disk":
                _add_local_disk(mo_1, k)
            elif boot_device[k] == "sd-card":
                _add_sd_card(mo_1, k)
            elif boot_device[k] == "usb-internal":
                _add_usb_internal(mo_1, k)
            elif boot_device[k] == "usb-external":
                _add_usb_external(mo_1, k)
        elif boot_device[k] in ["floppy", "floppy-local"]:
            _add_floppy_local(parent_mo, k)
        elif boot_device[k] == "floppy-external":
            _add_floppy_remote(parent_mo, k)
        elif boot_device[k] == "virtual-drive":
            _add_virtual_drive(parent_mo, k)
        else:
            log.debug("Option <%s> not recognized." % boot_device[k])
Ejemplo n.º 6
0
def run(job, resource, *args, **kwargs):
    username = conn.username
    password = conn.password

    organization = "{{ organization }}"
    service_profile_template = "{{ service_profile_template }}"
    create_sp_from_sp_template = "{{ create_sp_from_sp_template }}"
    service_profile_name = "{{ service_profile_name }}"
    service_profile_description = "{{ service_profile_description }}"
    use_blade_servers = "{{ use_blade_servers }}"
    chassis = "{{ chassis }}"
    ucs_server_dn = "{{ ucs_server_dn }}"
    ucs_rack_server = "{{ rack_server }}"
    mac_pool_name = "{{ mac_pool_name }}"

    service_profile_server_dn, _ = CustomField.objects.get_or_create(
        name="service_profile_server_dn",
        label="Service Profile Server DN",
        type="STR",
        show_on_servers=True)

    handler.login()
    ucs_event_handler = UcsEventHandle(handler)

    # create SP in an org
    set_progress(f"Creating service profile named {service_profile_name}")
    if create_sp_from_sp_template == "True":
        dn_set = ucscbasetype.DnSet()
        dn_set.child_add(Dn(value=f"{service_profile_name}"))

        xml_element = mf.ls_instantiate_n_named_template(
            cookie=handler.cookie,
            dn=service_profile_template,
            in_error_on_existing="true",
            in_name_set=dn_set,
            in_target_org=organization)
        handler.process_xml_elem(xml_element)
    else:
        mo = LsServer(parent_mo_or_dn=organization,
                      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=service_profile_description,
                      stats_policy_name="default",
                      policy_owner="local",
                      ext_ip_pool_name="ext-mgmt",
                      boot_policy_name="",
                      usr_lbl="",
                      host_fw_policy_name="",
                      vcon_profile_name="",
                      ident_pool_name="",
                      src_templ_name="",
                      local_disk_policy_name="",
                      scrub_policy_name="",
                      power_policy_name="default",
                      maint_policy_name="",
                      name=service_profile_name,
                      resolve_remote="yes")
        mo_1 = LsbootDef(parent_mo_or_dn=mo,
                         descr="",
                         reboot_on_update="no",
                         adv_boot_order_applicable="no",
                         policy_owner="local",
                         enforce_vnic_name="yes",
                         boot_mode="legacy")
        mo_1_1 = LsbootStorage(parent_mo_or_dn=mo_1, order="1")
        mo_1_1_1 = LsbootLocalStorage(parent_mo_or_dn=mo_1_1, )
        mo_1_1_1_1 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_1_1_1,
                                             order="1")
        mo_2 = VnicEther(parent_mo_or_dn=mo,
                         nw_ctrl_policy_name="",
                         name="eth0",
                         admin_host_port="ANY",
                         admin_vcon="any",
                         stats_policy_name="default",
                         admin_cdn_name="",
                         switch_id="A",
                         pin_to_group_name="",
                         mtu="1500",
                         qos_policy_name="",
                         adaptor_profile_name="",
                         ident_pool_name=mac_pool_name,
                         order="unspecified",
                         nw_templ_name="",
                         addr="derived")
        mo_2_1 = VnicEtherIf(parent_mo_or_dn=mo_2,
                             default_net="yes",
                             name="default")
        mo_3 = VnicFcNode(parent_mo_or_dn=mo,
                          ident_pool_name="",
                          addr="pool-derived")
        handler.add_mo(mo)

    # Associate a server to a service profile.
    if use_blade_servers == "True":
        set_progress(
            f"Associating service profile {service_profile_name} with {ucs_server_dn}"
        )
        mo = LsBinding(
            parent_mo_or_dn=f"{organization}/ls-{service_profile_name}",
            pn_dn=ucs_server_dn,
            restrict_migration="no")
    else:
        set_progress(
            f"Associating service profile {service_profile_name} with {ucs_rack_server}"
        )
        mo = LsBinding(
            parent_mo_or_dn=f"{organization}/ls-{service_profile_name}",
            pn_dn=ucs_rack_server,
            restrict_migration="no")

    handler.add_mo(mo)
    handler.commit()
    mo = handler.query_dn(f"{organization}/ls-{service_profile_name}")

    # Save the service profile dn
    resource.service_profile_server_dn = f"{organization}/ls-{service_profile_name}"
    resource.name = service_profile_name
    resource.save()

    return "SUCCESS", f"Created service profile named {service_profile_name}", ""
Ejemplo n.º 7
0
    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")
    handle.add_mo(mo)
    handle.commit()
Ejemplo n.º 8
0
def boot_policy(input):
    name = input['name']
    type = input['type']
    device_name = input['device_name']
    order = input['order']
    state = input['state']
    ip = input['ip']
    username = input['username']
    password = input['password']
    mo = ""
    mo_block = ""
    results = {}
    ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password)))
    ###-------CHECK IF MO EXISTS---------------------------------

    try:
        mo = ucs_handle.query_dn("org-root/boot-policy-" + name)

    except:
        return '{"error":"Could not query children of boot policy"}'

###----if expected state is "present"------------------------

    if state == "present":

        if (mo and (type == "LAN" or type == "LocalLun")):
            if (type == "LAN"):
                lan_query = query_lanmo(ucs_handle, mo, device_name, order)
                local_lun_query = True
            elif (type == "LocalLun"):
                local_lun_query = query_locallunmo(ucs_handle, mo, device_name,
                                                   order)
                lan_query = True
            else:
                print("The type mentioned is not supported by this module.")
            if (mo.name == name and lan_query and local_lun_query):
                results['name'] = name
                results['expected'] = True
                results['changed'] = False
                results['present'] = True

            else:
                try:
                    if (lan_query and ~(local_lun_query)):
                        modified_mo = LsbootStorage(parent_mo_or_dn=mo, )
                        mo_1 = LsbootLocalStorage(
                            parent_mo_or_dn=modified_mo, )
                        mo_1_1 = LsbootLocalHddImage(parent_mo_or_dn=mo_1,
                                                     order=order)
                        mo_1_1_1 = LsbootLocalLunImagePath(
                            parent_mo_or_dn=mo_1_1,
                            lun_name=device_name,
                            type="primary")
                        ucs_handle.add_mo(modified_mo, True)
                        ucs_handle.commit()
                    elif (local_lun_query and ~(lan_query)):
                        modified_mo = LsbootLan(parent_mo_or_dn=mo,
                                                order=order)
                        mo_1_1 = LsbootLanImagePath(
                            parent_mo_or_dn=modified_mo,
                            type="primary",
                            vnic_name=device_name)
                        ucs_handle.add_mo(mo, True)
                        ucs_handle.commit()
                    else:
                        modified_mo = LsbootStorage(parent_mo_or_dn=mo, )
                        mo_1 = LsbootLocalStorage(
                            parent_mo_or_dn=modified_mo, )
                        mo_1_1 = LsbootLocalHddImage(parent_mo_or_dn=mo_1,
                                                     order=order)
                        mo_1_1_1 = LsbootLocalLunImagePath(
                            parent_mo_or_dn=mo_1_1,
                            lun_name=device_name,
                            type="primary")
                        ucs_handle.add_mo(mo, True)
                        ucs_handle.commit()
                        modified_mo = LsbootLan(parent_mo_or_dn=mo,
                                                order=order)
                        mo_1_1 = LsbootLanImagePath(parent_mo_or_dn=mo_1,
                                                    type="primary",
                                                    vnic_name=device_name)
                        ucs_handle.add_mo(mo, True)
                        ucs_handle.commit()
                    results['name'] = name
                    results['present'] = True
                    results['removed'] = False
                    results['changed'] = True

                except Exception, e:
                    return '{"error":"%s" %e}'
        elif (mo and type == ""):
            results['name'] = name
            results['present'] = True
            results['removed'] = False
            results['changed'] = False

###----------if not, create boot policy with desired config ----------------

        else:
            try:

                mo = LsbootPolicy(parent_mo_or_dn="org-root",
                                  name=name,
                                  descr="")
                if (type != ""):
                    if (type == "LAN"):
                        mo_1 = LsbootLan(parent_mo_or_dn=mo, order=order)
                        mo_1_1 = LsbootLanImagePath(parent_mo_or_dn=mo_1,
                                                    type="primary",
                                                    vnic_name=device_name)
                    else:
                        mo_2 = LsbootStorage(parent_mo_or_dn=mo, order=order)
                        mo_2_1 = LsbootLocalStorage(parent_mo_or_dn=mo_2, )
                        mo_2_1_1 = LsbootLocalHddImage(parent_mo_or_dn=mo_2_1,
                                                       order=order)
                        mo_2_1_1_1 = LsbootLocalLunImagePath(
                            parent_mo_or_dn=mo_2_1_1,
                            lun_name=device_name,
                            type="primary")
                ucs_handle.add_mo(mo)
                ucs_handle.commit()
                results['name'] = name
                results['present'] = False
                results['created'] = True
                results['changed'] = True

            except:
                return '{"error":"boot policy creation failed"}'
def sp_create():
    # ###########################################
    # Create the SP that will be associated later
    # ###########################################
    log.debug("sp_create")
    from ucsmsdk.mometa.ls.LsServer import LsServer
    from ucsmsdk.mometa.lsboot.LsbootDef import LsbootDef
    from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage
    from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage
    from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import\
        LsbootDefaultLocalImage
    from ucsmsdk.mometa.vnic.VnicEther import VnicEther
    from ucsmsdk.mometa.vnic.VnicEtherIf import VnicEtherIf
    from ucsmsdk.mometa.vnic.VnicFcNode import VnicFcNode

    mo = LsServer(parent_mo_or_dn="org-root",
                  vmedia_policy_name="",
                  ext_ip_state="none",
                  bios_profile_name="",
                  mgmt_fw_policy_name="",
                  agent_policy_name="",
                  mgmt_access_policy_name="",
                  dynamic_con_policy_name="",
                  kvm_mgmt_policy_name="",
                  sol_policy_name="",
                  uuid="0",
                  descr="",
                  stats_policy_name="default",
                  policy_owner="local",
                  ext_ip_pool_name="ext-mgmt",
                  boot_policy_name="",
                  usr_lbl="",
                  host_fw_policy_name="",
                  vcon_profile_name="",
                  ident_pool_name="",
                  src_templ_name="",
                  local_disk_policy_name="",
                  scrub_policy_name="",
                  power_policy_name="default",
                  maint_policy_name="",
                  name="test_sp",
                  resolve_remote="yes")
    mo_1 = LsbootDef(parent_mo_or_dn=mo,
                     descr="",
                     reboot_on_update="no",
                     adv_boot_order_applicable="no",
                     policy_owner="local",
                     enforce_vnic_name="yes",
                     boot_mode="legacy")
    mo_1_1 = LsbootStorage(parent_mo_or_dn=mo_1, order="1")
    mo_1_1_1 = LsbootLocalStorage(parent_mo_or_dn=mo_1_1, )
    mo_1_1_1_1 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_1_1_1, order="1")
    mo_2 = VnicEther(parent_mo_or_dn=mo,
                     nw_ctrl_policy_name="",
                     name="eth0",
                     admin_host_port="ANY",
                     admin_vcon="any",
                     stats_policy_name="default",
                     admin_cdn_name="",
                     switch_id="A",
                     pin_to_group_name="",
                     mtu="1500",
                     qos_policy_name="",
                     adaptor_profile_name="",
                     ident_pool_name="",
                     order="unspecified",
                     nw_templ_name="",
                     addr="derived")
    mo_2_1 = VnicEtherIf(parent_mo_or_dn=mo_2,
                         default_net="yes",
                         name="default")
    mo_3 = VnicFcNode(parent_mo_or_dn=mo,
                      ident_pool_name="",
                      addr="pool-derived")
    handle.add_mo(mo)
    handle.commit()
Ejemplo n.º 10
0
        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)

        handle.commit()
        ##### End-Of-PythonScript #####

        handle.logout()

    except Exception, err:
        print "Exception:", str(err)
        import traceback, sys
        print '-' * 60
        traceback.print_exc(file=sys.stdout)
        print '-' * 60