
    M                     8   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d
lmZ ddlmZ ddlmZ ddlmZ dddZej(                   ej*                  ej,                  j.                         G d dej0                                      Zy)z,Command to create transfer appliance orders.    )absolute_import)division)unicode_literalsN)operations_util)apis)
exceptions)base)flags)mapping_util)regions)resource_argsz
        *{command}* facilitates the creation of Transfer Appliance orders.
        When an order is created, an appliance record is created as well.
        ag  
        To order a rackable appliance with 40 TB of storage, named
        `my-appliance`, a Cloud Storage destination of `my-bucket` and the
        minimum amount of contact information.

          $ {command} my-appliance               --model=TA40_RACKABLE               --shipping-contact="name=Jane Doe,emails=[jane@example.com],phone=12345678910"               --offline-import=gs://my-bucket               --order-contact="name=John Doe,phone=123456578910,emails=[john@example.com]" --country=US               --address="lines=['1600 Amphitheatre Parkway'],locality=Mountain View,administrative-area=CA,postal-code=94043"

        To clone an appliance order with the ID `my-appliance` and location
        `us-central1`, only changing the name and Cloud Storage destination:

          $ {command}               my-other-appliance --country=US --clone=my-appliance               --clone-region=us-central1 --offline-import=my-other-bucket

        To use a flags file to create an appliance rather than provide a
        long list of flags:

          $ {command} my-appliance               --flags-file=FLAGS_FILE

        Example file with all possible flags set:

          --address:
            lines:
            - 1600 Amphitheatre Parkway
            locality: Mountain View
            administrative-area: California
            postal-code: 94043
          --cmek: projects/p/locations/global/keyRings/kr/cryptoKeys/ck
          --country: US
          --delivery-notes: None
          --display-name: test
          --internet-enabled:
          --model: TA40_RACKABLE
          --offline-export:
            source: gs://my-bucket/path
            manifest: gs://my-other-bucket/manifest
          --offline-import: gs://my-bucket/path
          --online-import: gs://my-bucket/path
          --order-contact:
            business: Google
            name: Jane Doe
            phone: 1234567890
            emails:
            - janedoe@example.com
          --shipping-contact:
            business: Google
            name: John Doe
            phone: 1234567890
            emails:
            - johndoe@example.com
        )DESCRIPTIONEXAMPLESc                   T    e Zd ZdZeZed        Z ej                  d      d        Z
y)Createz)Create an order for a transfer appliance.c                     | j                  dd       | j                  ddd       t        j                  |        t        j                  |        t        j
                  |        y )Nnamez7Immutable ID that will uniquely identify the appliance.)helpz--submit
store_truezWhen specified the order will be submitted immediately. By default, orders are created in a draft state. Use `{parent_command} update --submit` to submit the order later.)actionr   )add_argumentr   add_clone_resource_argr
   add_appliance_settingsadd_delivery_information)parsers    0lib/surface/transfer/appliances/orders/create.pyArgszCreate.Argsl   si    
F  H L	  
 ((0	  (	""6*    z-Status code: {status_code}. {status_message}.c           	         t        j                  dd      }t        j                  dd      }|j                         }|j	                         }g }t
        j                  |j                     }t        j                  |      }|j                  d      r|j                  j                  j                         }	|j                  j                  |j!                  |	j#                                     }|j$                  r8|j&                  j                  |j)                  |j$                  d               }t+        j,                  ||       |j&                  j/                  |j1                  ||j2                  |t5        j6                         j8                              }
|j;                  t=        j>                  |
d             t        j@                  ||j2                        }t+        jB                  |||       |jD                  |_#        |j                  j/                  |jI                  ||j2                  |t5        j6                         j8                  	            }
|j;                  t=        jJ                  |
d             |S )
Ntransferappliancev1alpha1clone)r   )requestr   )	applianceapplianceIdparent	requestIdcreate)orderorderIdr&   r'   )&r   GetClientInstanceGetMessagesModule	ApplianceOrderr   COUNTRY_TO_LOCATION_MAPcountryr   get_parent_stringIsSpecifiedCONCEPTSr"   Parseprojects_locations_ordersGet2TransferapplianceProjectsLocationsOrdersGetRequestRelativeName
appliancesprojects_locations_appliances6TransferapplianceProjectsLocationsAppliancesGetRequestr   apply_args_to_appliancer   9TransferapplianceProjectsLocationsAppliancesCreateRequestr   uuiduuid4hexappendr   wait_then_yield_applianceget_appliance_nameapply_args_to_ordersubmit	skipDraft5TransferapplianceProjectsLocationsOrdersCreateRequestwait_then_yield_order)selfargsclientmessagesr$   r)   resultsregionr&   	clone_ref	operationappliance_names               r   Runz
Create.Run~   s+    ##$7DF%%&9:FH""$INNEG,,T\\:F,,V4F --%%++-i..22MM))+ N - 3 .e 
		 88<<KK%%a( L *+	
 ((D944;;JJ		jjl&&	 	K 	()I NN?<<8  #55fdiiHN$$UD.AkkEO0077FFIIjjl&&	 	G 	()I NN?888 Nr   N)__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpstaticmethodr   gcloud_exception CatchHTTPErrorRaiseHTTPExceptionrR    r   r   r   r   e   sC     2-+ +" 5445..r   r   )rV   
__future__r   r   r   r>   *googlecloudsdk.api_lib.transfer.appliancesr   googlecloudsdk.api_lib.utilr   r   rZ   googlecloudsdk.callioper	   .googlecloudsdk.command_lib.transfer.appliancesr
   r   r   r   rW   DefaultUniverseOnlyReleaseTracksReleaseTrackALPHACommandr   r\   r   r   <module>rg      s    3 &  '  G , F ( @ G B H
	
8	@F D%%++,HT\\ H - Hr   