
    Jh%                     H   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZ  e j"                   ej$                  e            Z G d d	e      Z G d
 de      Z G d de      Z G d dee	      ZdefdZdedefdZ edded      ZdddedddZy)    N)List)entitlementsutil)APIEndpoint)AdditionalInfo)UAConfig)
DataObjectFieldStringDataValue	data_listc                   H    e Zd Z eded       eded      gZdedefdZy)Reasoncodez'Short string that represents the reasondoctitlez9Longer string describing the reason - possibly translatedc                     || _         || _        y Nr   r   )selfr   r   s      M/usr/lib/python3/dist-packages/uaclient/api/u/pro/services/dependencies/v1.py__init__zReason.__init__   s    	
    N)__name__
__module____qualname__r
   r   fieldsstrr    r   r   r   r      s@    9	

 	K	
F C r   r   c                   H    e Zd Z eded       eded      gZdedefdZy)ServiceWithReasonname0Name of the Pro service this item corresponds tor   reasonz0Reason that this service is in the list it is inc                     || _         || _        y r   r"   r$   )r   r"   r$   s      r   r   zServiceWithReason.__init__.   s    	r   N)	r   r   r   r
   r   r   r   r   r   r   r   r   r!   r!       s@    B	

 	B	
F V r   r!   c                       e Zd Z eded       ed ee      d       ed ee      d      gZdede	e   de	e   fdZ
y	)
ServiceWithDependenciesr"   r#   r   incompatible_withzkList of Pro services this service is incompatible with. That means they cannot be enabled at the same time.
depends_onzwList of Pro services this service depends on. The services in this list must be enabled for this service to be enabled.c                .    || _         || _        || _        y r   r"   r)   r*   )r   r"   r)   r*   s       r   r   z ServiceWithDependencies.__init__L   s     	!2$r   N)r   r   r   r
   r   r   r!   r   r   r   r   r   r   r   r(   r(   3   s    B	

 	'(B		
 	'(P		
F0	% 	%   12		%
 *+	%r   r(   c                   B    e Zd Z ed ee      d      gZdee   fdZy)DependenciesResultservicesz*Each Pro service gets an item in this listr   c                    || _         y r   r/   )r   r/   s     r   r   zDependenciesResult.__init__a   s	     r   N)	r   r   r   r
   r   r(   r   r   r   r   r   r   r.   r.   X   s2    -.<	
F!D)@$A !r   r.   returnc                  (    t        t                     S r   )_dependenciesr   r   r   r   dependenciesr5   e   s    $$r   cfgc                    g }t         j                  D ]  } ||       }g }g }|j                  D ]e  }|j                  t	        |j
                  j                  t        |j                  j                  |j                  j                                     g |j                  D ]e  }|j                  t	        |j
                  j                  t        |j                  j                  |j                  j                                     g |j                  t        |j                  ||             ! t        |      S )a  
    This endpoint will return a full list of all service dependencies,
    regardless of the current system state. That means it will always return
    the same thing until new services are added, or until we add/remove
    dependencies between services.
    r   r&   r,   r1   )r   ENTITLEMENT_CLASSESincompatible_servicesappendr!   entitlementr"   r   	named_msgmsgrequired_servicesr(   r.   )r6   r/   ent_clsentr)   r*   ent_with_reasons          r   r4   r4   i   s$    H33 
cl
"88 		O$$!(4499!,66;;-77;;		  #44 		O!(4499!,66;;-77;;		 	#\\"3%	
1
> x00r   v1ServiceDependencies)versionr"   fnoptions_cls32Fz^
from uaclient.api.u.pro.services.dependencies.v1 import dependencies
result = dependencies()
z&pro api u.pro.services.dependencies.v1a  
{
    "services": [
        {
            "name": "one",
            "depends_on": [
                {
                    "name": "zero",
                    "reason": {
                        "code": "one-and-zero",
                        "title": "Service One requires service Zero."
                    }
                },
                ...
            ],
            "incompatible_with": [
                {
                    "name": "two",
                    "reason": {
                        "code": "one-and-two",
                        "title": "Services One and Two are not compatible."
                    }
                },
                ...
            ]
        },
        ...
    ]
}
)introduced_inrequires_networkexample_pythonresult_classexample_cliexample_json)loggingtypingr   uaclientr   r   uaclient.api.apir   uaclient.api.data_typesr   uaclient.configr   uaclient.data_typesr	   r
   r   r   	getLoggerreplace_top_level_logger_namer   LOGr   r!   r(   r.   r5   r4   endpoint_docr   r   r   <module>rZ      s      ' ( 2 $ M Mg:::8DEZ &
 &"%j "%J
!^ 
!%( %'1x '1$6 '1T 		  ';'r   