
                             d 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Zd	Zd
Zd Zd Z G d d      Zd Z G d d      Zd Zy)z9Instance inventory gcloud commands declarative functions.    )absolute_import)division)unicode_literals)encoding)flags)
propertiesNz3projects/{project}/locations/{location}/instances/-zFprojects/{project}/locations/{location}/instances/{instance}/inventoryc                 N   t         j                  j                  j                  j	                         }|j
                  xs2 t         j                  j                  j                  j                         }t        j                  |d       t        j                  ||      |_        |S )zAdd parent field to list request.

  Args:
    unused_ref: A parsed resource reference; unused.
    args: The parsed args namespace from CLI
    request: List request for the API call

  Returns:
    Modified request that includes the name field.
  
--location)projectlocation)r   VALUEScorer   	GetOrFailr   computezoneGetr   ValidateZone	_LIST_URIformatparent)
unused_refargsrequestr   r   s        Klib/googlecloudsdk/command_lib/compute/os_config/inventories/declarative.pySetParentOnListRequestHookr   !   sy     ""**446']]Bj//77<<@@B(X|,##Gh#G'.	.    c                    |j                   }t        j                  j                  j                  j                         }|j                  xs2 t        j                  j                  j                  j                         }t        j                  |d       t        j                  |d       t        j                  |||      |_        |S )zAdd name field to Describe request.

  Args:
    unused_ref: A parsed resource reference; unused.
    args: The parsed args namespace from CLI
    request: Describe request for the API call

  Returns:
    Modified request that includes the name field.
  INSTANCEr
   )r   r   instance)r   r   r   r   r   r   r   r   r   r   r   ValidateInstancer   _DESCRIBE_URIr   name)r   r   r   r   r   r   s         r   SetNameOnDescribeRequestHookr#   5   s     ]](""**446']]Bj//77<<@@B(:.X|,%%8 & =',	.r   c                       e Zd ZdZd Zy)ListTableRowz.View model for table rows of inventories list.c                 f    || _         || _        || _        || _        || _        || _        || _        y N)instance_idinstance_nameosinstalled_packagesavailable_packagesupdate_timeosconfig_agent_version)selfr(   r)   os_long_namer+   r,   r-   r.   s           r   __init__zListTableRow.__init__O   s;     #D&DDG0D0D"D"8Dr   N__name__
__module____qualname____doc__r1    r   r   r%   r%   L   s
    6	9r   r%   c                 2   |j                   r| S |j                  r|j                  nd}g }| D ]  }d}d}|dk(  rW|j                  rKt        j                  t        j                  |j                              D ]  }d|v r|dz  }d|v s|dz  } |j                  t        |j                  j                  d      d   |j                  j                  |j                  j                  |||j                  |j                  j                  	              ||iS )
zCreate ListTableRow from ListInventory response.

  Args:
    inventory_list: Response from ListInventory
    args: gcloud invocation args

  Returns:
    ListTableRow
  basicr   fullinstalledPackage   availablePackage/)r(   r)   r0   r+   r,   r-   r.   )unmodified_api_responseviewitemssix
itervaluesr   MessageToDictappendr%   r"   splitosInfohostnamelongName
updateTimeosconfigAgentVersion)inventory_listr   rA   rows	inventoryr+   r,   vs           r   CreateTableViewResponseHookrQ   [   s    
!!iiW$	$!iv~)//~~h44Y__EF!"

!
1$

!
	 G
 	KK!,,S1"5#**33"))2211!,,#,#3#3#H#H	JK "$ r   c                       e Zd ZdZd Zy)DescribeTableViewz$View model for inventories describe.c                 .    || _         || _        || _        y r'   )r+   updatedable_packagessystem_information)r/   r+   rU   rV   s       r   r1   zDescribeTableView.__init__   s    0D 4D0Dr   Nr2   r7   r   r   rS   rS      s
    ,1r   rS   c                    i }i }| j                   r t        j                  | j                         }ni }| j                  |d<   |j                  dk(  r| j
                  r}t        j                  t        j                  | j
                              D ]H  }d|v r|}|d   }nd|v r|}|d   }ndD ](  }||v s||vrg ||<   ||   j                  ||           H J t        |||      S )zCreate DescribeTableView from GetInventory response.

  Args:
    response: Response from GetInventory
    args: gcloud invocation args

  Returns:
    DescribeTableView
  rK   r:   r;   r=   )	
yumPackage
aptPackagezypperPackagegoogetPackagezypperPatch
wuaPackage
qfePackage
cosPackagewindowsApplication)
rH   r   rE   rK   rA   rB   rC   rD   rF   rS   )	responser   	installed	availablerV   rP   destpkgpkg_types	            r   #CreateDescribeTableViewResponseHookrg      s     ))__!//@%-%8%8\"	YY&X^^^^H228>>BC	q	 "#""#(
 s?T!DN
x.

H
.
 D& 
9i1C	DDr   )r6   
__future__r   r   r   apitools.base.pyr   ,googlecloudsdk.command_lib.compute.os_configr   googlecloudsdk.corer   rC   r   r!   r   r#   r%   rQ   rS   rg   r7   r   r   <module>rl      sV    @ &  ' % > * 
B	3(.9 9!H1 1%Er   