def get_ovdc(self, ovdc_id): uri = f"{self._ovdc_uri}/{ovdc_id}" response = self.do_request(uri=uri, method=shared_constants.RequestMethod.GET, accept_type='application/json') return common_models.Ovdc(**self.process_response(response))
def get_ovdc(self, ovdc_id): uri = f"{self._ovdc_uri}/{ovdc_id}" response = self._client._do_request_prim( shared_constants.RequestMethod.GET, uri, self._client._session, accept_type='application/json') return common_models.Ovdc(**process_response(response))
def ovdc_update(data, operation_context: ctx.OperationContext): """Request handler for ovdc enable, disable operations. Add or remove the respective cluster placement policies to enable or disable cluster deployment of a certain kind in the OVDC. Required data: k8s_runtime :return: Dictionary with org VDC update task href. """ ovdc_spec = common_models.Ovdc(**data[RequestKey.INPUT_SPEC]) return ovdc_service.update_ovdc(operation_context, ovdc_id=data[RequestKey.OVDC_ID], ovdc_spec=ovdc_spec)
def get_ovdc_k8s_runtime_details( sysadmin_client: vcd_client.Client, ovdc_id=None, ovdc_name=None, org_name=None, cpm: Optional[ compute_policy_manager.ComputePolicyManager] = None, # noqa: E501 log_wire=False) -> common_models.Ovdc: """Get k8s runtime details for an ovdc. At least ovdc_id and ovdc_name or org_name and ovdc_name should be provided. Additional call to get ovdc details can be avoided by providing ovdc_id and ovdc_name. :param vcd_client.Client sysadmin_client: vcd sysadmin client :param str ovdc_id: :param str ovdc_name: :param str org_name: :param compute_policy_manager.ComputePolicyManager cpm: :param bool log_wire: :return: Ovdc object with k8s runtimes :rtype: common_models.Ovdc """ vcd_utils.raise_error_if_user_not_from_system_org(sysadmin_client) if not cpm: cpm = compute_policy_manager.ComputePolicyManager(sysadmin_client, log_wire=log_wire) if not (org_name and ovdc_name) and not ovdc_id: msg = "Unable to fetch OVDC k8 runtime details with the " \ "provided parameters" logger.SERVER_LOGGER.error(msg) raise Exception(msg) if not ovdc_id or not ovdc_name: # populate ovdc_id and ovdc_name ovdc = vcd_utils.get_vdc(client=sysadmin_client, vdc_id=ovdc_id, vdc_name=ovdc_name, org_name=org_name, is_admin_operation=True) ovdc_id = vcd_utils.extract_id(ovdc.get_resource().get('id')) ovdc_name = ovdc.get_resource().get('name') policies = [] for cse_policy in \ compute_policy_manager.list_cse_placement_policies_on_vdc(cpm, ovdc_id): # noqa: E501 policies.append(RUNTIME_INTERNAL_NAME_TO_DISPLAY_NAME_MAP[ cse_policy['display_name']]) # noqa: E501 return common_models.Ovdc(ovdc_name=ovdc_name, ovdc_id=ovdc_id, k8s_runtime=policies) # noqa: E501
def update_ovdc(self, ovdc_name, k8s_runtime, enable=True, org_name=None, remove_cp_from_vms_on_disable=False): """Enable/Disable ovdc for k8s for the given k8s provider. :param str ovdc_name: Name of org VDC to update :param List[str] k8s_runtime: k8s_runtime of the k8s provider to enable / disable for the ovdc :param bool enable: If set to True will enable the vdc for the paricular k8s_runtime else if set to False, K8 support on the vdc will be disabled. :param str org_name: Name of org that @ovdc_name belongs to :param bool remove_cp_from_vms_on_disable: If set to True and enable is False, then all the vms in the ovdc having policies for the k8s_runtime is deleted. :rtype: dict """ ovdc = get_vdc(self.client, vdc_name=ovdc_name, org_name=org_name, is_admin_operation=True) ovdc_id = utils.extract_id(ovdc.get_resource().get('id')) curr_ovdc = self._ovdc_api.get_ovdc(ovdc_id) runtimes = curr_ovdc.k8s_runtime for k in k8s_runtime: if enable: if k in runtimes: raise Exception( f"OVDC {ovdc_name} already enabled for {k8s_runtime}" ) # noqa: E501 runtimes.append(k) else: if k not in runtimes: raise Exception( f"OVDC {ovdc_name} already disabled for {k8s_runtime}" ) # noqa: E501 runtimes.remove(k) updated_ovdc = common_models.Ovdc( k8s_runtime=runtimes, org_name=org_name, remove_cp_from_vms_on_disable=remove_cp_from_vms_on_disable) return self._ovdc_api.update_ovdc(ovdc_id, updated_ovdc)