4
4
# Copyright © 2019, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
5
5
# SPDX-License-Identifier: Apache-2.0
6
6
7
+ """Base functionality for all services."""
8
+
9
+ import logging
7
10
import time
8
11
12
+ from deprecated .sphinx import versionadded
13
+
9
14
from .. import core
10
- from ..core import sasctl_command , HTTPError
15
+ from ..core import HTTPError , sasctl_command
11
16
from ..exceptions import JobTimeoutError
12
17
13
18
14
19
class Service (object ):
20
+ """Base class for all services. Should not be used directly."""
21
+
15
22
_SERVICE_ROOT = None
16
23
17
24
is_uuid = staticmethod (core .is_uuid )
18
25
get_link = staticmethod (core .get_link )
19
26
request_link = staticmethod (core .request_link )
20
27
28
+ log = logging .getLogger (__name__ )
29
+
21
30
@property
22
31
def _SERVICE_ROOT (self ):
23
32
raise NotImplementedError ()
24
33
25
34
@classmethod
26
35
def is_available (cls ):
27
- """Checks if the service is currently available.
36
+ """Check if the service is currently available.
28
37
29
38
Returns
30
39
-------
@@ -47,6 +56,22 @@ def info(cls):
47
56
48
57
@classmethod
49
58
def request (cls , verb , path , session = None , raw = False , ** kwargs ):
59
+ """Make an HTTP request with a session.
60
+
61
+ Parameters
62
+ ----------
63
+ verb : str
64
+ path : str
65
+ session : Session, optional
66
+ Defaults to `current_session()`.
67
+ raw : bool
68
+ Whether to return the raw `Response` object. Defaults to False.
69
+ kwargs : any
70
+
71
+ Returns
72
+ -------
73
+
74
+ """
50
75
session = session or core .current_session ()
51
76
52
77
if session is None :
@@ -234,7 +259,6 @@ def update_item(cls, item):
234
259
None
235
260
236
261
"""
237
-
238
262
headers = getattr (item , '_headers' , None )
239
263
if headers is None or headers .get ('etag' ) is None :
240
264
raise ValueError (
@@ -263,10 +287,15 @@ def delete_item(cls, item):
263
287
None
264
288
265
289
"""
290
+ item_name = str (item )
266
291
267
292
# Try to find the item if the id can't be found
268
293
if not (isinstance (item , dict ) and 'id' in item ):
269
294
item = get_item (cls , item )
295
+ if item is None :
296
+ cls .log .info ("Object '%s' not found. Skipping delete."
297
+ % item_name )
298
+ return
270
299
271
300
if isinstance (item , dict ) and 'id' in item :
272
301
item = item ['id' ]
0 commit comments