5353
5454
5555
56- class ClientWrapper :
57- def __init__ (self , client , token ):
58- self ._client = client
59- self ._token = token
56+ class Driver :
57+ def __init__ (self , baseurl : str , token : str , timeout : int = 10 ):
58+ self .baseurl = baseurl
59+ self .token = token
60+ self .timeout = timeout
61+
62+ def admin (self ):
63+ return AdminDriver (baseurl = self .baseurl , token = self .token , timeout = self .timeout )
64+
65+ def api (self ):
66+ return ApiDriver (baseurl = self .baseurl , token = self .token , timeout = self .timeout )
67+
68+ def infra (self ):
69+ return InfraDriver (baseurl = self .baseurl , token = self .token , timeout = self .timeout )
6070
61- def __getattr__ (self , name ):
62- attr = getattr (self ._client , name )
63- if callable (attr ):
64- def wrapper (* args , ** kwargs ):
65- kwargs .setdefault ("ctx" , ClientContext ())
66- headers = kwargs .get ("headers" , {})
67- headers .setdefault ("Authorization" , "Bearer " + self ._token )
68- kwargs ["headers" ] = headers
69- return attr (* args , ** kwargs )
70- return wrapper
71- return attr
7271
7372class AdminDriver :
7473 def __init__ (self , baseurl : str , token : str , timeout : int = 10 ):
@@ -82,49 +81,41 @@ def filesystem(self):
8281 with admin_filesystem_connecpy .FilesystemServiceClient (self .baseurl , timeout = self .timeout ) as client :
8382 yield ClientWrapper (client , self .token )
8483
85-
8684 @contextmanager
8785 def image (self ):
8886 with admin_image_connecpy .ImageServiceClient (self .baseurl , timeout = self .timeout ) as client :
8987 yield ClientWrapper (client , self .token )
9088
91-
9289 @contextmanager
9390 def ip (self ):
9491 with admin_ip_connecpy .IPServiceClient (self .baseurl , timeout = self .timeout ) as client :
9592 yield ClientWrapper (client , self .token )
9693
97-
9894 @contextmanager
9995 def network (self ):
10096 with admin_network_connecpy .NetworkServiceClient (self .baseurl , timeout = self .timeout ) as client :
10197 yield ClientWrapper (client , self .token )
10298
103-
10499 @contextmanager
105100 def partition (self ):
106101 with admin_partition_connecpy .PartitionServiceClient (self .baseurl , timeout = self .timeout ) as client :
107102 yield ClientWrapper (client , self .token )
108103
109-
110104 @contextmanager
111105 def size (self ):
112106 with admin_size_connecpy .SizeServiceClient (self .baseurl , timeout = self .timeout ) as client :
113107 yield ClientWrapper (client , self .token )
114108
115-
116109 @contextmanager
117110 def tenant (self ):
118111 with admin_tenant_connecpy .TenantServiceClient (self .baseurl , timeout = self .timeout ) as client :
119112 yield ClientWrapper (client , self .token )
120113
121-
122114 @contextmanager
123115 def token (self ):
124116 with admin_token_connecpy .TokenServiceClient (self .baseurl , timeout = self .timeout ) as client :
125117 yield ClientWrapper (client , self .token )
126118
127-
128119class ApiDriver :
129120 def __init__ (self , baseurl : str , token : str , timeout : int = 10 ):
130121 self .baseurl = baseurl
@@ -137,79 +128,66 @@ def filesystem(self):
137128 with api_filesystem_connecpy .FilesystemServiceClient (self .baseurl , timeout = self .timeout ) as client :
138129 yield ClientWrapper (client , self .token )
139130
140-
141131 @contextmanager
142132 def health (self ):
143133 with api_health_connecpy .HealthServiceClient (self .baseurl , timeout = self .timeout ) as client :
144134 yield ClientWrapper (client , self .token )
145135
146-
147136 @contextmanager
148137 def image (self ):
149138 with api_image_connecpy .ImageServiceClient (self .baseurl , timeout = self .timeout ) as client :
150139 yield ClientWrapper (client , self .token )
151140
152-
153141 @contextmanager
154142 def ip (self ):
155143 with api_ip_connecpy .IPServiceClient (self .baseurl , timeout = self .timeout ) as client :
156144 yield ClientWrapper (client , self .token )
157145
158-
159146 @contextmanager
160147 def method (self ):
161148 with api_method_connecpy .MethodServiceClient (self .baseurl , timeout = self .timeout ) as client :
162149 yield ClientWrapper (client , self .token )
163150
164-
165151 @contextmanager
166152 def network (self ):
167153 with api_network_connecpy .NetworkServiceClient (self .baseurl , timeout = self .timeout ) as client :
168154 yield ClientWrapper (client , self .token )
169155
170-
171156 @contextmanager
172157 def partition (self ):
173158 with api_partition_connecpy .PartitionServiceClient (self .baseurl , timeout = self .timeout ) as client :
174159 yield ClientWrapper (client , self .token )
175160
176-
177161 @contextmanager
178162 def project (self ):
179163 with api_project_connecpy .ProjectServiceClient (self .baseurl , timeout = self .timeout ) as client :
180164 yield ClientWrapper (client , self .token )
181165
182-
183166 @contextmanager
184167 def size (self ):
185168 with api_size_connecpy .SizeServiceClient (self .baseurl , timeout = self .timeout ) as client :
186169 yield ClientWrapper (client , self .token )
187170
188-
189171 @contextmanager
190172 def tenant (self ):
191173 with api_tenant_connecpy .TenantServiceClient (self .baseurl , timeout = self .timeout ) as client :
192174 yield ClientWrapper (client , self .token )
193175
194-
195176 @contextmanager
196177 def token (self ):
197178 with api_token_connecpy .TokenServiceClient (self .baseurl , timeout = self .timeout ) as client :
198179 yield ClientWrapper (client , self .token )
199180
200-
201181 @contextmanager
202182 def user (self ):
203183 with api_user_connecpy .UserServiceClient (self .baseurl , timeout = self .timeout ) as client :
204184 yield ClientWrapper (client , self .token )
205185
206-
207186 @contextmanager
208187 def version (self ):
209188 with api_version_connecpy .VersionServiceClient (self .baseurl , timeout = self .timeout ) as client :
210189 yield ClientWrapper (client , self .token )
211190
212-
213191class InfraDriver :
214192 def __init__ (self , baseurl : str , token : str , timeout : int = 10 ):
215193 self .baseurl = baseurl
@@ -224,3 +202,19 @@ def bmc(self):
224202
225203
226204
205+ class ClientWrapper :
206+ def __init__ (self , client , token ):
207+ self ._client = client
208+ self ._token = token
209+
210+ def __getattr__ (self , name ):
211+ attr = getattr (self ._client , name )
212+ if callable (attr ):
213+ def wrapper (* args , ** kwargs ):
214+ kwargs .setdefault ("ctx" , ClientContext ())
215+ headers = kwargs .get ("headers" , {})
216+ headers .setdefault ("Authorization" , "Bearer " + self ._token )
217+ kwargs ["headers" ] = headers
218+ return attr (* args , ** kwargs )
219+ return wrapper
220+ return attr
0 commit comments