Пример #1
0
def configure_disk_policy(ucs, module, dn):
    from ucsmsdk.mometa.lstorage.LstorageDiskGroupConfigPolicy import LstorageDiskGroupConfigPolicy
    from ucsmsdk.mometa.lstorage.LstorageDiskGroupQualifier import LstorageDiskGroupQualifier
    from ucsmsdk.mometa.lstorage.LstorageLocalDiskConfigRef import LstorageLocalDiskConfigRef

    if not module.check_mode:
        try:
            # create if mo does not already exist
            mo = LstorageDiskGroupConfigPolicy(
                parent_mo_or_dn=module.params['org_dn'],
                name=module.params['name'],
                descr=module.params['description'],
                raid_level=module.params['raid_level'],
            )
            if module.params['configuration_mode'] == 'automatic':
                LstorageDiskGroupQualifier(
                    parent_mo_or_dn=mo,
                    num_drives=module.params['num_drives'],
                    drive_type=module.params['drive_type'],
                    use_remaining_disks=module.params['use_remaining_disks'],
                    num_ded_hot_spares=module.params['num_ded_hot_spares'],
                    num_glob_hot_spares=module.params['num_glob_hot_spares'],
                    min_drive_size=module.params['min_drive_size'],
                )
            else:  # configuration_mode == 'manual'
                for disk in module.params['manual_disks']:
                    if disk['state'] == 'absent':
                        child_dn = dn + '/slot-' + disk['slot_num']
                        mo_1 = ucs.login_handle.query_dn(child_dn)
                        if mo_1:
                            ucs.login_handle.remove_mo(mo_1)
                    else:  # state == 'present'
                        LstorageLocalDiskConfigRef(
                            parent_mo_or_dn=mo,
                            slot_num=disk['slot_num'],
                            role=disk['role'],
                            span_id=disk['span_id'],
                        )

            if module.params['virtual_drive']:
                _configure_virtual_drive(module, mo)

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

    ucs.result['changed'] = True
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
Пример #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
Пример #4
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
def main():
    argument_spec = ucs_argument_spec
    argument_spec.update(name=dict(type='str'),
                         disk_list=dict(type='list'),
                         slot_num=dict(type='str'),
                         role=dict(type='str', default='normal'),
                         span_id=dict(type='str', default='unspecified'), 
                         state=dict(type='str', default='present', choices=['present', 'absent'])) 

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

    from ucsmsdk.mometa.lstorage.LstorageLocalDiskConfigRef import LstorageLocalDiskConfigRef 
    err = False
    changed = False
    mo_exists = False

    try:
        if module.params['disk_list']:
            # directly use the list (single resource and list are mutually exclusive
            disk_list = module.params['disk_list']
        else:
            # single resource specified, create list from the current params
            disk_list = [module.params]

        for disk in disk_list:

            mo_exists = False
            commit = False

            if not disk.get('span_id'):
                disk['span_id'] = "unspecified" 

            if not disk.get('role'):
                disk['role'] = 'normal'

            dn_base = 'org-root' 
            dn = dn_base + '/disk-group-config-' + module.params['name'] 
      
            disk_mo = ucs.login_handle.query_dn(dn + '/slot-' + disk['slot_num'])
            if disk_mo:
                # check top-level mo props
                kwargs = dict(slot_num = disk['slot_num'])
                kwargs['role'] = disk['role']
                kwargs['span_id'] = disk['span_id']
                if disk_mo.check_prop_match(**kwargs):
                    mo_exists = True
        
            mo = LstorageLocalDiskConfigRef(parent_mo_or_dn=dn,
                                            slot_num=disk['slot_num'],
                                            role=disk['role'],
                                            span_id=disk['span_id'])

            if module.params['state'] == 'absent':
                if mo_exists:
                    if not module.check_mode:
                        # delete mo if dn already exists 
                        ucs.login_handle.remove_mo(mo)
                        commit = True
                    changed = True               
            else:
                if not mo_exists:
                    if not module.check_mode:
                        # create mo if dn does not already exist
                        ucs.login_handle.add_mo(mo)
                        commit = True
                    changed = True

        if commit:
            ucs.login_handle.commit()

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

    ucs.result['changed'] = changed
    if err:
        module.fail_json(**ucs.result)
    module.exit_json(**ucs.result)