20
20
)
21
21
from manifester .settings import settings
22
22
23
- MAX_RESULTS_PER_PAGE = 50
24
- RESULTS_LIMIT = 10000
25
-
26
23
27
24
class Manifester :
28
25
"""Main Manifester class responsible for generating a manifest from the provided settings."""
29
26
30
- def __init__ (self , manifest_category , allocation_name = None , ** kwargs ):
31
- if isinstance (manifest_category , dict ):
32
- self .manifest_data = DynaBox (manifest_category )
33
- else :
34
- self .manifest_data = settings .manifest_category .get (manifest_category )
35
- if kwargs .get ("requester" ) is not None :
36
- self .requester = kwargs ["requester" ]
37
- self .is_mock = True
27
+ def __init__ (
28
+ self ,
29
+ manifest_category = None ,
30
+ allocation_name = None ,
31
+ minimal_init = False ,
32
+ proxies = None ,
33
+ ** kwargs ,
34
+ ):
35
+ if minimal_init :
36
+ self .offline_token = settings .get ("offline_token" )
37
+ self .token_request_url = settings .get ("url" ).get ("token_request" )
38
+ self .allocations_url = settings .get ("url" ).get ("allocations" )
39
+ self ._access_token = None
40
+ self ._allocations = None
41
+ self .token_request_data = {
42
+ "grant_type" : "refresh_token" ,
43
+ "client_id" : "rhsm-api" ,
44
+ "refresh_token" : self .offline_token ,
45
+ }
46
+ self .manifest_data = {"proxies" : proxies }
47
+ self .username_prefix = settings .get ("username_prefix" )
48
+ if kwargs .get ("requester" ) is not None :
49
+ self .requester = kwargs ["requester" ]
50
+ self .is_mock = True
51
+ else :
52
+ import requests
53
+
54
+ self .requester = requests
55
+ self .is_mock = False
38
56
else :
39
- import requests
57
+ if isinstance (manifest_category , dict ):
58
+ self .manifest_data = DynaBox (manifest_category )
59
+ else :
60
+ self .manifest_data = settings .manifest_category .get (manifest_category )
61
+ if kwargs .get ("requester" ) is not None :
62
+ self .requester = kwargs ["requester" ]
63
+ self .is_mock = True
64
+ else :
65
+ import requests
40
66
41
- self .requester = requests
42
- self .is_mock = False
43
- self .username_prefix = settings .username_prefix or self .manifest_data .username_prefix
44
- self .allocation_name = allocation_name or f"{ self .username_prefix } -" + "" .join (
45
- random .sample (string .ascii_letters , 8 )
46
- )
47
- self .manifest_name = Path (f"{ self .allocation_name } _manifest.zip" )
48
- self .offline_token = kwargs .get ("offline_token" , self .manifest_data .offline_token )
49
- self .subscription_data = self .manifest_data .subscription_data
50
- self .token_request_data = {
51
- "grant_type" : "refresh_token" ,
52
- "client_id" : "rhsm-api" ,
53
- "refresh_token" : self .offline_token ,
54
- }
55
- self .simple_content_access = kwargs .get (
56
- "simple_content_access" , self .manifest_data .simple_content_access
57
- )
58
- self .token_request_url = self .manifest_data .get ("url" ).get ("token_request" )
59
- self .allocations_url = self .manifest_data .get ("url" ).get ("allocations" )
60
- self ._access_token = None
61
- self ._allocations = None
62
- self ._subscription_pools = None
63
- self ._active_pools = []
64
- self .sat_version = process_sat_version (
65
- kwargs .get ("sat_version" , self .manifest_data .sat_version ),
66
- self .valid_sat_versions ,
67
- )
67
+ self .requester = requests
68
+ self .is_mock = False
69
+ self .username_prefix = (
70
+ self .manifest_data .get ("username_prefix" ) or settings .username_prefix
71
+ )
72
+ self .allocation_name = allocation_name or f"{ self .username_prefix } -" + "" .join (
73
+ random .sample (string .ascii_letters , 8 )
74
+ )
75
+ self .manifest_name = Path (f"{ self .allocation_name } _manifest.zip" )
76
+ self .offline_token = self .manifest_data .get (
77
+ "offline_token" , settings .get ("offline_token" )
78
+ )
79
+ self .subscription_data = self .manifest_data .subscription_data
80
+ self .token_request_data = {
81
+ "grant_type" : "refresh_token" ,
82
+ "client_id" : "rhsm-api" ,
83
+ "refresh_token" : self .offline_token ,
84
+ }
85
+ self .simple_content_access = kwargs .get (
86
+ "simple_content_access" , self .manifest_data .simple_content_access
87
+ )
88
+ self .token_request_url = self .manifest_data .get ("url" ).get ("token_request" )
89
+ self .allocations_url = self .manifest_data .get ("url" ).get ("allocations" )
90
+ self ._access_token = None
91
+ self ._allocations = None
92
+ self ._subscription_pools = None
93
+ self ._active_pools = []
94
+ self .sat_version = process_sat_version (
95
+ kwargs .get ("sat_version" , self .manifest_data .sat_version ),
96
+ self .valid_sat_versions ,
97
+ )
68
98
69
99
@property
70
100
def access_token (self ):
@@ -113,7 +143,7 @@ def subscription_allocations(self):
113
143
114
144
@property
115
145
def subscription_pools (self ):
116
- """Reprentation of subscription pools in an account."""
146
+ """Representation of subscription pools in an account."""
117
147
return fetch_paginated_data (self , "pools" )
118
148
119
149
def create_subscription_allocation (self ):
@@ -151,7 +181,7 @@ def create_subscription_allocation(self):
151
181
update_inventory (self .subscription_allocations )
152
182
return self .allocation_uuid
153
183
154
- def delete_subscription_allocation (self ):
184
+ def delete_subscription_allocation (self , uuid = None ):
155
185
"""Deletes the specified subscription allocation and returns the RHSM API's response."""
156
186
self ._access_token = None
157
187
data = {
@@ -163,9 +193,10 @@ def delete_subscription_allocation(self):
163
193
self .allocation_uuid = self .allocation_uuid .uuid
164
194
response = simple_retry (
165
195
self .requester .delete ,
166
- cmd_args = [f"{ self .allocations_url } /{ self .allocation_uuid } " ],
196
+ cmd_args = [f"{ self .allocations_url } /{ uuid if uuid else self .allocation_uuid } " ],
167
197
cmd_kwargs = data ,
168
198
)
199
+ update_inventory (self .subscription_allocations )
169
200
return response
170
201
171
202
def add_entitlements_to_allocation (self , pool_id , entitlement_quantity ):
@@ -367,6 +398,7 @@ def trigger_manifest_export(self):
367
398
local_file .write_bytes (manifest .content )
368
399
manifest .path = local_file
369
400
manifest .name = self .manifest_name
401
+ update_inventory (self .subscription_allocations )
370
402
return manifest
371
403
372
404
def get_manifest (self ):
@@ -392,6 +424,6 @@ def __enter__(self):
392
424
raise
393
425
394
426
def __exit__ (self , * tb_args ):
395
- """Deletes subscription allocation on teardown."""
427
+ """Deletes subscription allocation on teardown unless using CLI ."""
396
428
self .delete_subscription_allocation ()
397
429
update_inventory (self .subscription_allocations )
0 commit comments