def _follow_task(op_ctx: ctx.OperationContext, task_href: str, ovdc_id: str): try: task = vcd_task.Task(client=op_ctx.sysadmin_client) session = op_ctx.sysadmin_client.get_vcloud_session() vdc = vcd_utils.get_vdc(op_ctx.sysadmin_client, vdc_id=ovdc_id) org = vcd_utils.get_org(op_ctx.sysadmin_client) user_name = session.get('user') user_href = org.get_user(user_name).get('href') msg = "Remove ovdc compute policy" # TODO(pyvcloud): Add method to retireve task from task href t = task.update(status=vcd_task.TaskStatus.RUNNING.value, namespace='vcloud.cse', operation=msg, operation_name=msg, details='', progress=None, owner_href=vdc.href, owner_name=vdc.name, owner_type=vcd_client.EntityType.VDC.value, user_href=user_href, user_name=user_name, org_href=op_ctx.user.org_href, task_href=task_href) op_ctx.sysadmin_client.get_task_monitor().wait_for_status(t) except Exception as err: logger.SERVER_LOGGER.error(f"{err}") finally: if op_ctx.sysadmin_client: op_ctx.end()
def update_ovdc(operation_context: ctx.OperationContext, ovdc_id: str, ovdc_spec: common_models.Ovdc) -> dict: # noqa: 501 """Update ovdc with the updated k8s runtimes list. :param ctx.OperationContext operation_context: context for the request :param common_models.Ovdc ovdc_spec: Ovdc object having the updated k8s runtime list :return: dictionary containing the task href for the update operation :rtype: dict """ # NOTE: For CSE 3.0, if `enable_tkg_plus` flag in config is set to false, # Prevent enable/disable of OVDC for TKG+ k8s runtime by throwing an # exception msg = "Updating OVDC placement policies" task = vcd_task.Task(operation_context.sysadmin_client) org = vcd_utils.get_org(operation_context.client) user_href = org.get_user(operation_context.user.name).get('href') vdc = vcd_utils.get_vdc(operation_context.sysadmin_client, vdc_id=ovdc_id, # noqa: E501 is_admin_operation=True) logger.SERVER_LOGGER.debug(msg) task_resource = task.update( status=vcd_client.TaskStatus.RUNNING.value, namespace='vcloud.cse', operation=msg, operation_name='OVDC Update', details='', progress=None, owner_href=vdc.href, owner_name=vdc.name, owner_type=vcd_client.EntityType.VDC.value, user_href=user_href, user_name=operation_context.user.name, org_href=operation_context.user.org_href, task_href=None, error_message=None, stack_trace=None) task_href = task_resource.get('href') operation_context.is_async = True # NOTE: Telemetry is currently handled in the async function as it is not # possible to know the operation (enable/disable) without comparing it to # current k8s runtimes. if ClusterEntityKind.TKG_PLUS.value in ovdc_spec.k8s_runtime and \ not server_utils.is_tkg_plus_enabled(): msg = "TKG+ is not enabled on CSE server. Please enable TKG+ in the " \ "server and try again." logger.SERVER_LOGGER.debug(msg) raise Exception(msg) policy_list = [RUNTIME_DISPLAY_NAME_TO_INTERNAL_NAME_MAP[p] for p in ovdc_spec.k8s_runtime] # noqa: E501 _update_ovdc_using_placement_policy_async(operation_context=operation_context, # noqa:E501 task=task, task_href=task_href, user_href=user_href, policy_list=policy_list, # noqa:E501 ovdc_id=ovdc_id, vdc=vdc, org_name=ovdc_spec.org_name, remove_cp_from_vms_on_disable=ovdc_spec.remove_cp_from_vms_on_disable) # noqa:E501 return {'task_href': task_href}