
    "                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ d
 Z G d de
j                        Zddie_        y)zCommand for deprecating images.    )absolute_import)division)unicode_literalsN)base_classes)arg_parsers)base)flagsc                 ~    | r| S |r7|t        j                  |      z   j                  d      j                         S y)zFGet the RFC 3339 time string for a provided absolute or relative time.)secondsr   )microsecondN)datetime	timedeltareplace	isoformat)absoluterelative_seccurrent_times      'lib/surface/compute/images/deprecate.py_ResolveTimer      s>     Ox)),??g!gYY[)     c                   &    e Zd ZdZed        Zd Zy)DeprecateImageszbManage deprecation status of Compute Engine images.

  *{command}* is used to deprecate images.
  c                    t        j                         t        _        t        j                  j	                  |        t         j
                  j	                  |        ddddd}| j                  d|dd d	d
       | j                         }|j                  dd       |j                  dt        j                         d       | j                         }|j                  dd       |j                  dt        j                         d       | j                         }|j                  dd       |j                  dt        j                         d       y )Nz!The image is currently supported.zNew uses result in an error. Setting this state will not automatically delete the image. You must still make a request to delete the image to remove it from the image list.zOperations which create a new *DEPRECATED* resource return successfully, but with a warning indicating that the image is deprecated and recommending its replacement.zNew uses result in an error.)ACTIVEDELETED
DEPRECATEDOBSOLETEz--stater   c                 "    | j                         S )N)upper)xs    r   <lambda>z&DeprecateImages.Args.<locals>.<lambda>K   s
    qwwyr   Tz*The deprecation state to set on the image.)choicesdefaulttyperequiredhelpz--deprecate-ona          Specifies a date when the image should be marked as DEPRECATED.

        Note: This is only informational and the image will not be deprecated unless you manually deprecate it.

        This flag is mutually exclusive with *--deprecate-in*.

        The date and time specified must be valid RFC 3339 full-date or date-time.
        For times in UTC, this looks like ``YYYY-MM-DDTHH:MM:SSZ''.
        For example: 2020-01-02T00:00:00Z for midnight on January 2, 2020 in UTC.
        )r&   z--deprecate-ina/          Specifies a time duration in which the image should be marked as ``DEPRECATED''.

        Note: This is only informational and the image will not be deprecated unless you manually deprecate it.

        This flag is mutually exclusive with *--deprecate-on*.

        For example, specifying ``30d'' sets the planned ``DEPRECATED'' date to 30 days from the current system time,
        but does not deprecate the image. You must manually deprecate the image in 30 days.
        See $ gcloud topic datetimes for information on duration formats.

       )r$   r&   z--delete-ona          Specifies a date when the image should be marked as ``DELETED''.

        Note: This is only informational and the image will not be deleted unless you manually delete it.

        This flag is mutually exclusive with *--delete-in*.

        The date and time specified must be valid RFC 3339 full-date or date-time.
        For times in UTC, this looks like ``YYYY-MM-DDTHH:MM:SSZ''.
        For example: 2020-01-02T00:00:00Z for midnight on January 2, 2020 in UTC.

        z--delete-ina          Specifies a time duration in which the image should be marked as ``DELETED''.

        Note: This is only informational and the image will not be deleted unless you manually delete it.

        For example, specifying ``30d'' sets the planned ``DELETED'' time to 30 days from the current system time,
        but does not delete the image. You must manually delete the image in 30 days.
        See $ gcloud topic datetimes for information on duration formats.

        This flag is mutually exclusive with *--delete-on*.
       z--obsolete-ona          Specifies a date when the image should be marked as ``OBSOLETE''.

        Note: This is only informational and the image will not be obsoleted unless you manually obsolete it.

        This flag is mutually exclusive with *--obsolete-in*.

        The date and time specified must be valid RFC 3339 full-date or date-time.
        For times in UTC, this looks like ``YYYY-MM-DDTHH:MM:SSZ''.
        For example: 2020-01-02T00:00:00Z for midnight on January 2, 2020 in UTC.
       z--obsolete-ina&          Specifies a time duration in which the image should be marked as ``OBSOLETE''.

        Note: This is only informational and the image will not be obsoleted unless you manually obsolete it.

        This flag is mutually exclusive with *--obsolete-on*.

        For example, specifying ``30d'' sets the planned ``OBSOLETE'' time to 30 days from the current system time,
        but does not obsolete the image. You must manually obsolete the image in 30 days.
        See $ gcloud topic datetimes for information on duration formats.
        )
r	   MakeDiskImageArgr   DISK_IMAGE_ARGAddArgumentREPLACEMENT_DISK_IMAGE_ARGadd_argumentadd_mutually_exclusive_groupr   Duration)parserdeprecation_statusesdeprecate_groupdelete_groupobsolete_groups        r   ArgszDeprecateImages.Args4   s{   %*%;%;%=O"""..v6	$$008 6A; 3 $ 9  ; 99;O  
 !    !!# !   668L   !!#
   88:N
    !!#
   r   c           	         t        j                  | j                               }|j                  }t        j                  j                         }t        |j                  |j                  |      }t        |j                  |j                  |      }t        |j                  |j                  |      }|j                  j                  j                  |j                         }t"        j$                  j'                  ||j(                        }	|	r|	j+                         }
nd}
t,        j.                  j'                  ||j(                        }|j                  j1                  |j                  j                  |||||
      |j3                         |j4                        }|j7                  |j8                  j:                  d|fg      S )z2Invokes requests necessary for deprecating images.N)statedeletedobsolete
deprecatedreplacement)deprecationStatusimageproject	Deprecate)r   ComputeApiHolderReleaseTrackclientr   nowr   	delete_on	delete_inobsolete_onobsolete_indeprecate_ondeprecate_inmessagesDeprecationStatusStateValueValuesEnumr5   r	   r*   ResolveAsResource	resourcesSelfLinkr   r(   ComputeImagesDeprecateRequestNamer<   MakeRequestsapitools_clientimages)selfargsholderr@   r   delete_timeobsolete_timedeprecate_timer5   replacement_refreplacement_uri	image_refrequests                r   RunzDeprecateImages.Run   s    **4+<+<+>?F]]F $$((*Lt~~t~~|LK $**L:M!4,,l<N OO--BB4::NE66HHf O'002oo..@@f I oo;; //;;"%' < ) nn!! < #G !7!7!>!>!,g!7  8 9 9r   N)__name__
__module____qualname____doc__staticmethodr3   r]    r   r   r   r   .   s#    
 w wr*9r   r   EXAMPLESaN  
To deprecate an image called 'IMAGE' immediately, mark it as
obsolete in one day, and mark it as deleted in two days, use:

  $ {command} IMAGE --state=DEPRECATED --obsolete-in=1d --delete-in=2d

To un-deprecate an image called 'IMAGE' and clear times for deprecated,
obsoleted, and deleted, use:

  $ {command} IMAGE --state=ACTIVE
)ra   
__future__r   r   r   r   googlecloudsdk.api_lib.computer   googlecloudsdk.callioper   r   )googlecloudsdk.command_lib.compute.imagesr	   r   SilentCommandr   detailed_helprc   r   r   <module>rk      sP    & &  '  7 / ( ;"j9d(( j9\  
! r   