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 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 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
def main(): argument_spec = ucs_argument_spec argument_spec.update(name=dict(type='str'), num_drives=dict(type='str', default='1'), num_ded_hot_spares=dict(type='str', default='unspecified'), num_glob_hot_spares=dict(type='str', default='unspecified'), drive_type=dict(type='str', default='unspecified', choice=['unspecified', 'HDD', 'SSD']), use_jbod_disks=dict(type='str', default='no', choice=['yes', 'no']), use_remaining_disks=dict(type='str', default='no', choice=['yes', 'no']), min_drive_size=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.LstorageDiskGroupQualifier import LstorageDiskGroupQualifier num_policies = 1 name_start_index = 0 name_list = module.params['name'].split(',') policy_name_prefix = name_list[0] policy_name = policy_name_prefix if len(name_list) == 3: name_start_index = int(name_list[1]) num_policies = int(name_list[2]) for num in range(name_start_index, name_start_index + num_policies): err = False changed = False mo_exists = False if num_policies > 1: policy_name = policy_name_prefix + str(num) try: dn_base = 'org-root' dn = dn_base + '/disk-group-config-' + policy_name existing_mo = ucs.login_handle.query_dn(dn + '/disk-group-qual') if existing_mo: # check top-level mo props kwargs = dict(num_drives=module.params['num_drives']) kwargs['drive_type'] = module.params['drive_type'] kwargs['use_jbod_disks'] = module.params['use_jbod_disks'] kwargs['use_remaining_disks'] = module.params[ 'use_remaining_disks'] kwargs['num_ded_hot_spares'] = module.params[ 'num_ded_hot_spares'] kwargs['num_glob_hot_spares'] = module.params[ 'num_glob_hot_spares'] kwargs['min_drive_size'] = module.params['min_drive_size'] if existing_mo.check_prop_match(**kwargs): mo_exists = True mo_dg_qual = LstorageDiskGroupQualifier( parent_mo_or_dn=dn, num_drives=module.params['num_drives'], drive_type=module.params['drive_type'], use_jbod_disks=module.params['use_jbod_disks'], 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']) if module.params['state'] == 'absent': if mo_exists: if not module.check_mode: # delete mo if dn already exist ucs.login_handle.remove_mo(mo_dg_qual) ucs.login_handle.commit() 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_dg_qual, True) ucs.login_handle.commit() changed = True 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)