Exemple #1
0
def createDiskGroupConfig(handle, org):
    print "Adding Disk Group Config"
    from ucsmsdk.mometa.lstorage.LstorageDiskGroupConfigPolicy import LstorageDiskGroupConfigPolicy
    from ucsmsdk.mometa.lstorage.LstorageDiskGroupQualifier import LstorageDiskGroupQualifier
    from ucsmsdk.mometa.lstorage.LstorageVirtualDriveDef import LstorageVirtualDriveDef
    mo = LstorageDiskGroupConfigPolicy(parent_mo_or_dn=org, 
        policy_owner="local",
        name="kube_boot",
        descr="Kubernetes Boot Disk",
        raid_level="mirror")
    mo_1 = LstorageDiskGroupQualifier(parent_mo_or_dn=mo, 
        use_remaining_disks="no",
        num_ded_hot_spares="unspecified",
        drive_type="unspecified",
        num_drives="2",
        min_drive_size="unspecified",
        num_glob_hot_spares="unspecified")
    mo_2 = LstorageVirtualDriveDef(parent_mo_or_dn=mo, read_policy="platform-default",
        drive_cache="platform-default",
        strip_size="platform-default",
        io_policy="platform-default",
        write_cache_policy="platform-default",
        access_policy="platform-default")
    handle.add_mo(mo, 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, ""
def setup_disk_group_policy(server, module):
    from ucsmsdk.mometa.lstorage.LstorageDiskGroupConfigPolicy import LstorageDiskGroupConfigPolicy
    from ucsmsdk.mometa.lstorage.LstorageVirtualDriveDef import LstorageVirtualDriveDef
    from ucsmsdk.mometa.lstorage.LstorageLocalDiskConfigRef import LstorageLocalDiskConfigRef
   
    ansible = module.params
    args_mo  =  _get_mo_params(ansible)

    changed = False

    for dg in args_mo['disk_group_policy_list']:
        mo = server.query_dn(args_mo['org_dn']+'/disk-group-config-'+dg['name'])
        if mo:
            exists = True
        else:
            exists = False

        if ansible['state'] == 'absent':
            if exists:
                changed = True
                if not module.check_mode:
                    server.remove_mo(mo)
                    server.commit()
        else:
            if not exists:
                changed = True
                if not module.check_mode:
                    # create if mo does not already exist
                    mo = LstorageDiskGroupConfigPolicy(parent_mo_or_dn=args_mo['org_dn'],
                                                       raid_level=dg['RAID_level'],
				                       name=dg['name'])
                    mo_1 = LstorageVirtualDriveDef(parent_mo_or_dn=mo,
                                                   read_policy='platform-default',
				                   drive_cache='platform-default',
                                                   strip_size='platform-default',
				                   io_policy='platform-default',
				                   write_cache_policy='platform-default',
                                                   access_policy='platform-default')
                    if(len(dg['disk_slot_numbers']) > 0):
                        for slot_num in dg['disk_slot_numbers']:
                            mo_2 = LstorageLocalDiskConfigRef(parent_mo_or_dn=mo,
	                                                      slot_num=slot_num)
                    server.add_mo(mo, True)
                    server.commit()
    
    return changed
Exemple #3
0
    def push_object(self, commit=True):
        if commit:
            self.logger(message="Pushing " + self._CONFIG_NAME + " configuration: " + str(self.name))
        else:
            self.logger(message="Adding to the handle " + self._CONFIG_NAME + " configuration: " + str(self.name) +
                                ", waiting for a commit")

        if hasattr(self._parent, '_dn'):
            parent_mo = self._parent._dn
        else:
            self.logger(level="error", message="Impossible to find the parent dn of " + self._CONFIG_NAME + " : "
                                               + str(self.name))
            return False

        mo_lstorage_disk_group_config_policy = LstorageDiskGroupConfigPolicy(parent_mo_or_dn=parent_mo, name=self.name,
                                                                             raid_level=self.raid_level,
                                                                             descr=self.descr)
        LstorageVirtualDriveDef(parent_mo_or_dn=mo_lstorage_disk_group_config_policy,
                                write_cache_policy=self.write_cache_policy, io_policy=self.io_policy,
                                security=self.security, read_policy=self.read_policy, strip_size=self.strip_size,
                                access_policy=self.access_policy, drive_cache=self.drive_cache)

        if len(self.manual_disk_group_configuration):
            for disk in self.manual_disk_group_configuration:
                role = disk["role"]
                if role == "dedicated-hot-spare":
                    role = "ded-hot-spare"
                elif role == "global-hot-spare":
                    role = "glob-hot-spare"

                LstorageLocalDiskConfigRef(parent_mo_or_dn=mo_lstorage_disk_group_config_policy,
                                           slot_num=disk['slot_number'], role=role, span_id=disk['span_id'])
        else:
            LstorageDiskGroupQualifier(parent_mo_or_dn=mo_lstorage_disk_group_config_policy, drive_type=self.drive_type,
                                       num_glob_hot_spares=self.number_of_global_hot_spares,
                                       num_ded_hot_spares=self.number_of_dedicated_hot_spares,
                                       use_remaining_disks=self.use_remaining_disks, use_jbod_disks=self.use_jbod_disks,
                                       min_drive_size=self.min_drive_size, num_drives=self.number_of_drives)

        self._handle.add_mo(mo=mo_lstorage_disk_group_config_policy, modify_present=True)

        if commit:
            if self.commit(detail=self.name) != True:
                return False
        return True
Exemple #4
0
    def push_object(self, commit=True):
        if commit:
            self.logger(message="Pushing " + self._CONFIG_NAME + " configuration: " + str(self.name))
        else:
            self.logger(message="Adding to the handle " + self._CONFIG_NAME + " configuration: " + str(self.name) +
                                ", waiting for a commit")

        if hasattr(self._parent, '_dn'):
            parent_mo = self._parent._dn
        else:
            self.logger(level="error", message="Impossible to find the parent dn of " + self._CONFIG_NAME + " : " +
                                               str(self.name))
            return False

        mo_lstorage_profile = LstorageProfile(parent_mo_or_dn=parent_mo, name=self.name, descr=self.descr)
        if self.security_policy:
            mo_security = LstorageSecurity(parent_mo_or_dn=mo_lstorage_profile)
            mo_drive_security = LstorageDriveSecurity(parent_mo_or_dn=mo_security)
            for policy in self.security_policy:
                if policy["type"] == "remote_policy":
                    mo_remote = LstorageRemote(parent_mo_or_dn=mo_drive_security,
                                               primary_server=policy['primary_ip_address'],
                                               port=policy['port'],
                                               secondary_server=policy['secondary_ip_address'],
                                               server_cert=policy['kmip_server_public_certificate'],
                                               deployed_security_key=policy['deployed_key'])
                    LstorageLogin(parent_mo_or_dn=mo_remote,
                                  user_name=policy['username'],
                                  password=policy['password'])
                elif policy["type"] == "local_policy":
                    LstorageLocal(parent_mo_or_dn=mo_drive_security,
                                  security_key=policy["key"])
                                  # deployed_security_key=policy['deployed_key']
        if self.local_luns:
            for local_lun in self.local_luns:
                LstorageDasScsiLun(parent_mo_or_dn=mo_lstorage_profile, fractional_size=local_lun['fractional_size'],
                                   expand_to_avail=local_lun['expand_to_available'],
                                   local_disk_policy_name=local_lun['disk_group_policy'], size=local_lun['size'],
                                   name=local_lun['name'],
                                   auto_deploy=local_lun['auto_deploy'])
        if self.controller_definitions:
            for controller_definition in self.controller_definitions:
                mo_controller_def = LstorageControllerDef(parent_mo_or_dn=mo_lstorage_profile,
                                                          name=controller_definition['name'])
                LstorageControllerModeConfig(parent_mo_or_dn=mo_controller_def,
                                             protect_config=controller_definition['protected_configuration'],
                                             raid_mode=controller_definition['raid_level'])

        if self.lun_sets:
            for lun_set in self.lun_sets:
                mo_ls_storage_lun_set_config = LstorageLunSetConfig(parent_mo_or_dn=mo_lstorage_profile,
                                                                    disk_slot_range=lun_set['disk_slot_range'],
                                                                    name=lun_set['name'])
                LstorageVirtualDriveDef(parent_mo_or_dn=mo_ls_storage_lun_set_config,
                                        access_policy=lun_set['access_policy'],
                                        drive_cache=lun_set['drive_cache'],
                                        io_policy=lun_set['io_policy'],
                                        read_policy=lun_set['read_policy'],
                                        security=lun_set['security'],
                                        strip_size=lun_set['strip_size'],
                                        write_cache_policy=lun_set['write_cache_policy'])

        self._handle.add_mo(mo=mo_lstorage_profile, modify_present=True)

        if commit:
            if self.commit(detail=self.name) != True:
                return False
        return True
def _configure_virtual_drive(module, mo):
    from ucsmsdk.mometa.lstorage.LstorageVirtualDriveDef import LstorageVirtualDriveDef
    LstorageVirtualDriveDef(parent_mo_or_dn=mo,
                            **module.params['virtual_drive'])
Exemple #6
0
def disk_group_policy(input):
    name = input['name']
    raid_level = input['raid_level']
    slot_numbers = input['slot_numbers']
    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/disk-group-config-" + name)
        mo_block = ucs_handle.query_children(
            in_dn="org-root/disk-group-config-" + name,
            class_id="lstorageLocalDiskConfigRef")
    except:
        print("Could not query children of disk group policy")

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

    if state == "present":
        if mo:
            slot_numbers_exist = False
            current_slot_numbers = []
            for obj in mo_block:
                current_slot_numbers.append(obj.slot_num)
            if (collections.Counter(slot_numbers) == collections.Counter(
                    current_slot_numbers)):
                slot_numbers_exist = True
            if (mo.raid_level == raid_level and slot_numbers_exist):

                results['name'] = name
                results['expected'] = True
                results['changed'] = False
                results['present'] = True
            else:
                for slot_num in slot_numbers:
                    query_slot = ucs_handle.query_dn(
                        "org-root/disk-group-config-" + name + "/slot-" +
                        slot_num)
                    if (query_slot == None):
                        mo_2 = LstorageLocalDiskConfigRef(parent_mo_or_dn=mo,
                                                          slot_num=slot_num)
                        ucs_handle.add_mo(mo, True)
                        ucs_handle.commit()
                mo = LstorageDiskGroupConfigPolicy(parent_mo_or_dn="org-root",
                                                   raid_level=raid_level,
                                                   name=name)
                ucs_handle.add_mo(mo, True)
                ucs_handle.commit()
                results['name'] = name
                results['expected'] = True
                results['changed'] = True
                results['present'] = True
###----------if not, create boot policy with desired config ----------------

        else:
            try:
                mo = LstorageDiskGroupConfigPolicy(parent_mo_or_dn="org-root",
                                                   raid_level=raid_level,
                                                   name=name)
                mo_1 = LstorageVirtualDriveDef(
                    parent_mo_or_dn=mo,
                    read_policy="platform-default",
                    drive_cache="platform-default",
                    strip_size="platform-default",
                    io_policy="platform-default",
                    write_cache_policy="platform-default",
                    access_policy="platform-default")
                if (len(slot_numbers) > 0):
                    for slot_num in slot_numbers:
                        mo_2 = LstorageLocalDiskConfigRef(parent_mo_or_dn=mo,
                                                          slot_num=slot_num)
                ucs_handle.add_mo(mo)
                ucs_handle.commit()
                results['name'] = name
                results['present'] = False
                results['created'] = True
                results['changed'] = True

            except Exception as e:
                print("disk group configuration policy  creation failed " +
                      str(e))


###------if expected state is "absent"----------------------------

    if state == "absent":

        if mo:

            try:
                ucs_handle.remove_mo(mo)
                results['name'] = name
                results['present'] = False
                results['removed'] = True
                ucs_handle.commit()

            except:
                print("Removal Mac-pool mo failed")

        else:
            results['name'] = name
            results['removed'] = False
            results['present'] = False
    ucs_handle = pickle.dumps(ucs_handle)
    ucs_logout.main(ucs_handle)
    return results