
    +                     ^    S r SSKrSSKJr  SSKJr  SSKJr   " S S\R                  5      r	g)Cloud Backup Plans client.    N)util)
exceptionsc                   V   ^  \ rS rSrSrU 4S jrS rS rS r SS jr	S r
S	 rS
rU =r$ )BackupPlansClient   r   c                 `   > [         [        U ]  5         U R                  R                  U l        g N)superr   __init__clientprojects_locations_backupPlansservice)self	__class__s    3lib/googlecloudsdk/api_lib/backupdr/backup_plans.pyr   BackupPlansClient.__init__   s"    	
T+-;;==DL    c                    / nUc  / $ U GH  nU R                   R                  5       nSU;  a  SOUS   Ul        U R                   R                  US   US   S9Ul        U R                   R                  R                  US   5      Ul        SU;   a
  US   Ul        SU;   a>  US    Vs/ s H(  nU R                   R                  R                  U5      PM*     snUl	        S	U;   a  US	   R                  S
5      nU R                   R                  U R                   R                  R                  US   5      U R                   R                  R                  US   5      S9Ul        SU;   a
  US   Ul        SU;   a>  US    Vs/ s H(  nU R                   R                  R!                  U5      PM*     snUl        U R                   R%                  US   US   US9nUR'                  U5        GM     U$ s  snf s  snf )Nz	time-zoneUTCzbackup-window-startzbackup-window-end)startHourOfDayendHourOfDay
recurrencezhourly-frequencyzdays-of-weekzweek-day-of-month-r      )weekOfMonth	dayOfWeekzdays-of-monthmonthsrule-idzretention-days)ruleIdbackupRetentionDaysstandardSchedule)messagesStandardScheduletimeZoneBackupWindowbackupWindowRecurrenceTypeValueValuesEnumrecurrenceTypehourlyFrequency"DaysOfWeekValueListEntryValuesEnum
daysOfWeeksplitWeekDayOfMonthWeekOfMonthValueValuesEnumDayOfWeekValueValuesEnumweekDayOfMonthdaysOfMonthMonthsValueListEntryValuesEnumr   
BackupRuleappend)	r   backup_rulesbackup_rules_messagebackup_rulestandard_scheduledayweek_day_of_monthmonthbackup_rule_messages	            r   _ParseBackupRules#BackupPlansClient._ParseBackupRules"   s=   i#--88:k1%{;7O   (,}}'A'A$%:;"#67 (B ($
 --
(
(
F
F,' &
 
{	*,78J,K)	;	&
 #>2	(
 3 MM**MM 3	(
$ 
	+'(;<BB3G+/==+G+G44OO!!$ mm22KK!!$	 ,H ,
( 
K	'(3O(D%	[	  %X.$
. MM**II%P.$
  !MM44Y')*:;, 5 
 !!"56[ $\  ;(
&$
s   )/G2/G7c
                    UR                  5       R                  5       n
UR                  5       nSnU(       aq  U R                  R                  R                  UR                  5        VVs/ s H2  u  pU R                  R                  R
                  R                  XS9PM4     snnS9nSnU	(       a)  U R                  R                  U	R                  SS5      S9nU R                  R	                  UUUUU R                  U5      UUb  [        U5      OSUS9nU R                  R                  U
UUS9nU R                  R                  U5      $ s  snnf )	aA  Creates a Backup Plan.

Args:
  resource: The Backup Plan resource.
  backup_vault: The Backup Vault resource.
  resource_type: The resource type of the Backup Plan.
  backup_rules: The backup rules of the Backup Plan.
  log_retention_days: The log retention days of the Backup Plan.
  description: The description of the Backup Plan.
  labels: The labels of the Backup Plan.
  max_custom_on_demand_retention_days: The custom on demand retention days
    limit of the Backup Plan.
  disk_properties: The disk properties of the Backup Plan.

Returns:
  The created Backup Plan.
N)keyvalue)additionalPropertiesguest-flushF
guestFlush)resourceTypebackupVaultdescriptionlabelsbackupRuleslogRetentionDaysmaxCustomOnDemandRetentionDaysdiskBackupPlanProperties)parent
backupPlanbackupPlanId)ParentRelativeNameNamer#   
BackupPlanLabelsValueitemsAdditionalPropertyDiskBackupPlanPropertiesgetr>   int1BackupdrProjectsLocationsBackupPlansCreateRequestr   Create)r   resourcebackup_vaultresource_typer6   log_retention_daysrI   rJ   #max_custom_on_demand_retention_daysdisk_propertiesrO   backup_plan_idlabels_messagerA   rB   disk_props_messagebackup_planrequests                     r   r]   BackupPlansClient.CreateV   sa   : __++-F]]_NN}}//;;
 !'	  !/*# mm&&22EE F  !/	  < n ==AA$((> B  --**" **<8+ 3> 34!3 + K mmMM# N G
 <<w''C s   *9E
c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )zmDescribes a Backup Plan.

Args:
  resource: The Backup Plan resource.

Returns:
  The described Backup Plan.
name)r#   .BackupdrProjectsLocationsBackupPlansGetRequestrS   r   Getr   r^   rh   s      r   DescribeBackupPlansClient.Describe   sA     mmJJ""$ K G <<G$$r   c
           	        ^ Uc  [        S5      eU R                  R                  UR                  S9n
Ub  Xl        Ub  Xzl        Ub  [        U5      U
l        UR                   Vs1 s H  oR                  iM     snmUb  U R                  U5      U
l        U
$ UGb?  [        R                  " U Vs/ s H  oS   PM	     sn5      nUR                  5        VVs/ s H  u  pUS:  d  M  UPM     nnnU(       a  [        R                  " SSU S35      e[!        [#        U Vs/ s H  nUS   T;  d  M  US   PM     sn5      5      nU(       a  [        R                  " SSU S35      eU Vs/ s H  oS   PM	     nnUR                   Vs/ s H  nUR                  U;  d  M  UPM     snU
l        U
R                  R%                  U R                  U5      5        OUR                  U
l        Ub*  U
R                  R%                  U R                  U5      5        Ubt  [!        [#        U4S jU 5       5      5      nU(       a  [        R                  " SSU S	35      eU
R                   Vs/ s H  nUR                  U;  d  M  UPM     snU
l        U	b-  U R                  R'                  U	R)                  S
5      S9U
l        U
$ s  snf s  snf s  snnf s  snf s  snf s  snf s  snf )a[  Parses the update request for a Backup Plan.

Args:
  description: The description of the Backup Plan.
  new_backup_rules_from_file: The backup rules to update from file in the
    Backup Plan.
  update_backup_rules: The backup rules to update in the Backup Plan.
  add_backup_rules: The backup rules to add to the Backup Plan.
  remove_backup_rules: The backup rules to remove from the Backup Plan.
  current_backup_plan: The current Backup Plan.
  log_retention_days: The log retention days of the Backup Plan.
  max_custom_on_demand_retention_days: The custom on demand retention days
    limit of the Backup Plan.
  disk_properties: A dictionary containing the disk properties of the
    Backup Plan.

Returns:
  The updated Backup Plan.

Raises:
  InvalidArgumentException: If the backup rules are invalid.
  ValueError: If the backup plan is not found.
zCould not find the backup plan.)rG   r   r   zRules z+ found in more than one --backup-rule flag.z` not found in the backup plan. The --backup-rule flag can only be used to modify existing rules.c              3   8   >#    U  H  nUT;  d  M  Uv   M     g 7fr
    ).0rule_idcurrent_rule_idss     r   	<genexpr>0BackupPlansClient.ParseUpdate.<locals>.<genexpr>	  s#      0' 00 g0s   
	z not found in the backup plan.rD   rE   )
ValueErrorr#   rU   rG   rI   rL   r[   rM   rK   r    r>   collectionsCounterrW   r   InvalidArgumentExceptionlistsetextendrY   rZ   rN   )r   rI   new_backup_rules_from_fileupdate_backup_rulesadd_backup_rulesremove_backup_rulescurrent_backup_planra   rb   rc   updated_backup_planrulerule_idsrv   countduplicate_rule_idsnot_found_rule_idsupdate_rule_idsrw   s                     @r   ParseUpdateBackupPlansClient.ParseUpdate   sE   F "899--22(55 3  (3%%-?**6
1
2 8 1D0O0OP0O0OP!-(,(>(>
$)% ! &$$':
;':t	?':
;h )1(8(8ngEAI'(8   
11'( )# #
 	

  )%)d)_$44 $y/)% !	 

 
11'( ) 
 	
 6II5HTi5HoI *55)5d[[/ 5)%
 %%,,

 
 !4
5 )<(G(G%#%%,,

 
 !1
2 &
 0  
11'((FG
 	
 *55)5d[[ 33 5)%
 "
--
0
0(,,]; 1  2
 M Q <% J)6)sB   &K1KK)K"K3	K-KK#K+K"K"c                     [         R                  " 5       nU R                  R                  UUR	                  5       UUS9nU R
                  R                  U5      $ )zUpdates a Backup Plan.

Args:
  resource: The Backup Plan resource.
  backup_plan: The updated Backup Plan.
  update_mask: The update mask to edit the Backup Plan.

Returns:
  The updated Backup Plan.
)rP   rl   	requestId
updateMask)command_utilGenerateRequestIdr#   0BackupdrProjectsLocationsBackupPlansPatchRequestrS   r   Patch)r   r^   rg   update_mask
request_idrh   s         r   UpdateBackupPlansClient.Update!  sX     //1JmmLL""$	 M G <<g&&r   c                     U R                   R                  UR                  5       S9nU R                  R	                  U5      $ )ziDeletes a Backup Plan.

Args:
  resource: The Backup Plan resource.

Returns:
  The deleted Backup Plan.
rk   )r#   1BackupdrProjectsLocationsBackupPlansDeleteRequestrS   r   Deletero   s      r   r   BackupPlansClient.Delete5  sA     mmMM""$ N G <<w''r   )r   r
   )__name__
__module____qualname____firstlineno____doc__r   r>   r]   rp   r   r   r   __static_attributes____classcell__)r   s   @r   r   r      s8    ">2 hC(J%0 vp'(( (r   r   )
r   r{   googlecloudsdk.api_lib.backupdrr   googlecloudsdk.callioper   #googlecloudsdk.command_lib.backupdrr   BackupDrClientBaser   rt   r   r   <module>r      s,    !  0 . D
f(// f(r   