
    s_                     H   S 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  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  \" 5       r                 SS jr SS jr       SS jr SS jr     SS jr     SS jrS r g)z:Convenience functions for dealing with instance templates.    )absolute_import)division)unicode_literals)alias_ip_range_utils)	constants)image_utils)instance_utils)	kms_utils)utils)scope)flags)labels_util)
propertiesNc                 \   UR                  5       nUbW  [        R                  " 5       R                  U/[        R
                  R                  UU US9S   nUR                  5       Ul        UbU  U R                  US[        R                  R                  R                  R                  0SS9nUR                  5       Ul        OhUce  Ucb  U R                  [         R"                  S[        R                  R                  R                  R                  0SS9nUR                  5       Ul        Ub  UUl        U
b   UR                   R'                  U
5      Ul        U(       a~  U
S:w  ax  UR+                  [         R,                  UR*                  R.                  R0                  S9nU[2        :w  a  UUl        U	b   UR*                  R7                  U	5      Ul        U/Ul        SnUc  UbD  UR+                  [         R<                  UR*                  R.                  R>                  S9nU/Ul         Ub   UR*                  R7                  U5      Ul        Ub  UUl!        Uc  UnUc  UnUbN  UcD  UR+                  [         R<                  UR*                  R.                  R>                  S9nU/Ul         UUl"        UbN  UcD  UR+                  [         R<                  UR*                  R.                  R>                  S9nU/Ul         UUl#        Ub  UUl$        Ub  UUl%        U(       a  [L        RN                  " US	U5      Ul(        Ub   UR                   RS                  U5      Ul*        Ub  UUl+        Ub  UUl,        Ub  UUl-        Ub   UR                   R]                  U5      Ul/        U(       a  UUl0        U$ )
aX
  Creates and returns a new NetworkInterface message.

Args:
  resources: generates resource references,
  scope_lister: function, provides scopes for prompting subnet region,
  messages: GCE API messages,
  network: network,
  private_ip: IPv4 internal IP address to assign to the instance.
  subnet_region: region for subnetwork,
  subnet: regional subnetwork,
  address: specify static address for instance template
             * None - no address,
             * EPHEMERAL_ADDRESS - ephemeral address,
             * string - address name to be fetched from GCE API.
  alias_ip_ranges_string: command line string specifying a list of alias
      IP ranges.
  network_tier: specify network tier for instance template
             * None - no network tier
             * PREMIUM - network tier being PREMIUM
             * SELECT - network tier being SELECT
             * STANDARD - network tier being STANDARD
  stack_type: identify whether IPv6 features are enabled
             * IPV4_ONLY - can only have IPv4 address
             * IPV4_IPV6 - can have both IPv4 and IPv6 address
             * IPV6_ONLY - can only have IPv6 address
  ipv6_network_tier: specify network tier for IPv6 access config
             * PREMIUM - network tier being PREMIUM
             * STANDARD - network tier being STANDARD
  nic_type: specify the type of NetworkInterface Controller
             * GVNIC
             * VIRTIO_NET
  ipv6_public_ptr_domain: a string represents the custom PTR domain assigned
    to the interface.
  ipv6_address: a string represents the external IPv6 address reserved to the
    interface.
  ipv6_prefix_length: a string represents the external IPv6 address
    prefix length reserved to the interface.
  external_ipv6_address: a string represents the external IPv6 address
    reserved to the interface.
  external_ipv6_prefix_length: a string represents the external IPv6 address
    prefix length reserved to the interface.
  internal_ipv6_address: a string represents the internal IPv6 address
    reserved to the interface.
  internal_ipv6_prefix_length:  the internal IPv6 address prefix
    length of the internal IPv6 address reserved to the interface.
  network_attachment: URL of a network attachment to connect the interface to.
  network_queue_count: the number of queues assigned to the network interface.
  vlan: the VLAN tag of the network interface.
  igmp_query: the IGMP query mode of the network interface.
  enable_vpc_scoped_dns: If True, indicates that this network interface can be
    used to send DNS queries to the VPC network's scope.

Returns:
  network_interface: a NetworkInterface message object
N)scope_listerr   projectzcompute.networks)params
collection	IPV6_ONLY)nametypeF)1NetworkInterfacesubnet_flagsSubnetworkResolverResolveResourcescompute_scope	ScopeEnumREGIONSelfLink
subnetworkParser   VALUEScorer   	GetOrFailnetworkr   DEFAULT_NETWORK	networkIPStackTypeValueValuesEnum	stackTypeAccessConfigDEFAULT_ACCESS_CONFIG_NAMETypeValueValuesEnumONE_TO_ONE_NATEPHEMERAL_ADDRESSnatIPNetworkTierValueValuesEnumnetworkTieraccessConfigsDEFAULT_IPV6_ACCESS_CONFIG_NAMEDIRECT_IPV6ipv6AccessConfigspublicPtrDomainNameexternalIpv6externalIpv6PrefixLengthipv6AddressinternalIpv6PrefixLengthr   $CreateAliasIpRangeMessagesFromStringaliasIpRangesNicTypeValueValuesEnumnicTypenetworkAttachment
queueCountvlanIgmpQueryValueValuesEnum	igmpQueryenableVpcScopedDns)	resourcesr   messagesr%   
private_ipsubnet_regionsubnetaddressalias_ip_ranges_stringnetwork_tier
stack_typeipv6_network_tiernic_typeipv6_public_ptr_domainipv6_addressipv6_prefix_lengthexternal_ipv6_addressexternal_ipv6_prefix_lengthinternal_ipv6_addressinternal_ipv6_prefix_lengthnetwork_attachmentnetwork_queue_countrA   
igmp_queryenable_vpc_scoped_dnsnetwork_interface
subnet_refnetwork_refaccess_configipv6_access_configs                                 =lib/googlecloudsdk/api_lib/compute/instance_template_utils.pyCreateNetworkInterfaceMessagera   $   s   h //1002CC	&&! D #
 $%&J $.#6#6#8 //:,,1199CCD% " 'K !, 4 4 6 ~,4//!!:,,1199CCD% " 'K !, 4 4 6",!!:::F  {*))11""66EE * GM ###m



:
:<
H  (5o#"&<&H!..66""66BB / D ,>*>'"889JK " '-C* "( !("4&!#0088$$88DD 1 F .@,@)&;# ,!#0088$$88DD 1 F .@,@)2M/&$9! ,1L.AAe3	5 # !!88B  #*<'$#6 	!!!:::F  +@(	    c                    / nU(       Ga  U GH  nUR                  SS5      nSU;   =(       d    UR                  SS5      n	US:X  d
  Uc  U	(       d  [        nUR                  SS5      n
UR                  SS5      nSnU(       a  SU;   nUR                  [        U UUUR                  S	S5      UR                  S
S5      UUR                  SS5      UUR                  SS5      U
4
UUR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  SS5      UR                  S5      UR                  SS5      UR                  SS5      UR                  SS5      US.65        GM     U$ )a  Create network interface messages.

Args:
  resources: generates resource references,
  scope_lister: function, provides scopes for prompting subnet region,
  messages: creates resources.
  network_interface_arg: CLI argument specifying network interfaces.
  subnet_region: region of the subnetwork.
  support_enable_vpc_scoped_dns: Indicates whether setting enable vpc scoped
    dns on network interfaces is supported.

Returns:
  list, items are NetworkInterfaceMessages.
rJ   Nz
no-addressznetwork-attachment znetwork-tierznic-typezenable-vpc-scoped-dnsr%   zprivate-network-iprI   aliasesz
stack-typezipv6-network-tierzipv6-public-ptr-domainzipv6-addresszipv6-prefix-lengthzexternal-ipv6-addresszexternal-ipv6-prefix-lengthzinternal-ipv6-addresszinternal-ipv6-prefix-lengthzqueue-countrA   z
igmp-query)rO   rM   rN   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rA   rY   rZ   )getr.   appendra   )rE   r   rF   network_interface_argrH   support_enable_vpc_scoped_dnsresult	interfacerJ   has_no_addressrL   rO   rZ   s                r`   CreateNetworkInterfaceMessagesrm      s   , &*	i.g $y0 &IMM
5&n 
B7?N#]]>48lz40h"	& 79 Dmm
'mmIt,mm0$7mmHd+mmIt,$  "|T: ).A4 H%.]]*D& %==>!*/CT!J$-MM)4% +4--/+ %.MM)4% +4--/+ "+/C!D"+--t"D==."|T:$9G$&! +n 
-rb   c                    U	(       a  U R                   O/ n[        UR                  U R                  =(       d    / US9n[	        UUU[        U S/ 5      UUU
US9nU(       a[  [        UR                  U R                  U R                  U R                  UUU UU R                  U R                  U R                  S9/nO^U(       a'  US   R                  (       a  UR                  S5      /nO0U(       a'  US   R                  (       a  UR                  S5      /nO/ n[        R                   " U UUR                  5      n[        R"                  " U UUR                  5      nUU-   U-   U-   U-   $ )z4Create disk messages for a single instance template.)container_mount_diskcreate_disk)support_kmssupport_multi_writersupport_replica_zonessupport_disk_labels)rF   	disk_typedisk_device_namedisk_auto_deletedisk_size_gb	image_urikms_argsrq   disk_provisioned_iopsdisk_provisioned_throughputdisk_interfacer   )ro   $CreatePersistentAttachedDiskMessagesrF   disk"CreatePersistentCreateDiskMessagesgetattr$CreateDefaultBootAttachedDiskMessageboot_disk_typeboot_disk_device_nameboot_disk_auto_deleteboot_disk_provisioned_iops boot_disk_provisioned_throughputboot_disk_interfacebootpopcreate_utilsCreateLocalNvdimmMessagesCreateLocalSsdMessages)argsclientrE   r   ry   boot_disk_size_gbcreate_boot_diskrq   rr   match_container_mount_disksrs   rt   ro   persistent_diskspersistent_create_disksboot_disk_listlocal_nvdimms
local_ssdss                     r`   CreateDiskMessagesr   D  s~     $?dB  +
//
))/r35  ?dM2&/1-	 ,__))!77!77*#"&"A"A(,(M(M33	
N #:1#=#B#B-11!45N,Q/44&**1-.NN88
oo- 22
oo*   	 		rb   c           
         / nU GHb  nUS   nUR                  SS5      nUS:X  a!  U R                  R                  R                  nO U R                  R                  R                  nUR                  SS5      nUR                  SS5      n	[
        R                  " XEU5      n
U R                  U	UU
UUU R                  R                  R                  S9nUR                  S5      (       a\  UR                  S5      S	:X  a!  U R                  R                  R                  nO U R                  R                  R                  nXl        U(       a	  U/U-   nGMQ  UR                  U5        GMe     U$ )
a#  Returns a list of AttachedDisk messages and the boot disk's reference.

Args:
  messages: GCE API messages,
  disks: disk objects - contains following properties
           * name - the name of disk,
           * mode - 'rw' (R/W), 'ro' (R/O) access mode,
           * boot - whether it is a boot disk,
           * auto-delete - whether disks is deleted when VM is deleted,
           * device-name - device name on VM.
  container_mount_disk: list of disks to be mounted to container, if any.

Returns:
  list of API messages for attached disks
r   moderwr   Fauto-delete)
autoDeleter   
deviceNamer   sourcer   rk   SCSI)rf   AttachedDiskModeValueValuesEnum
READ_WRITE	READ_ONLYr	   GetDiskDeviceNamer,   
PERSISTENTInterfaceValueValuesEnumr   NVMErk   rg   )rF   disksro   disks_messagesr   r   
mode_valuer   r   auto_deletedevice_nameattached_diskrk   s                r`   r~   r~     sS   & .d<D&$'JT""66AAd""66@@d88FE"D((=%0K 2243GIK ))""66AA * CM xx	+	&	())BBGG	))BBGG	 ) %7nM*C F 
rb   c	                    / n	U R                   n
U=(       d    /  GH:  nUR                  S5      nUR                  SS5      nUS:X  a+  U R                   R                  R                  R                  nO*U R                   R                  R                  R
                  nUR                  SS5      nUR                  SS5      n[        R                  " UR                  S5      5      nUR                  S5      nUR                  S	5      nUR                  S
5      nSnU(       d  U(       a,  [        R                  " X5      nUR                  UUUUSS9u  nnSnU(       a!  [        R                  " XR                   U5      n[        R                  " XU5      nU R                   R                  UUR                  S5      UUUR                  S5      UR                  S5      S9nUR                  S5      nU(       aK  U(       aD  / nU H5  nUR!                  USSU0S9nUR#                  UR%                  5       5        M7     UUl        UR                  S5      nU(       a  UUl        UR                  S5      n U(       a  U (       a  SUl        UR                  S5      n!U!(       a   U
R                  R-                  U!5      Ul        U(       a  [0        R2                  " UR                  S5      5      n"U"(       aZ  U
R                  R5                  5       n#U"R7                  5        V$V%s/ s H  u  n$n%U#R9                  U$U%S9PM     sn%n$U#l        U#Ul        UR                  S5      Ul        UR                  S5      Ul         U R                   R                  UUUUUU R                   R                  RB                  RD                  US9n&UR                  S5      (       a]  UR                  S5      S:X  a!  U
R                  RF                  RH                  n'O U
R                  RF                  RJ                  n'U'U&l&        U(       a	  U&/U	-   n	GM)  U	R#                  U&5        GM=     U	$ s  sn%n$f ) aX  Returns a list of AttachedDisk messages.

Args:
  client: Compute client adapter
  resources: Compute resources registry
  user_project: name of user project
  create_disks: disk objects - contains following properties * name - the name
    of disk, * description - an optional description for the disk, * mode -
    'rw' (R/W), 'ro' (R/O) access mode, * size - the size of the disk, *
    provisioned-iops - Indicates how many IOPS must be provisioned for the
    disk. * provisioned-throughput - Indicates how much throughput is
    provisioned for the disks. * type - the type of the disk (HDD or SSD), *
    image - the name of the image to initialize from, * image-family - the
    image family name, * image-project - the project name that has the image,
    * auto-delete - whether disks is deleted when VM is deleted ('yes' if
    True), * device-name - device name on VM, * disk-resource-policy -
    resource policies applied to disk. * storage-pool: the storage pool in
    which the new disk is created.
  support_kms: if KMS is supported
  container_mount_disk: list of disks to be mounted to container, if any.
  support_multi_writer: if multi writer disks are supported.
  support_replica_zones: True if we allow creation of regional disks.
  support_disk_labels: True if we allow adding disk labels.

Returns:
  list of API messages for attached disks
r   r   r   r   Fr   sizeimagezimage-familyzimage-projectN)user_projectr   image_familyimage_projectreturn_image_resourcedescriptionr   zprovisioned-iops)diskNamer   sourceImage
diskSizeGbdiskTypeprovisionedIopszreplica-zoneszcompute.zonesr   )r   r   zdisk-resource-policyzmulti-writerTarchitecturelabels)keyvaluezprovisioned-throughputzstorage-poolr   r   r   initializeParamsr   r   diskEncryptionKeyrk   r   )'rF   rf   r   r   r   r   r   	BytesToGbr   ImageExpanderExpandImageFlagr
   MaybeGetKmsKeyFromDictr	   r   AttachedDiskInitializeParamsr!   rg   r   replicaZonesresourcePoliciesmultiWriterArchitectureValueValuesEnumr   r   ValidateAndParseLabelsLabelsValueitemsAdditionalPropertyadditionalPropertiesr   provisionedThroughputstoragePoolr,   r   r   r   r   rk   )(r   rE   r   create_disksrq   ro   rr   rs   rt   r   rF   r   r   r   r   r   r   rx   img
img_familyimg_projectry   image_expander_disk_keyr   init_paramsreplica_zonesnormalized_zoneszonezone_refpoliciesmulti_writerdisk_architecturedict_labelslabels_valuer   r   rp   rk   s(                                           r`   r   r     s   N .__( b d88FD&$'JT__))==HHd__))==GGd((=%0K88FE"D??488F#34L
((7
C.)J((?+KI
j"00Cn#33#!# % 4 'li H11$2:<h !2243GIK //>>HH]+&!!34 ? 6K HH_-M$??_i5N # P 1 1 34   "2kxx./H%-k"88N+L $k0

/
/
K
K  66txx7IJk	<<HHJ *//1-
1
U ++5+A1-
)
 *(,1I(JK%"hh~6K//..$__))==HH" / K xx	+	&	())BBGG	))BBGG	'k #}~5nK(M !P 
C-
s    Qc           
         SnU(       a  [         R                  " X`USS9nU R                  XTUS9nUb  Xl        U	b  Xl        U R                  USUUU R
                  R                  R                  U R
                  R                  R                  US9nU
(       aM  U
S:X  a!  U R
                  R                  R                  nO U R
                  R                  R                  nXl        U$ )z=Returns an AttachedDisk message for creating a new boot disk.NT)boot_disk_prefix)r   r   r   r   r   )r
   MaybeGetKmsKeyr   r   r   r   r   r   r,   r   r   r   r   rk   )rF   ru   rv   rw   rx   ry   rz   rq   r{   r|   r}   r   initialize_paramsboot_attached_diskrk   s                  r`   r   r   a  s     (''Ht=H ;;y < J &(=% ,.I+,,!!(  44??  44??  -  ''@@EEi''@@EEi#, 	rb   c                 p    Uc  / $ US   n[        UR                  SS5      5      nU R                  X#S9nU/$ )a  Returns a list of accelerator config messages for Instance Templates.

Args:
  messages: tracked GCE API messages.
  accelerator: accelerator object with the following properties:
      * type: the accelerator's type.
      * count: the number of accelerators to attach. Optional, defaults to 1.

Returns:
  a list of accelerator config messages that specify the type and number of
  accelerators to attach to an instance.
r   count   )acceleratorTypeacceleratorCount)intrf   AcceleratorConfig)rF   acceleratoraccelerator_typeaccelerator_countaccelerator_configs        r`   CreateAcceleratorConfigMessagesr     sS     I (+//'15611& 2 L
	rb   )NNNNNNNNNNNNNNNNN)F)NFFFFTF)N)FNFTF)NFNNN)!__doc__
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   r	   r
   r   /googlecloudsdk.api_lib.compute.instances.creater   "googlecloudsdk.command_lib.computer   r   3googlecloudsdk.command_lib.compute.networks.subnetsr   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   objectr.   ra   rm   r   r~   r   r   r    rb   r`   <module>r      s    A &  ' ? 4 6 9 4 0 Q E U < *H    $ $	3Kh #(Op  %L` +/7~ Qv  $+\rb   