
                             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  G d	 d
e      Z G d de      Z G d de      Zy)zNCommands for interacting with the Cloud NetApp Files Quota Rules API resource.    )
list_pager)	constants)util)waiter)base)log)	resourcesc                       e Zd ZdZej
                  j                  fdZed        Z	ed        Z
d Zd Z	 	 	 	 	 	 ddZdd	Zd
 Zd Z	 	 	 ddZd Zy)QuotaRulesClientzMWrapper for working with Quota Rules in the Cloud NetApp Files API Client.
  c                 B   || _         | j                   t        j                  j                  k(  rt	               | _        y | j                   t        j                  j                  k(  rt               | _        y t        dj                  t        j                  |               )Nz [{}] is not a valid API version.)release_trackr   ReleaseTrackBETABetaQuotaRulesAdapter_adapterGAQuotaRulesAdapter
ValueErrorformatnetapp_api_utilVERSION_MAP)selfr   s     ?lib/googlecloudsdk/api_lib/netapp/volumes/quota_rules/client.py__init__zQuotaRulesClient.__init__   s{    &DT..333+-dm			t0033	3')dm9@@

%
%m
46 7 7    c                 .    | j                   j                  S N)r   clientr   s    r   r   zQuotaRulesClient.client)   s    ==r   c                 .    | j                   j                  S r   )r   messagesr   s    r   r!   zQuotaRulesClient.messages-   s    ==!!!r   c                     t        j                  t        j                  | j                  j                        |dj                  |j                                     S )a  Waits on the long-running operation until the done field is True.

    Args:
      operation_ref: the operation reference.

    Raises:
      waiter.OperationError: if the operation contains an error.

    Returns:
      the 'response' field of the Operation.
    zWaiting for [{0}] to finish)r   WaitForCloudOperationPollerNoResourcesr   projects_locations_operationsr   Name)r   operation_refs     r   WaitForOperationz!QuotaRulesClient.WaitForOperation1   sL     >>..KK55	78E%,,]-?-?-ABD Dr   c                 @   | j                   j                  ||j                         |      }| j                  j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )z(Create a Cloud NetApp Volume Quota Rule.)parentquotaRuleId	quotaRule
collection)r!   5NetappProjectsLocationsVolumesQuotaRulesCreateRequestr&   r   %projects_locations_volumes_quotaRulesCreater	   REGISTRYParseRelativeNamenamer   OPERATIONS_COLLECTIONr(   )r   quota_rule_ref
volume_refasync_configrequest	create_opr'   s           r   CreateQuotaRulez QuotaRulesClient.CreateQuotaRuleB   s     	KK&++- 	L 	
  AAHHI &&889#B#B 9 M   //r   Nc                     | j                   j                         }||_        ||_        ||_        ||_        ||_        ||_        |S )zFParses the command line arguments for Create Quota Rule into a config.)r!   	QuotaRuler4   typetargetdiskLimitMibdescriptionlabels)r   r4   quota_rule_typer@   disk_limit_mibrB   rC   
quota_rules           r   ParseQuotaRuleConfigz%QuotaRulesClient.ParseQuotaRuleConfigU   sJ     ((*JJO%JOJ,J(JJr   c                 f   | j                   j                  |      }| j                  j                  j	                  |      }|j
                  D ]&  }t        j                  dj                  |             ( t        j                  | j                  j                  |t        j                  |d      S )ao  List Cloud NetApp Volume Quota Rules.

    Args:
      volume_ref: The parent Volume to list Cloud Netapp Volume QuotaRules.
      limit: The number of Cloud Netapp Volume QuotaRules to limit the results
        to. This limit is passed to the server and the server does the limiting.

    Returns:
      Generator that yields the Cloud Netapp Volume QuotaRules.
    )r*   zLocation {} may be unreachable.pageSize)fieldlimitbatch_size_attribute)r!   3NetappProjectsLocationsVolumesQuotaRulesListRequestr   r0   Listunreachabler   warningr   r   YieldFromListr   QUOTA_RULE_RESOURCE)r   r7   rK   r:   responselocations         r   ListQuotaRuleszQuotaRulesClient.ListQuotaRulesh   s     mmOO P G {{@@EEgNH((	kk3::8DE )##99++' r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z%Get a Cloud NetApp Volume Quota Rule.r4   )r!   2NetappProjectsLocationsVolumesQuotaRulesGetRequestRelativeNamer   r0   Get)r   r6   r:   s      r   GetQuotaRulezQuotaRulesClient.GetQuotaRule   sE    mmNN((* O G ;;<<@@IIr   c                 <   | j                   j                  |j                               }| j                  j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )z(Delete a Cloud NetApp Volume Quota Rule.rW   r-   )r!   5NetappProjectsLocationsVolumesQuotaRulesDeleteRequestrY   r   r0   Deleter	   r2   r3   r4   r   r5   r(   )r   r6   r8   r:   	delete_opr'   s         r   DeleteQuotaRulez QuotaRulesClient.DeleteQuotaRule   s     	KK,,. 	L 	
 
 AAHHI &&889#B#B 9 M   //r   c                 <    |||_         |||_        |||_        |S )aG  Parses updates into a quota rule config.

    Args:
      quota_rule_config: The quota rule config to update.
      disk_limit_mib: int, a new disk limit, if any.
      description: str, a new description, if any.
      labels: LabelsValue message, the new labels value, if any.

    Returns:
      The quota rule message.
    )rA   rB   rC   )r   quota_rule_configrE   rB   rC   s        r   ParseUpdatedQuotaRuleConfigz,QuotaRulesClient.ParseUpdatedQuotaRuleConfig   s7    $ !'5$&1#!'r   c                 @   | j                   j                  |j                         ||      }| j                  j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )ae  Updates a Cloud NetApp Volume Quota Rule.

    Args:
      quota_rule_ref: the reference to the Quota Rule.
      quota_rule: Quota rule config, the updated quota rule.
      update_mask: str, a comma-separated list of updated fields.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Volume message.
    )r4   
updateMaskr,   r-   )r!   4NetappProjectsLocationsVolumesQuotaRulesPatchRequestrY   r   r0   Patchr	   r2   r3   r4   r   r5   r(   )r   r6   rF   update_maskr8   r:   	update_opr'   s           r   UpdateQuotaRulez QuotaRulesClient.UpdateQuotaRule   s     	JJ,,."  	K 	
  AAGGPI&&889#B#B 9 DM  //r   )NNNNNNr   )NNN)__name__
__module____qualname____doc__r   r   r   r   propertyr   r!   r(   r<   rG   rU   r[   r`   rc   rj    r   r   r   r      s     $(#4#4#9#9 7     " "D"0* &4J0( 40r   r   c                       e Zd ZdZd Zy)r   z;Adapter for the Cloud NetApp Files API Quota Rule resource.c                     t         j                  j                  | _        t	        j
                  | j                        | _        t	        j                  | j                        | _        y N)r   )	r   r   r   r   r   GetClientInstancer   GetMessagesModuler!   r   s    r   r   zQuotaRulesAdapter.__init__   sN    **--D!33((DK $55((DMr   N)rk   rl   rm   rn   r   rp   r   r   r   r      s
    Cr   r   c                   "     e Zd ZdZ fdZ xZS )r   z@Adapter for the Beta Cloud NetApp Files API Quota Rule resource.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y rs   )superr   r   r   r   r   r   r   rt   r   ru   r!   )r   	__class__s    r   r   zBetaQuotaRulesAdapter.__init__   s]    	
/1**//D!33((DK $55((DMr   )rk   rl   rm   rn   r   __classcell__)ry   s   @r   r   r      s    H r   r   N)rn   apitools.base.pyr   googlecloudsdk.api_lib.netappr   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer   r	   objectr   r   r   rp   r   r   <module>r      sH     U ' 3 A . ( # )q0v q0h
 
- r   