
    G*                     d   S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSK	Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  \R*                  \R,                  " \R.                  R0                  \R.                  R2                  5       " S S\R4                  5      5       5       rg)zUpdates a new Backup Plan.    )absolute_import)division)unicode_literalsN)
exceptions)backup_plans)util)base)flags)log)yamlc                       \ rS rSrSrSSSS.r\S\R                  4S j5       r	 " S	 S
\
R                  5      rS rS\4S jrSrg)Update"   zUpdate a specific backup plan.zUpdate a specific backup planz          Update a specific backup plan in the project. It can only be updated in regions supported by the Backup and DR Service.
      a          To update 2 backup rules and description of an existing backup plan ``sample-backup-plan''
        in project ``sample-project'',
        at location ``us-central1'':

        run:

          $ {command} sample-backup-plan --project=sample-project --location=us-central1
            --backup-rule <BACKUP-RULE>
            --backup-rule <BACKUP-RULE>
            --description "This is a sample backup plan"

        To add backup rules to an existing backup plan ``sample-backup-plan''
        in project ``sample-project'',
        at location ``us-central1'':

        run:

          $ {command} sample-backup-plan --project=sample-project --location=us-central1
            --add-backup-rule <BACKUP-RULE>
            --add-backup-rule <BACKUP-RULE>

        To remove a backup rule with id ``sample-daily-rule'' from an existing backup plan ``sample-backup-plan''
        in project ``sample-project'',
        at location ``us-central1'':

        run:

          $ {command} sample-backup-plan --project=sample-project --location=us-central1
            --remove-backup-rule sample-daily-rule

        To override backup rules in an existing backup plan ``sample-backup-plan''
        in project ``sample-project'',
        at location ``us-central1'', pass a file path containing backup rules in YAML or JSON format:
        This flag is mutually exclusive with --add-backup-rule, --remove-backup-rule and --backup-rule flags.

        run:
          $ {command} sample-backup-plan --project=sample-project --location=us-central1
            --backup-rules-fom-file <FILE_PATH>

        Backup Rule Examples:

        1. Hourly backup rule with hourly backup frequency of 6 hours and store it for 30 days, and expect the backups to run only between 10:00 to 20:00 UTC

        <BACKUP-RULE>: rule-id=sample-hourly-rule,retention-days=30,recurrence=HOURLY,hourly-frequency=6,time-zone=UTC,backup-window-start=10,backup-window-end=20

        Properties:
          -- rule-id = "sample-hourly-rule"
          -- retention-days = 30
          -- recurrence = HOURLY
          -- hourly-frequency = 6
          -- time-zone = UTC
          -- backup-window-start = 10
          -- backup-window-end = 20

        2. Daily backup rule with daily backup frequency of 6 hours and store it for 7 days

        <BACKUP-RULE>: rule-id=sample-daily-rule,retention-days=7,recurrence=DAILY,backup-window-start=1,backup-window-end=14

        Properties:
          -- rule-id = "sample-daily-rule"
          -- retention-days = 7
          -- recurrence = DAILY
          -- backup-window-start = 1
          -- backup-window-end = 14

        3. Weekly backup rule with weekly backup frequency on every MONDAY & FRIDAY and store it for 21 days

        <BACKUP-RULE>: rule-id=sample-weekly-rule,retention-days=21,recurrence=WEEKLY,days-of-week="MONDAY FRIDAY",backup-window-start=10,backup-window-end=20

        Properties:
          -- rule-id = "sample-weekly-rule"
          -- retention-days: 21
          -- recurrence = WEEKLY
          -- days-of-week = "MONDAY FRIDAY"
          -- backup-window-start = 10
          -- backup-window-end = 20

        YAML and JSON file examples:

        YAML file example:

        ```
        backup-rules:
        - rule-id: weekly-rule
          retention-days: 7
          recurrence: WEEKLY
          backup-window-start: 0
          backup-window-end: 23
          days-of-week: [MONDAY, TUESDAY]
          time-zone: UTC
        - rule-id: daily-rule
          retention-days: 1
          recurrence: DAILY
          backup-window-start: 1
          backup-window-end: 24
          time-zone: UTC
        ```

        JSON file example:
        ```
        {
          "backup-rules": [
            {
              "rule-id": "weekly-rule",
              "retention-days": 7,
              "recurrence": "WEEKLY",
              "backup-window-start": 0,
              "backup-window-end": 23,
              "days-of-week": ["MONDAY", "TUESDAY"],
              "time-zone": "UTC"
            },
            {
              "rule-id": "daily-rule",
              "retention-days": 1,
              "recurrence": "DAILY",
              "backup-window-start": 1,
              "backup-window-end": 24,
              "time-zone": "UTC"
            }
          ]
        }
        ```
        )BRIEFDESCRIPTIONEXAMPLESparserc                    [         R                  R                  U 5        [         R                  R                  U S5        [        R
                  " U S5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        Sn[        R                  " X5        [        R                  " U 5        [        R                  " U 5        g)z\Specifies additional command flags.

Args:
  parser: Parser object for command line inputs.
TzkName of the backup plan to be updated.
        The name must be unique for a project and location.
        a          Provide a description of the backup plan, such as specific use cases and
        relevant details, in 2048 characters or less.

        E.g., This is a backup plan that performs a daily backup at 6 p.m. and
        retains data for 3 months.
        N)r	   
ASYNC_FLAGAddToParser
SetDefaultr
   AddBackupPlanResourceArgAddUpdateBackupRuleAddAddBackupRuleAddRemoveBackupRuleAddBackupRulesFromFileAddDescriptionAddLogRetentionDays!AddMaxCustomOnDemandRetentionDays)r   description_helps     ,lib/surface/backup_dr/backup_plans/update.pyArgsUpdate.Args   s     	OO'OOvt,	""	 
f%	6"	f%	  ( 
2	f%	++F3    c                       \ rS rSrSrSrg)Update.YamlOrJsonLoadError   z(Error parsing YAML or JSON file content. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r(   r$   r!   YamlOrJsonLoadErrorr&      s    2r$   r/   c                      [         R                  " U5      nUR                  S5      $ ! [         a&  nU R	                  SR                  U5      5      UeSnAff = f)z.Parses the backup rules from the file content.zbackup-rulesz5Could not parse content in the backup rules file: {0}N)r   loadget	Exceptionr/   format)selfbackup_rules_file_contentbackup_rulesexcs       r!   _GetBackupRulesFromFileUpdate._GetBackupRulesFromFile   s[    YY89ln-- $$
A
H
H
Ms   &) 
A!AAreturnc           
      X   [         R                  " 5       nUR                  R                  R	                  5       nUR
                  nUR                  nUR                  nUR                  nU(       a+  U(       d  U(       d  U(       a  [        R                  " S5      eUR                  nUR                  n	UR                  n
 UR                  U5      nSnU(       a  U R                  U5      nUR!                  U	UUUUUUU
5      n/ nU	b   XR                  :w  a  UR#                  S5        Ub   XR$                  :w  a  UR#                  S5        U
b!  U
UR&                  :w  a  UR#                  S5        [)        UUUU/5      (       a  UR#                  S5        UR+                  X=SR-                  U5      5      nUR:                  (       aN  [<        R>                  " URA                  5       SS	[6        RB                  RE                  URF                  5      S
9  U$ URI                  URK                  U5      SURA                  5        S3S9n[<        R>                  " URA                  5       SS9  U$ ! [.        R0                   a*  n[2        R4                  " U[6        R8                  5      eSnAff = f)zConstructs and sends request.

Args:
  args: argparse.Namespace, An object that contains the values for the
    arguments specified in the .Args() method.

Returns:
  ProcessHttpResponse of the request made.
zq--backup-rules-from-file flag cannot be used with --backup-rule, --add-backup-rule or --remove-backup-rule flags.NdescriptionlogRetentionDaysmaxCustomOnDemandRetentionDaysbackupRules,zbackup planT)kindis_asyncdetailszUpdating backup plan [z/]. (This operation could take up to 2 minutes.))operation_refmessage)rB   )&r   BackupPlansClientCONCEPTSbackup_planParsebackup_rules_from_filebackup_ruleadd_backup_ruleremove_backup_rulecore_exceptionsErrorlog_retention_daysr=   #max_custom_on_demand_retention_daysDescriber9   ParseUpdateappendr>   r?   anyr   joinapitools_exceptions	HttpErrorr   HttpExceptionr   HTTP_ERROR_FORMATasync_r   UpdatedResourceRelativeNameASYNC_OPERATION_MESSAGEr4   nameWaitForOperationGetOperationRef)r5   argsclientrI   r6   update_backup_rulesadd_backup_rulesremove_backup_rulesrQ   r=   rR   current_backup_plannew_backup_rules_from_fileupdated_backup_planupdate_mask	operationeresources                     r!   Run
Update.Run   s    ++-F--++113K $ ; ;**++11 /3F!!M 
 00""K00 (-@"OOK8#' 	"%)%A%A%&
" #..

$





-	 k

!<<<=)

( $H$HH-.
-
91 ??@ 	;<	



$	 
	 
	 	=)--
CHH[,Ai {{	

"
"
$..55innE	 &&,,Y7$[%=%=%?$@ A6 6 ' H 002GO+ (( @$$Q(>(>??@s   C5I+ +J)?%J$$J)r(   N)r)   r*   r+   r,   r-   detailed_helpstaticmethodargparseArgumentParserr"   rO   rP   r/   r9   rV   ro   r.   r(   r$   r!   r   r   "   sf     ' /
{A-F 48** 4 4<3O11 3a ar$   r   )r-   
__future__r   r   r   rs   apitools.base.pyr   rX   googlecloudsdk.api_lib.backupdrr   r   googlecloudsdk.api_lib.utilgooglecloudsdk.callioper	   #googlecloudsdk.command_lib.backupdrr
   googlecloudsdk.corerO   r   r   UniverseCompatibleReleaseTracksReleaseTrackALPHAGAUpdateCommandr   r(   r$   r!   <module>r      s    ! &  '  > 8 0 2 ( 5 = # $ D%%++T->->-A-ABST S C Sr$   