
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ d
Zd Z G d de      Zy)z5Utilities Assured Workloads API, Workloads Endpoints.    )absolute_import)division)unicode_literals)
list_pager)message_util)util)waiter)	resourcesz&Creating Assured Workloads environmentc                 x    t         j                  j                  | j                  d      }|j	                         S )Nz2assuredworkloads.organizations.locations.workloads
collection)r
   REGISTRYParseRelativeNamenameSelfLink)resourceworkloads     /lib/googlecloudsdk/api_lib/assured/workloads.pyGetWorkloadURIr      s8    11mmE 2 ( 
			    c                   J    e Zd ZdZddZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zy)WorkloadsClientz.Client for Workloads in Assured Workloads API.c                     t        j                  ||      | _        t        j                  |      | _        || _        | j                  j                  | _        y )N)r   GetClientInstanceclientGetMessagesModulemessages_release_track!organizations_locations_workloads_service)selfrelease_trackno_https      r   __init__zWorkloadsClient.__init__*   sA    ((@DK**=9DM'DKKAADMr   Nc                     | j                   j                  ||      }t        j                  | j                  |d||d      S )a+  List all Assured Workloads environments belonging to a given parent organization.

    Args:
      parent: str, the parent organization of the Assured Workloads environment
        to be listed, in the form: organizations/{ORG_ID}/locations/{LOCATION}.
      limit: int or None, the total number of results to return.
      page_size: int, the number of entries in each batch (affects requests
        made, but not the yielded results).

    Returns:
      A list of all Assured Workloads environments belonging to a given parent
      organization.
    )parentpageSize	workloadsN)field
batch_sizelimitbatch_size_attribute)r   :AssuredworkloadsOrganizationsLocationsWorkloadsListRequestr   YieldFromListr    )r!   r&   r+   	page_sizelist_reqs        r   ListzWorkloadsClient.List0   sN     }}WW	 X H ##! r   c                     t        j                  |||| j                        }| j                  j                  j                  |      }| j                  |t              S )a  Create a new Assured Workloads environment in the parent organization.

    Args:
      parent: str, the parent organization of the Assured Workloads environment
        to be created, in the form: organizations/{ORG_ID}/locations/{LOCATION}.
      external_id: str, the identifier that identifies this Assured Workloads
        environment externally.
      workload: Workload, new Assured Workloads environment containing the
        values to be used.

    Returns:
      The created Assured Workloads environment resource.
    )r   CreateCreateRequestr   r   r   CreateWaitForOperation%WORKLOAD_CREATION_IN_PROGRESS_MESSAGE)r!   r&   external_idr   
create_reqops         r   r4   zWorkloadsClient.CreateJ   sS     11VXt':':J 
	6	6	=	=j	IB  %JKKr   c                     | j                   j                  ||      }| j                  j                  j	                  |      S )a[  Delete an existing Assured Workloads environment.

    Args:
      name: str, name of the Assured Workloads environtment to be deleted, in
        the form:
        organization/{ORG_ID}/locations/{LOCATION}/workloads/{WORKLOAD_ID}
      etag: str, the etag string acquired by reading the Workload.

    Returns:
      Empty response message.
    )r   etag)r   <AssuredworkloadsOrganizationsLocationsWorkloadsDeleteRequestr   r   Delete)r!   r   r;   
delete_reqs       r   r=   zWorkloadsClient.Delete^   s@     [[ \ J ;;88??
KKr   c                     | j                   j                  |      }| j                  j                  j	                  |      S )a/  Describe an existing Assured Workloads environment.

    Args:
      name: str, the name for the Assured Workloads environment being described
        in the form:
        organizations/{ORG_ID}/locations/{LOCATION}/workloads/{WORKLOAD_ID}.

    Returns:
      Specified Assured Workloads resource.
    r   )r   9AssuredworkloadsOrganizationsLocationsWorkloadsGetRequestr   r   Get)r!   r   describe_reqs      r   DescribezWorkloadsClient.Describeo   sA     	OO 	P 	
 
 ;;88<<\JJr   c                     t        j                  |||| j                        }| j                  j                  j                  |      S )a  Update the configuration values of an existing Assured Workloads environment.

    Args:
      workload: googleCloudAssuredworkloadsV1beta1Workload, new Assured
        Workloads environment containing the new configuration values to be
        used.
      name: str, the name for the Assured Workloads environment being updated in
        the form:
        organizations/{ORG_ID}/locations/{LOCATION}/workloads/{WORKLOAD_ID}.
      update_mask: str, list of the fields to be updated, for example,
        workload.display_name,workload.labels,workload.violation_notifications_enabled

    Returns:
      Updated Assured Workloads environment resource.
    )r   CreateUpdateRequestr   r   r   Patch)r!   r   r   update_mask
update_reqs        r   UpdatezWorkloadsClient.Update   s@    " 11$T%8%8J ;;88>>zJJr   c                     | j                   j                  |      }| j                  j                  j	                  |      S )a)  Enable resource violation monitoring for a workload.

    Args:
      name: str, name of the Assured Workloads for which Resource Monitoring is
        enabled, in the form:
        organization/{ORG_ID}/locations/{LOCATION}/workloads/{WORKLOAD_ID}

    Returns:
      Empty response message.
    r@   )r   NAssuredworkloadsOrganizationsLocationsWorkloadsEnableResourceMonitoringRequestr   r   EnableResourceMonitoring)r!   r   
enable_reqs      r   rM   z(WorkloadsClient.EnableResourceMonitoring   sC     mm n J 	55NN	
r   c                     | j                  |j                        }t        j                  | j                  j
                  | j                  j                        }t        j                  |||      S )aG  Waits for the given google.longrunning.Operation to complete.

    Args:
      operation: The operation to poll.
      progress_message: String to display for default progress_tracker.

    Raises:
      apitools.base.py.HttpError: if the request returns an HTTP error

    Returns:
      The created Environment resource.
    )GetOperationResourcer   r	   CloudOperationPollerr   r   "organizations_locations_operationsWaitFor)r!   	operationprogress_messageoperation_refpollers        r   r5   z WorkloadsClient.WaitForOperation   sX     --inn=M((5566F >>&-1ABBr   c                 D    t         j                  j                  |d      S )Nz3assuredworkloads.organizations.locations.operationsr   )r
   r   r   )r!   r   s     r   rP   z$WorkloadsClient.GetOperationResource   s&    //N 0  r   )F)Nd   )__name__
__module____qualname____doc__r$   r1   r4   r=   rD   rJ   rM   r5   rP    r   r   r   r   '   s8    6B4L(L"K$K,(C(r   r   N)r]   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.assuredr   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.corer
   r6   r   objectr   r^   r   r   <module>re      s>    < &  ' ' 7 / . ) )Q %[f [r   