
    
                     b    d Z ddlmZ ddlmZ ddlmZ ddlmZ g dZdZdZ	d	 Z
d
 Zd ZddZy)zFUtility function for OS Config Troubleshooter to check metadata setup.    )absolute_import)division)unicode_literals)utils)trueyyes1   zenable-osconfigzosconfig-disabled-featuresc                     g d}t        j                  ||      }ddd| j                  dg}t        j                  ||      }d|z   dz   |z   S )N)computeproject_infoadd-metadata--metadata=enable-osconfig=truer   	instancesr   r   zeNo
OS Config agent is not enabled for this VM instance. To enable for all VMs in this project, run:

z

To enable for this VM, run:

)r   GetCommandStringname)instancerelease_trackcommand_argsproject_commandinstance_argsinstance_commands         Olib/googlecloudsdk/command_lib/compute/os_config/troubleshoot/metadata_setup.py_DisabledMessager   $   sn    5,**<G/k>8==46-++M=I/1@AD,, /?? @    c                     d| z   dz   S )Nz_Yes
OS Config agent is enabled for this VM instance, but the following features are disabled:
[z].
See https://cloud.google.com/compute/docs/manage-os#disable-features for instructions on how to make changes to this setting. )disabled_featuress    r   #_EnabledWithDisabledFeaturesMessager    1   s     "$569BBr   c                 .    t        fd| D        d      S )zGets the value of the key field of the given metadata list.

  Args:
    metadata: The metadata to look through.
    key: the key to look for

  Returns:
  The value of the key, None if the metadata field does not exist.
  c              3   V   K   | ]   }|j                   k(  s|j                   " y wN)keyvalue).0mdr$   s     r   	<genexpr>z$_GetMetadataValue.<locals>.<genexpr>E   s      <(Bbffmrxx(s   ))N)next)metadatar$   s    `r   _GetMetadataValuer+   ;   s     
<(<d	CCr   Nc                 &   d}d}d}d}|r.|t        j                  |      z  }t        j                  ||      S |j                  j                  }|r t        |t              }t        |t              }| j                  j                  }	|	r$|st        |	t              }|st        |	t              }|r?|j                         t        v rd}|r|t        |      z  }n%|dz  }n|t        ||      z  }n|t        ||      z  }t        j                  ||      S )z+Checks if the metadata is set up correctly.z"> Is the OS Config agent enabled? FNTYes)r   UnknownMessageResponser*   itemsr+   _ENABLE_OSCONFIG_DISABLED_FEATUREScommonInstanceMetadatalower_METADATA_BOOLr    r   )
projectr   r   	exceptionresponse_messagecontinue_flagenable_osconfigr   instance_metadataproject_metadatas
             r   Checkr=   H   s-   9-/,,Y77>>-)9:: ''--'(9;KLO)*;=OP 3399)*:<LMo+,<,>@ .0m	? 	 	E!*8]CC(=AA	'7	88r   r#   )__doc__
__future__r   r   r   9googlecloudsdk.command_lib.compute.os_config.troubleshootr   r5   r1   r2   r   r    r+   r=   r   r   r   <module>rA      sB    M &  ' K % 1 
@
D(9r   