Package cm_api :: Package endpoints :: Module types
[hide private]
[frames] | no frames]

Source Code for Module cm_api.endpoints.types

   1  # Licensed to Cloudera, Inc. under one 
   2  # or more contributor license agreements.  See the NOTICE file 
   3  # distributed with this work for additional information 
   4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
   5  # to you under the Apache License, Version 2.0 (the 
   6  # "License"); you may not use this file except in compliance 
   7  # with the License.  You may obtain a copy of the License at 
   8  # 
   9  #     http://www.apache.org/licenses/LICENSE-2.0 
  10  # 
  11  # Unless required by applicable law or agreed to in writing, software 
  12  # distributed under the License is distributed on an "AS IS" BASIS, 
  13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  14  # See the License for the specific language governing permissions and 
  15  # limitations under the License. 
  16   
  17  try: 
  18    import json 
  19  except ImportError: 
  20    import simplejson as json 
  21   
  22  import copy 
  23  import datetime 
  24  import time 
  25   
  26  __docformat__ = "epytext" 
27 28 -class Attr(object):
29 """ 30 Encapsulates information about an attribute in the JSON encoding of the 31 object. It identifies properties of the attribute such as whether it's 32 read-only, its type, etc. 33 """ 34 DATE_FMT = "%Y-%m-%dT%H:%M:%S.%fZ" 35
36 - def __init__(self, atype=None, rw=True, is_api_list=False):
37 self._atype = atype 38 self._is_api_list = is_api_list 39 self.rw = rw
40
41 - def to_json(self, value, preserve_ro):
42 """ 43 Returns the JSON encoding of the given attribute value. 44 45 If the value has a 'to_json_dict' object, that method is called. Otherwise, 46 the following values are returned for each input type: 47 - datetime.datetime: string with the API representation of a date. 48 - dictionary: if 'atype' is ApiConfig, a list of ApiConfig objects. 49 - python list: python list (or ApiList) with JSON encoding of items 50 - the raw value otherwise 51 """ 52 if hasattr(value, 'to_json_dict'): 53 return value.to_json_dict(preserve_ro) 54 elif isinstance(value, dict) and self._atype == ApiConfig: 55 return config_to_api_list(value) 56 elif isinstance(value, datetime.datetime): 57 return value.strftime(self.DATE_FMT) 58 elif isinstance(value, list) or isinstance(value, tuple): 59 if self._is_api_list: 60 return ApiList(value).to_json_dict() 61 else: 62 return [ self.to_json(x, preserve_ro) for x in value ] 63 else: 64 return value
65
66 - def from_json(self, resource_root, data):
67 """ 68 Parses the given JSON value into an appropriate python object. 69 70 This means: 71 - a datetime.datetime if 'atype' is datetime.datetime 72 - a converted config dictionary or config list if 'atype' is ApiConfig 73 - if the attr is an API list, an ApiList with instances of 'atype' 74 - an instance of 'atype' if it has a 'from_json_dict' method 75 - a python list with decoded versions of the member objects if the input 76 is a python list. 77 - the raw value otherwise 78 """ 79 if data is None: 80 return None 81 82 if self._atype == datetime.datetime: 83 return datetime.datetime.strptime(data, self.DATE_FMT) 84 elif self._atype == ApiConfig: 85 # ApiConfig is special. We want a python dictionary for summary views, 86 # but an ApiList for full views. Try to detect each case from the JSON 87 # data. 88 if not data['items']: 89 return { } 90 first = data['items'][0] 91 return json_to_config(data, len(first) == 2) 92 elif self._is_api_list: 93 return ApiList.from_json_dict(data, resource_root, self._atype) 94 elif isinstance(data, list): 95 return [ self.from_json(resource_root, x) for x in data ] 96 elif hasattr(self._atype, 'from_json_dict'): 97 return self._atype.from_json_dict(data, resource_root) 98 else: 99 return data
100
101 -class ROAttr(Attr):
102 """ 103 Subclass that just defines the attribute as read-only. 104 """
105 - def __init__(self, atype=None, is_api_list=False):
106 Attr.__init__(self, atype=atype, rw=False, is_api_list=is_api_list)
107
108 109 -def check_api_version(resource_root, min_version):
110 """ 111 Checks if the resource_root's API version it at least the given minimum 112 version. 113 """ 114 if resource_root.version < min_version: 115 raise Exception("API version %s is required but %s is in use." 116 % (min_version, resource_root.version))
117
118 119 -def call(method, path, ret_type, 120 ret_is_list=False, data=None, params=None, api_version=1):
121 """ 122 Generic function for calling a resource method and automatically dealing with 123 serialization of parameters and deserialization of return values. 124 125 @param method: method to call (must be bound to a resource; 126 e.g., "resource_root.get"). 127 @param path: the full path of the API method to call. 128 @param ret_type: return type of the call. 129 @param ret_is_list: whether the return type is an ApiList. 130 @param data: Optional data to send as payload to the call. 131 @param params: Optional query parameters for the call. 132 @param api_version: minimum API version for the call. 133 """ 134 check_api_version(method.im_self, api_version) 135 if data is not None: 136 data = json.dumps(Attr(is_api_list=True).to_json(data, False)) 137 ret = method(path, data=data, params=params) 138 else: 139 ret = method(path, params=params) 140 if ret_type is None: 141 return 142 elif ret_is_list: 143 return ApiList.from_json_dict(ret, method.im_self, ret_type) 144 elif isinstance(ret, list): 145 return [ ret_type.from_json_dict(x, method.im_self) for x in ret ] 146 else: 147 return ret_type.from_json_dict(ret, method.im_self)
148
149 -class BaseApiObject(object):
150 """ 151 The BaseApiObject helps with (de)serialization from/to JSON. 152 153 The derived class has two ways of defining custom attributes: 154 - Overwriting the '_ATTRIBUTES' field with the attribute dictionary 155 - Override the _get_attributes() method, in case static initialization of 156 the above field is not possible. 157 158 It's recommended that the _get_attributes() implementation do caching to 159 avoid computing the dictionary on every invocation. 160 161 The derived class's constructor must call the base class's init() static 162 method. All constructor arguments (aside from self and resource_root) must 163 be keywords arguments with default values (typically None), or 164 from_json_dict() will not work. 165 """ 166 167 _ATTRIBUTES = { } 168 _WHITELIST = ( '_resource_root', '_attributes' ) 169 170 @classmethod
171 - def _get_attributes(cls):
172 """ 173 Returns a map of property names to attr instances (or None for default 174 attribute behavior) describing the properties of the object. 175 176 By default, this method will return the class's _ATTRIBUTES field. 177 Classes can override this method to do custom initialization of the 178 attributes when needed. 179 """ 180 return cls._ATTRIBUTES
181 182 @staticmethod
183 - def init(obj, resource_root, attrs=None):
184 """ 185 Wraper around the real constructor to avoid issues with the 'self' 186 argument. Call like this, from a subclass's constructor: 187 188 - BaseApiObject.init(self, locals()) 189 """ 190 # This works around http://bugs.python.org/issue2646 191 # We use unicode strings as keys in kwargs. 192 str_attrs = { } 193 if attrs: 194 for k, v in attrs.iteritems(): 195 if k not in ('self', 'resource_root'): 196 str_attrs[k] = v 197 BaseApiObject.__init__(obj, resource_root, **str_attrs)
198
199 - def __init__(self, resource_root, **attrs):
200 """ 201 Initializes internal state and sets all known writable properties of the 202 object to None. Then initializes the properties given in the provided 203 attributes dictionary. 204 205 @param resource_root: API resource object. 206 @param attrs: optional dictionary of attributes to set. This should only 207 contain r/w attributes. 208 """ 209 self._resource_root = resource_root 210 211 for name, attr in self._get_attributes().iteritems(): 212 object.__setattr__(self, name, None) 213 if attrs: 214 self._set_attrs(attrs, from_json=False)
215
216 - def _set_attrs(self, attrs, allow_ro=False, from_json=True):
217 """ 218 Sets all the attributes in the dictionary. Optionally, allows setting 219 read-only attributes (e.g. when deserializing from JSON) and skipping 220 JSON deserialization of values. 221 """ 222 for k, v in attrs.iteritems(): 223 try: 224 attr = self._check_attr(k, allow_ro) 225 except AttributeError: 226 continue 227 if attr and from_json: 228 v = attr.from_json(self._get_resource_root(), v) 229 object.__setattr__(self, k, v)
230
231 - def __setattr__(self, name, val):
232 if name not in BaseApiObject._WHITELIST: 233 self._check_attr(name, False) 234 object.__setattr__(self, name, val)
235
236 - def _check_attr(self, name, allow_ro):
237 if name not in self._get_attributes(): 238 raise AttributeError('Invalid property %s for class %s.' % 239 (name, self.__class__.__name__)) 240 attr = self._get_attributes()[name] 241 if not allow_ro and attr and not attr.rw: 242 raise AttributeError('Attribute %s of class %s is read only.' % 243 (name, self.__class__.__name__)) 244 return attr
245
246 - def _get_resource_root(self):
247 return self._resource_root
248
249 - def _update(self, api_obj):
250 """Copy state from api_obj to this object.""" 251 if not isinstance(self, api_obj.__class__): 252 raise ValueError( 253 "Class %s does not derive from %s; cannot update attributes." % 254 (self.__class__, api_obj.__class__)) 255 256 for name in self._get_attributes().keys(): 257 try: 258 val = getattr(api_obj, name) 259 setattr(self, name, val) 260 except AttributeError, ignored: 261 pass
262
263 - def to_json_dict(self, preserve_ro=False):
264 dic = { } 265 for name, attr in self._get_attributes().iteritems(): 266 if not preserve_ro and attr and not attr.rw: 267 continue 268 try: 269 value = getattr(self, name) 270 if value is not None: 271 if attr: 272 dic[name] = attr.to_json(value, preserve_ro) 273 else: 274 dic[name] = value 275 except AttributeError: 276 pass 277 return dic
278
279 - def __str__(self):
280 """ 281 Default implementation of __str__. Uses the type name and the first 282 attribute retrieved from the attribute map to create the string. 283 """ 284 name = self._get_attributes().keys()[0] 285 value = getattr(self, name, None) 286 return "<%s>: %s = %s" % (self.__class__.__name__, name, value)
287 288 @classmethod
289 - def from_json_dict(cls, dic, resource_root):
290 obj = cls(resource_root) 291 obj._set_attrs(dic, allow_ro=True) 292 return obj
293
294 -class BaseApiResource(BaseApiObject):
295 """ 296 A specialization of BaseApiObject that provides some utility methods for 297 resources. This class allows easier serialization / deserialization of 298 parameters and return values. 299 """ 300
301 - def _api_version(self):
302 """ 303 Returns the minimum API version for this resource. Defaults to 1. 304 """ 305 return 1
306
307 - def _path(self):
308 """ 309 Returns the path to the resource. 310 311 e.g., for a service 'foo' in cluster 'bar', this should return 312 '/clusters/bar/services/foo'. 313 """ 314 raise NotImplementedError
315
316 - def _require_min_api_version(self, version):
317 """ 318 Raise an exception if the version of the api is less than the given version. 319 320 @param version: The minimum required version. 321 """ 322 actual_version = self._get_resource_root().version 323 version = max(version, self._api_version()) 324 if actual_version < version: 325 raise Exception("API version %s is required but %s is in use." 326 % (version, actual_version))
327
328 - def _cmd(self, command, data=None, params=None, api_version=1):
329 """ 330 Invokes a command on the resource. Commands are expected to be under the 331 "commands/" sub-resource. 332 """ 333 return self._post("commands/" + command, ApiCommand, 334 data=data, params=params, api_version=api_version)
335
336 - def _get_config(self, rel_path, view, api_version=1):
337 """ 338 Retrieves an ApiConfig list from the given relative path. 339 """ 340 self._require_min_api_version(api_version) 341 params = view and dict(view=view) or None 342 resp = self._get_resource_root().get(self._path() + '/' + rel_path, 343 params=params) 344 return json_to_config(resp, view == 'full')
345
346 - def _update_config(self, rel_path, config, api_version=1):
347 self._require_min_api_version(api_version) 348 resp = self._get_resource_root().put(self._path() + '/' + rel_path, 349 data=config_to_json(config)) 350 return json_to_config(resp, False)
351
352 - def _delete(self, rel_path, ret_type, ret_is_list=False, params=None, 353 api_version=1):
354 return self._call('delete', rel_path, ret_type, ret_is_list, None, params, 355 api_version)
356
357 - def _get(self, rel_path, ret_type, ret_is_list=False, params=None, 358 api_version=1):
359 return self._call('get', rel_path, ret_type, ret_is_list, None, params, 360 api_version)
361
362 - def _post(self, rel_path, ret_type, ret_is_list=False, data=None, params=None, 363 api_version=1):
364 return self._call('post', rel_path, ret_type, ret_is_list, data, params, 365 api_version)
366
367 - def _put(self, rel_path, ret_type, ret_is_list=False, data=None, params=None, 368 api_version=1):
369 return self._call('put', rel_path, ret_type, ret_is_list, data, params, 370 api_version)
371
372 - def _call(self, method, rel_path, ret_type, ret_is_list=False, data=None, 373 params=None, api_version=1):
374 path = self._path() 375 if rel_path: 376 path += '/' + rel_path 377 return call(getattr(self._get_resource_root(), method), 378 path, 379 ret_type, 380 ret_is_list, 381 data, 382 params, 383 api_version)
384
385 -class ApiList(BaseApiObject):
386 """A list of some api object""" 387 LIST_KEY = "items" 388
389 - def __init__(self, objects, resource_root=None, **attrs):
390 BaseApiObject.__init__(self, resource_root, **attrs) 391 # Bypass checks in BaseApiObject.__setattr__ 392 object.__setattr__(self, 'objects', objects)
393
394 - def __str__(self):
395 return "<ApiList>(%d): [%s]" % ( 396 len(self.objects), 397 ", ".join([str(item) for item in self.objects]))
398
399 - def to_json_dict(self, preserve_ro=False):
400 ret = BaseApiObject.to_json_dict(self, preserve_ro) 401 attr = Attr() 402 ret[ApiList.LIST_KEY] = [ attr.to_json(x, preserve_ro) for x in self.objects ] 403 return ret
404
405 - def __len__(self):
406 return self.objects.__len__()
407
408 - def __iter__(self):
409 return self.objects.__iter__()
410
411 - def __getitem__(self, i):
412 return self.objects.__getitem__(i)
413
414 - def __getslice(self, i, j):
415 return self.objects.__getslice__(i, j)
416 417 @classmethod
418 - def from_json_dict(cls, dic, resource_root, member_cls=None):
419 if not member_cls: 420 member_cls = cls._MEMBER_CLASS 421 attr = Attr(atype=member_cls) 422 items = [] 423 if ApiList.LIST_KEY in dic: 424 items = [ attr.from_json(resource_root, x) for x in dic[ApiList.LIST_KEY] ] 425 ret = cls(items) 426 # If the class declares custom attributes, populate them based on the input 427 # dict. The check avoids extra overhead for the common case, where we just 428 # have a plain list. _set_attrs() also does not understand the "items" 429 # attribute, so it can't be in the input data. 430 if cls._ATTRIBUTES: 431 if ApiList.LIST_KEY in dic: 432 dic = copy.copy(dic) 433 del dic[ApiList.LIST_KEY] 434 ret._set_attrs(dic, allow_ro=True) 435 return ret
436
437 -class ApiHostRef(BaseApiObject):
438 _ATTRIBUTES = { 439 'hostId' : None, 440 } 441
442 - def __init__(self, resource_root, hostId=None):
443 BaseApiObject.init(self, resource_root, locals())
444
445 - def __str__(self):
446 return "<ApiHostRef>: %s" % (self.hostId)
447
448 -class ApiServiceRef(BaseApiObject):
449 _ATTRIBUTES = { 450 'clusterName' : None, 451 'serviceName' : None, 452 'peerName' : None, 453 } 454
455 - def __init__(self, resource_root, serviceName=None, clusterName=None, 456 peerName=None):
457 BaseApiObject.init(self, resource_root, locals())
458
459 -class ApiClusterRef(BaseApiObject):
460 _ATTRIBUTES = { 461 'clusterName' : None, 462 } 463
464 - def __init__(self, resource_root, clusterName = None):
465 BaseApiObject.init(self, resource_root, locals())
466
467 -class ApiRoleRef(BaseApiObject):
468 _ATTRIBUTES = { 469 'clusterName' : None, 470 'serviceName' : None, 471 'roleName' : None, 472 } 473
474 - def __init__(self, resource_root, serviceName=None, roleName=None, 475 clusterName=None):
476 BaseApiObject.init(self, resource_root, locals())
477
478 -class ApiRoleConfigGroupRef(BaseApiObject):
479 _ATTRIBUTES = { 480 'roleConfigGroupName' : None, 481 } 482
483 - def __init__(self, resource_root, roleConfigGroupName=None):
484 BaseApiObject.init(self, resource_root, locals())
485
486 -class ApiCommand(BaseApiObject):
487 SYNCHRONOUS_COMMAND_ID = -1 488 489 @classmethod
490 - def _get_attributes(cls):
491 if not cls.__dict__.has_key('_ATTRIBUTES'): 492 cls._ATTRIBUTES = { 493 'id' : ROAttr(), 494 'name' : ROAttr(), 495 'startTime' : ROAttr(datetime.datetime), 496 'endTime' : ROAttr(datetime.datetime), 497 'active' : ROAttr(), 498 'success' : ROAttr(), 499 'resultMessage' : ROAttr(), 500 'clusterRef' : ROAttr(ApiClusterRef), 501 'serviceRef' : ROAttr(ApiServiceRef), 502 'roleRef' : ROAttr(ApiRoleRef), 503 'hostRef' : ROAttr(ApiHostRef), 504 'children' : ROAttr(ApiCommand, is_api_list=True), 505 'parent' : ROAttr(ApiCommand), 506 'resultDataUrl' : ROAttr(), 507 'canRetry' : ROAttr(), 508 } 509 return cls._ATTRIBUTES
510
511 - def __str__(self):
512 return "<ApiCommand>: '%s' (id: %s; active: %s; success: %s)" % ( 513 self.name, self.id, self.active, self.success)
514
515 - def _path(self):
516 return '/commands/%d' % self.id
517
518 - def fetch(self):
519 """ 520 Retrieve updated data about the command from the server. 521 522 @return: A new ApiCommand object. 523 """ 524 if self.id == ApiCommand.SYNCHRONOUS_COMMAND_ID: 525 return self 526 527 resp = self._get_resource_root().get(self._path()) 528 return ApiCommand.from_json_dict(resp, self._get_resource_root())
529
530 - def wait(self, timeout=None):
531 """ 532 Wait for command to finish. 533 534 @param timeout: (Optional) Max amount of time (in seconds) to wait. Wait 535 forever by default. 536 @return: The final ApiCommand object, containing the last known state. 537 The command may still be running in case of timeout. 538 """ 539 if self.id == ApiCommand.SYNCHRONOUS_COMMAND_ID: 540 return self 541 542 SLEEP_SEC = 5 543 544 if timeout is None: 545 deadline = None 546 else: 547 deadline = time.time() + timeout 548 549 while True: 550 cmd = self.fetch() 551 if not cmd.active: 552 return cmd 553 554 if deadline is not None: 555 now = time.time() 556 if deadline < now: 557 return cmd 558 else: 559 time.sleep(min(SLEEP_SEC, deadline - now)) 560 else: 561 time.sleep(SLEEP_SEC)
562 563
564 - def abort(self):
565 """ 566 Abort a running command. 567 568 @return: A new ApiCommand object with the updated information. 569 """ 570 if self.id == ApiCommand.SYNCHRONOUS_COMMAND_ID: 571 return self 572 573 path = self._path() + '/abort' 574 resp = self._get_resource_root().post(path) 575 return ApiCommand.from_json_dict(resp, self._get_resource_root())
576
577 - def retry(self):
578 """ 579 Retry a failed or aborted command. 580 581 @return: A new ApiCommand object with the updated information. 582 """ 583 path = self._path() + '/retry' 584 resp = self._get_resource_root().post(path) 585 return ApiCommand.from_json_dict(resp, self._get_resource_root())
586
587 -class ApiBulkCommandList(ApiList):
588 _ATTRIBUTES = { 589 'errors' : ROAttr(), 590 } 591 _MEMBER_CLASS = ApiCommand
592
593 -class ApiCommandMetadata(BaseApiObject):
594 _ATTRIBUTES = { 595 'name' : ROAttr(), 596 'argSchema' : ROAttr(), 597 } 598
599 - def __init__(self, resource_root):
600 BaseApiObject.init(self, resource_root)
601
602 - def __str__(self):
603 return "<ApiCommandMetadata>: %s (%s)" % (self.name, self.argSchema)
604
605 # 606 # Metrics. 607 # 608 609 -class ApiMetricData(BaseApiObject):
610 """Metric reading data.""" 611 612 _ATTRIBUTES = { 613 'timestamp' : ROAttr(datetime.datetime), 614 'value' : ROAttr(), 615 } 616
617 - def __init__(self, resource_root):
618 BaseApiObject.init(self, resource_root)
619
620 621 -class ApiMetric(BaseApiObject):
622 """Metric information.""" 623 624 _ATTRIBUTES = { 625 'name' : ROAttr(), 626 'context' : ROAttr(), 627 'unit' : ROAttr(), 628 'data' : ROAttr(ApiMetricData), 629 'displayName' : ROAttr(), 630 'description' : ROAttr(), 631 } 632
633 - def __init__(self, resource_root):
634 BaseApiObject.init(self, resource_root)
635
636 # 637 # Activities. 638 # 639 640 -class ApiActivity(BaseApiObject):
641 _ATTRIBUTES = { 642 'name' : ROAttr(), 643 'type' : ROAttr(), 644 'parent' : ROAttr(), 645 'startTime' : ROAttr(), 646 'finishTime' : ROAttr(), 647 'id' : ROAttr(), 648 'status' : ROAttr(), 649 'user' : ROAttr(), 650 'group' : ROAttr(), 651 'inputDir' : ROAttr(), 652 'outputDir' : ROAttr(), 653 'mapper' : ROAttr(), 654 'combiner' : ROAttr(), 655 'reducer' : ROAttr(), 656 'queueName' : ROAttr(), 657 'schedulerPriority' : ROAttr(), 658 } 659
660 - def __init__(self, resource_root):
661 BaseApiObject.init(self, resource_root)
662
663 - def __str__(self):
664 return "<ApiActivity>: %s (%s)" % (self.name, self.status)
665
666 # 667 # Replication 668 # 669 670 -class ApiCmPeer(BaseApiObject):
671 _ATTRIBUTES = { 672 'name' : None, 673 'url' : None, 674 'username' : None, 675 'password' : None, 676 'type' : None, 677 'clouderaManagerCreatedUser' : None, 678 } 679
680 - def __str__(self):
681 return "<ApiPeer>: %s (%s)" % (self.name, self.url)
682
683 -class ApiLicensedFeatureUsage(BaseApiObject):
684 _ATTRIBUTES = { 685 'totals' : ROAttr(), 686 'clusters' : ROAttr(), 687 }
688
689 -class ApiReplicationDiagnosticsCollectionArgs(BaseApiObject):
690 _ATTRIBUTES = { 691 'commands' : ROAttr(), 692 'ticketNumber' : ROAttr(), 693 'comments' : ROAttr(), 694 'phoneHome' : ROAttr(), 695 }
696
697 -class ApiHdfsReplicationArguments(BaseApiObject):
698 _ATTRIBUTES = { 699 'sourceService' : Attr(ApiServiceRef), 700 'sourcePath' : None, 701 'destinationPath' : None, 702 'mapreduceServiceName' : None, 703 'userName' : None, 704 'sourceUser' : None, 705 'numMaps' : None, 706 'dryRun' : None, 707 'bandwidthPerMap' : None, 708 'logPath' : None, 709 'schedulerPoolName' : None, 710 'abortOnError' : None, 711 'preservePermissions' : None, 712 'preserveBlockSize' : None, 713 'preserveReplicationCount' : None, 714 'removeMissingFiles' : None, 715 'skipChecksumChecks' : None, 716 'skipListingChecksumChecks' : None, 717 'skipTrash' : None, 718 'replicationStrategy' : None, 719 'preserveXAttrs' : None, 720 'exclusionFilters' : None, 721 'raiseSnapshotDiffFailures' : None, 722 }
723
724 -class ApiHdfsCloudReplicationArguments(ApiHdfsReplicationArguments):
725 @classmethod
726 - def _get_attributes(cls):
727 if not cls.__dict__.has_key('_ATTRIBUTES'): 728 attrs = { 729 'sourceAccount' : None, 730 'destinationAccount' : None, 731 } 732 attrs.update(ApiHdfsReplicationArguments._get_attributes()) 733 cls._ATTRIBUTES = attrs 734 return cls._ATTRIBUTES
735
736 -class ApiHdfsReplicationResult(BaseApiObject):
737 _ATTRIBUTES = { 738 'progress' : ROAttr(), 739 'counters' : ROAttr(), 740 'numBytesDryRun' : ROAttr(), 741 'numFilesDryRun' : ROAttr(), 742 'numFilesExpected' : ROAttr(), 743 'numBytesExpected' : ROAttr(), 744 'numFilesCopied' : ROAttr(), 745 'numBytesCopied' : ROAttr(), 746 'numFilesSkipped' : ROAttr(), 747 'numBytesSkipped' : ROAttr(), 748 'numFilesDeleted' : ROAttr(), 749 'numFilesCopyFailed' : ROAttr(), 750 'numBytesCopyFailed' : ROAttr(), 751 'setupError' : ROAttr(), 752 'jobId' : ROAttr(), 753 'jobDetailsUri' : ROAttr(), 754 'dryRun' : ROAttr(), 755 'snapshottedDirs' : ROAttr(), 756 'failedFiles' : ROAttr(), 757 'runAsUser' : ROAttr(), 758 'runOnSourceAsUser' : ROAttr(), 759 'remainingTime' : ROAttr(), 760 'throughput' : ROAttr(), 761 'estimatedCompletionTime' : ROAttr(), 762 }
763
764 -class ApiHiveTable(BaseApiObject):
765 _ATTRIBUTES = { 766 'database' : None, 767 'tableName' : None, 768 } 769
770 - def __str__(self):
771 return "<ApiHiveTable>: %s, %s" % (self.database, self.tableName)
772
773 -class ApiImpalaUDF(BaseApiObject):
774 _ATTRIBUTES = { 775 'database' : ROAttr(), 776 'signature' : ROAttr(), 777 } 778
779 - def __str__(self):
780 return "<ApiImpalaUDF>: %s, %s" % (self.database, self.signature)
781
782 -class ApiHiveUDF(BaseApiObject):
783 _ATTRIBUTES = { 784 'database' : ROAttr(), 785 'signature' : ROAttr(), 786 } 787
788 - def __str__(self):
789 return "<ApiHiveUDF>: %s, %s" % (self.database, self.signature)
790
791 -class ApiHiveReplicationArguments(BaseApiObject):
792 _ATTRIBUTES = { 793 'sourceService' : Attr(ApiServiceRef), 794 'tableFilters' : Attr(ApiHiveTable), 795 'exportDir' : None, 796 'force' : None, 797 'replicateData' : None, 798 'hdfsArguments' : Attr(ApiHdfsReplicationArguments), 799 'dryRun' : None, 800 'replicateImpalaMetadata' : None, 801 'runInvalidateMetadata' : None, 802 'numThreads' : None, 803 }
804
805 -class ApiHiveCloudReplicationArguments(ApiHiveReplicationArguments):
806 @classmethod
807 - def _get_attributes(cls):
808 if not cls.__dict__.has_key('_ATTRIBUTES'): 809 attrs = { 810 'sourceAccount' : None, 811 'destinationAccount' : None, 812 'cloudRootPath': None, 813 'replicationOption': None 814 } 815 attrs.update(ApiHiveReplicationArguments._get_attributes()) 816 cls._ATTRIBUTES = attrs 817 return cls._ATTRIBUTES
818
819 -class ApiHiveReplicationResult(BaseApiObject):
820 _ATTRIBUTES = { 821 'tableCount' : ROAttr(), 822 'tables' : ROAttr(ApiHiveTable), 823 'impalaUDFCount' : ROAttr(), 824 'impalaUDFs' : ROAttr(ApiImpalaUDF), 825 'hiveUDFCount' : ROAttr(), 826 'hiveUDFs' : ROAttr(ApiHiveUDF), 827 'errorCount' : ROAttr(), 828 'errors' : ROAttr(), 829 'dataReplicationResult' : ROAttr(ApiHdfsReplicationResult), 830 'dryRun' : ROAttr(), 831 'runAsUser' : ROAttr(), 832 'runOnSourceAsUser' : ROAttr(), 833 'phase' : ROAttr(), 834 'statsAvailable' : ROAttr(), 835 'dbProcessed' : ROAttr(), 836 'tableProcessed' : ROAttr(), 837 'partitionProcessed' : ROAttr(), 838 'functionProcessed' : ROAttr(), 839 'indexProcessed' : ROAttr(), 840 'statsProcessed' : ROAttr(), 841 'dbExpected' : ROAttr(), 842 'tableExpected' : ROAttr(), 843 'partitionExpected' : ROAttr(), 844 'functionExpected' : ROAttr(), 845 'indexExpected' : ROAttr(), 846 'statsExpected' : ROAttr(), 847 }
848
849 -class ApiReplicationCommand(ApiCommand):
850 @classmethod
851 - def _get_attributes(cls):
852 if not cls.__dict__.has_key('_ATTRIBUTES'): 853 attrs = { 854 'hdfsResult' : ROAttr(ApiHdfsReplicationResult), 855 'hiveResult' : ROAttr(ApiHiveReplicationResult), 856 } 857 attrs.update(ApiCommand._get_attributes()) 858 cls._ATTRIBUTES = attrs 859 return cls._ATTRIBUTES
860
861 -class ApiReplicationSchedule2(BaseApiObject):
862 _ATTRIBUTES = { 863 'startTime' : Attr(datetime.datetime), 864 'endTime' : Attr(datetime.datetime), 865 'interval' : None, 866 'intervalUnit' : None, 867 'paused' : None, 868 'hdfsArguments' : Attr(ApiHdfsReplicationArguments), 869 'hiveArguments' : Attr(ApiHiveReplicationArguments), 870 'hdfsCloudArguments' : Attr(ApiHdfsCloudReplicationArguments), 871 'hiveCloudArguments' : Attr(ApiHiveCloudReplicationArguments), 872 'alertOnStart' : None, 873 'alertOnSuccess' : None, 874 'alertOnFail' : None, 875 'alertOnAbort' : None, 876 'id' : ROAttr(), 877 'nextRun' : ROAttr(datetime.datetime), 878 'history' : ROAttr(ApiReplicationCommand), 879 'active' : None 880 }
881
882 -class ApiReplicationSchedule(BaseApiObject):
883 _ATTRIBUTES = { 884 'startTime' : Attr(datetime.datetime), 885 'endTime' : Attr(datetime.datetime), 886 'interval' : None, 887 'intervalUnit' : None, 888 'paused' : None, 889 'hdfsArguments' : Attr(ApiHdfsReplicationArguments), 890 'hiveArguments' : Attr(ApiHiveReplicationArguments), 891 'hdfsCloudArguments' : Attr(ApiHdfsCloudReplicationArguments), 892 'hiveCloudArguments' : Attr(ApiHiveCloudReplicationArguments), 893 'alertOnStart' : None, 894 'alertOnSuccess' : None, 895 'alertOnFail' : None, 896 'alertOnAbort' : None, 897 'id' : ROAttr(), 898 'displayName' : ROAttr(), 899 'description' : ROAttr(), 900 'nextRun' : ROAttr(datetime.datetime), 901 'history' : ROAttr(ApiReplicationCommand), 902 'active' : None, 903 'displayName' : None, # Added in 5.12 904 'description' : None # Added in 5.12 905 }
906
907 -class ApiHBaseSnapshotPolicyArguments(BaseApiObject):
908 _ATTRIBUTES = { 909 'tableRegExps' : None, 910 'storage' : None, 911 }
912
913 -class ApiHdfsSnapshotPolicyArguments(BaseApiObject):
914 _ATTRIBUTES = { 915 'pathPatterns' : None, 916 }
917
918 -class ApiHBaseSnapshot(BaseApiObject):
919 _ATTRIBUTES = { 920 'snapshotName' : None, 921 'tableName' : None, 922 'creationTime' : ROAttr(datetime.datetime), 923 'storage' : None, 924 }
925
926 -class ApiHBaseSnapshotError(BaseApiObject):
927 _ATTRIBUTES = { 928 'tableName' : ROAttr(), 929 'snapshotName' : ROAttr(), 930 'error' : ROAttr(), 931 'storage' : ROAttr(), 932 }
933
934 -class ApiHdfsSnapshot(BaseApiObject):
935 _ATTRIBUTES = { 936 'path' : None, 937 'snapshotName' : None, 938 'snapshotPath' : None, 939 'creationTime' : ROAttr(datetime.datetime), 940 }
941
942 -class ApiHdfsSnapshotError(BaseApiObject):
943 _ATTRIBUTES = { 944 'path' : ROAttr(), 945 'snapshotName' : ROAttr(), 946 'snapshotPath' : ROAttr(), 947 'error' : ROAttr(), 948 }
949
950 -class ApiHBaseSnapshotResult(BaseApiObject):
951 _ATTRIBUTES = { 952 'processedTableCount' : ROAttr(), 953 'processedTables' : ROAttr(), 954 'unprocessedTableCount' : ROAttr(), 955 'unprocessedTables' : ROAttr(), 956 'createdSnapshotCount' : ROAttr(), 957 'createdSnapshots' : ROAttr(ApiHBaseSnapshot), 958 'deletedSnapshotCount' : ROAttr(), 959 'deletedSnapshots' : ROAttr(ApiHBaseSnapshot), 960 'creationErrorCount' : ROAttr(), 961 'creationErrors' : ROAttr(ApiHBaseSnapshotError), 962 'deletionErrorCount' : ROAttr(), 963 'deletionErrors' : ROAttr(ApiHBaseSnapshotError), 964 }
965
966 -class ApiHdfsSnapshotResult(BaseApiObject):
967 _ATTRIBUTES = { 968 'processedPathCount' : ROAttr(), 969 'processedPaths' : ROAttr(), 970 'unprocessedPathCount' : ROAttr(), 971 'unprocessedPaths' : ROAttr(), 972 'createdSnapshotCount' : ROAttr(), 973 'createdSnapshots' : ROAttr(ApiHdfsSnapshot), 974 'deletedSnapshotCount' : ROAttr(), 975 'deletedSnapshots' : ROAttr(ApiHdfsSnapshot), 976 'creationErrorCount' : ROAttr(), 977 'creationErrors' : ROAttr(ApiHdfsSnapshotError), 978 'deletionErrorCount' : ROAttr(), 979 'deletionErrors' : ROAttr(ApiHdfsSnapshotError), 980 }
981
982 -class ApiSnapshotCommand(BaseApiObject):
983 @classmethod
984 - def _get_attributes(cls):
985 if not cls.__dict__.has_key('_ATTRIBUTES'): 986 attrs = { 987 'hdfsResult' : ROAttr(ApiHdfsSnapshotResult), 988 'hbaseResult' : ROAttr(ApiHBaseSnapshotResult), 989 } 990 attrs.update(ApiCommand._get_attributes()) 991 cls._ATTRIBUTES = attrs 992 return cls._ATTRIBUTES
993
994 -class ApiSnapshotPolicy(BaseApiObject):
995 """ 996 @type name: str 997 @ivar name: Name of the snapshot policy. 998 @type description: str 999 @ivar description: Description of the snapshot policy. 1000 @type hourly_snapshots: int 1001 @ivar hourly_snapshots: Number of hourly snapshots to be retained (default: 0). 1002 @type daily_snapshots: int 1003 @ivar daily_snapshots: Number of daily snapshots to be retained (default: 0). 1004 @type weekly_snapshots: int 1005 @ivar weekly_snapshots: Number of weekly snapshots to be retained (default: 0). 1006 @type monthly_snapshots: int 1007 @ivar monthly_snapshots: Number of monthly snapshots to be retained (default: 0). 1008 @type yearly_snapshots: int 1009 @ivar yearly_snapshots: Number of yearly snapshots to be retained (default: 0). 1010 @type hours_for_hourly_snapshots: list of int 1011 @ivar hours_for_hourly_snapshots: Hours of the day that hourly snapshots should be created. 1012 Valid values are 0 to 23. If this list is empty, then hourly snapshots are 1013 created for every hour. 1014 @type minute_of_hour: int 1015 @ivar minute_of_hour: Minute in the hour that hourly, daily, weekly, monthly and yearly 1016 snapshots should be created. Valid values are 0 to 59 (default: 0). 1017 @type hour_of_day: int 1018 @ivar hour_of_day: Hour in the day that daily, weekly, monthly and yearly snapshots should be created. 1019 Valid values are 0 to 23 (default: 0). 1020 @type day_of_week: int 1021 @ivar day_of_week: Day of the week that weekly snapshots should be created. 1022 Valid values are 1 to 7, 1 representing Sunday (default: 1). 1023 @type day_of_month: int 1024 @ivar day_of_month: Day of the month that monthly and yearly snapshots should be created. 1025 Values from 1 to 31 are allowed. Additionally 0 to -30 can be used to 1026 specify offsets from the last day of the month (default: 1). 1027 @type month_of_year: int 1028 @ivar month_of_year: Month of the year that yearly snapshots should be created. 1029 Valid values are 1 to 12, 1 representing January (default: 1). 1030 @ivar alert_on_start: whether to generate alerts on start of snapshot creation/deletion activity. 1031 @ivar alert_on_success: whether to generate alerts on successful completion of snapshot creation/deletion activity. 1032 @ivar alert_on_fail: whether to generate alerts on failure of snapshot creation/deletion activity. 1033 @ivar alert_on_abort: whether to generate alerts on abort of snapshot creation/deletion activity. 1034 @ivar paused: whether to run the policy on schedule 1035 @type hbaseArguments: ApiHBaseSnapshotPolicyArguments 1036 @ivar hbaseArguments: HBase specific arguments for the replication job. 1037 @type hdfsArguments: ApiHdfsSnapshotPolicyArguments 1038 @ivar hdfsArguments: HDFS specific arguments for the replication job. 1039 """ 1040 _ATTRIBUTES = { 1041 'name' : None, 1042 'description' : None, 1043 'hourlySnapshots' : None, 1044 'dailySnapshots' : None, 1045 'weeklySnapshots' : None, 1046 'monthlySnapshots' : None, 1047 'yearlySnapshots' : None, 1048 'minuteOfHour' : None, 1049 'hourOfDay' : None, 1050 'dayOfWeek' : None, 1051 'dayOfMonth' : None, 1052 'monthOfYear' : None, 1053 'hoursForHourlySnapshots' : None, 1054 'alertOnStart' : None, 1055 'alertOnSuccess' : None, 1056 'alertOnFail' : None, 1057 'alertOnAbort' : None, 1058 'paused' : None, 1059 'hbaseArguments' : Attr(ApiHBaseSnapshotPolicyArguments), 1060 'hdfsArguments' : Attr(ApiHdfsSnapshotPolicyArguments), 1061 'lastCommand' : ROAttr(ApiSnapshotCommand), 1062 'lastSuccessfulCommand' : ROAttr(ApiSnapshotCommand), 1063 }
1064
1065 # 1066 # Batch. 1067 # 1068 1069 -class ApiBatchRequestElement(BaseApiObject):
1070 """One element in a batch request.""" 1071 _ATTRIBUTES = { 1072 'method' : None, 1073 'url' : None, 1074 'body' : None, 1075 'contentType' : None, 1076 'acceptType' : None, 1077 }
1078
1079 -class ApiBatchResponseElement(BaseApiObject):
1080 """One element in a batch response.""" 1081 _ATTRIBUTES = { 1082 'statusCode' : ROAttr(), 1083 'response' : ROAttr(), 1084 }
1085
1086 -class ApiBatchResponseList(ApiList):
1087 """A list of batch response objects.""" 1088 _ATTRIBUTES = { 1089 'success' : ROAttr(), 1090 } 1091 _MEMBER_CLASS = ApiBatchResponseElement
1092
1093 # 1094 # Configuration helpers. 1095 # 1096 1097 -class ApiConfig(BaseApiObject):
1098 _ATTRIBUTES = { 1099 'name' : None, 1100 'value' : None, 1101 'required' : ROAttr(), 1102 'default' : ROAttr(), 1103 'displayName' : ROAttr(), 1104 'description' : ROAttr(), 1105 'relatedName' : ROAttr(), 1106 'sensitive' : ROAttr(), 1107 'validationState' : ROAttr(), 1108 'validationMessage' : ROAttr(), 1109 'validationWarningsSuppressed' : ROAttr() 1110 } 1111
1112 - def __init__(self, resource_root, name=None, value=None):
1113 BaseApiObject.init(self, resource_root, locals())
1114
1115 - def __str__(self):
1116 return "<ApiConfig>: %s = %s" % (self.name, self.value)
1117
1118 -class ApiImpalaQuery(BaseApiObject):
1119 _ATTRIBUTES = { 1120 'queryId' : ROAttr(), 1121 'queryState' : ROAttr(), 1122 'queryType' : ROAttr(), 1123 'statement' : ROAttr(), 1124 'database' : ROAttr(), 1125 'rowsProduced' : ROAttr(), 1126 'coordinator' : ROAttr(ApiHostRef), 1127 'user' : ROAttr(), 1128 'startTime' : ROAttr(datetime.datetime), 1129 'endTime' : ROAttr(datetime.datetime), 1130 'detailsAvailable' : ROAttr(), 1131 'attributes' : ROAttr(), 1132 'durationMillis' : ROAttr() 1133 } 1134
1135 - def __str__(self):
1136 return "<ApiImpalaQuery>: %s" % (self.queryId)
1137
1138 # 1139 # WatchedDirectories data types 1140 # 1141 1142 -class ApiWatchedDir(BaseApiObject):
1143 1144 _ATTRIBUTES = { 1145 'path' : None 1146 } 1147
1148 - def __str__(self):
1149 return "<ApiWatchedDir>: %s" % (self.path)
1150
1151 -class ApiWatchedDirList(ApiList):
1152 1153 _ATTRIBUTES = { 1154 'watchedDirs' : ROAttr(ApiWatchedDir) 1155 } 1156 _MEMBER_CLASS = ApiWatchedDir
1157
1158 -class ApiImpalaQueryResponse(BaseApiObject):
1159 1160 _ATTRIBUTES = { 1161 'queries' : ROAttr(ApiImpalaQuery), 1162 'warnings' : ROAttr() 1163 }
1164
1165 -class ApiImpalaQueryDetailsResponse(BaseApiObject):
1166 _ATTRIBUTES = { 1167 'details' : ROAttr() 1168 } 1169
1170 - def __str__(self):
1171 return "<AipImpalaQueryDetailsResponse> %s" % self.details
1172
1173 -class ApiImpalaCancelResponse(BaseApiObject):
1174 _ATTRIBUTES = { 1175 'warning' : ROAttr() 1176 } 1177
1178 - def __str__(self):
1179 return "<ApiImpalaCancelResponse> %s" % self.warning
1180
1181 -class ApiImpalaQueryAttribute(BaseApiObject):
1182 1183 _ATTRIBUTES = { 1184 'name' : ROAttr(), 1185 'type' : ROAttr(), 1186 'displayName' : ROAttr(), 1187 'supportsHistograms' : ROAttr(), 1188 'description' : ROAttr() 1189 } 1190
1191 - def __str__(self):
1192 return "<ApiImpalaQueryAttribute> %s" % name
1193
1194 -class ApiMr2AppInformation(BaseApiObject):
1195 _ATTRIBUTES = { 1196 'jobState' : ROAttr() 1197 } 1198
1199 - def __str__(self):
1200 return "<ApiMr2AppInformation>: %s" % (self.jobState)
1201
1202 -class ApiYarnApplication(BaseApiObject):
1203 _ATTRIBUTES = { 1204 'applicationId' : ROAttr(), 1205 'name' : ROAttr(), 1206 'user' : ROAttr(), 1207 'startTime' : ROAttr(datetime.datetime), 1208 'endTime' : ROAttr(datetime.datetime), 1209 'pool' : ROAttr(), 1210 'state' : ROAttr(), 1211 'progress' : ROAttr(), 1212 'mr2AppInformation' : ROAttr(ApiMr2AppInformation), 1213 'attributes' : ROAttr(), 1214 'allocatedMB' : ROAttr(), 1215 'allocatedVCores' : ROAttr(), 1216 'runningContainers' : ROAttr(), 1217 'applicationTags' : ROAttr(), 1218 'allocatedMemorySeconds' : ROAttr(), 1219 'allocatedVcoreSeconds' : ROAttr(), 1220 'containerUsedMemorySeconds' : ROAttr(), 1221 'containerUsedCpuSeconds' : ROAttr(), 1222 'containerUsedVcoreSeconds' : ROAttr(), 1223 'containerAllocatedMemorySeconds' : ROAttr(), 1224 'containerAllocatedVcoreSeconds' : ROAttr(), 1225 'containerUsedMemoryMax' : ROAttr(), 1226 } 1227
1228 - def __str__(self):
1229 return "<ApiYarnApplication>: %s" % (self.applicationId)
1230
1231 -class ApiYarnApplicationResponse(BaseApiObject):
1232 1233 _ATTRIBUTES = { 1234 'applications' : ROAttr(ApiYarnApplication), 1235 'warnings' : ROAttr() 1236 }
1237
1238 -class ApiYarnKillResponse(BaseApiObject):
1239 _ATTRIBUTES = { 1240 'warning' : ROAttr() 1241 } 1242
1243 - def __str__(self):
1244 return "<ApiYarnKillResponse> %s" % self.warning
1245
1246 -class ApiYarnApplicationAttribute(BaseApiObject):
1247 1248 _ATTRIBUTES = { 1249 'name' : ROAttr(), 1250 'type' : ROAttr(), 1251 'displayName' : ROAttr(), 1252 'supportsHistograms' : ROAttr(), 1253 'description' : ROAttr() 1254 } 1255
1256 - def __str__(self):
1257 return "<ApiYarnApplicationAttribute> %s" % name
1258
1259 -class ApiTimeSeriesRequest(BaseApiObject):
1260 _ATTRIBUTES = { 1261 'query' : None, 1262 'from' : None, 1263 'to' : None, 1264 'contentType' : None, 1265 'desiredRollup' : None, 1266 'mustUseDesiredRollup' : None 1267 } 1268
1269 - def __str__(self):
1270 return "<ApiTimeSeriesRequest>: %s" % (self.query)
1271
1272 -class ApiProductVersion(BaseApiObject):
1273 _ATTRIBUTES = { 1274 'version' : None, 1275 'product' : None, 1276 }
1277
1278 -class ApiClusterTemplateConfig(BaseApiObject):
1279 _ATTRIBUTES = { 1280 'name' : None, 1281 'value' : None, 1282 'ref' : None, 1283 'variable' : None, 1284 'autoConfig' : None, 1285 }
1286
1287 -class ApiClusterTemplateRoleConfigGroup(BaseApiObject):
1288 _ATTRIBUTES = { 1289 'refName' : None, 1290 'roleType' : None, 1291 'base' : None, 1292 'displayName' : None, 1293 'configs' : Attr(ApiClusterTemplateConfig), 1294 }
1295
1296 -class ApiClusterTemplateRole(BaseApiObject):
1297 _ATTRIBUTES = { 1298 'refName' : None, 1299 'roleType' : None, 1300 }
1301
1302 -class ApiClusterTemplateHostTemplate(BaseApiObject):
1303 _ATTRIBUTES = { 1304 'refName' : None, 1305 'cardinality' : None, 1306 'roleConfigGroupsRefNames' : None, 1307 }
1308
1309 -class ApiClusterTemplateHostInfo(BaseApiObject):
1310 _ATTRIBUTES = { 1311 'hostName' : None, 1312 'hostNameRange' : None, 1313 'rackId' : None, 1314 'hostTemplateRefName' : None, 1315 'roleRefNames' : None, 1316 }
1317
1318 -class ApiClusterTemplateVariable(BaseApiObject):
1319 _ATTRIBUTES = { 1320 'name' : None, 1321 'value' : None, 1322 }
1323
1324 -class ApiClusterTemplateRoleConfigGroupInfo(BaseApiObject):
1325 _ATTRIBUTES = { 1326 'rcgRefName' : None, 1327 'name' : None, 1328 }
1329
1330 -class ApiClusterTemplateInstantiator(BaseApiObject):
1331 _ATTRIBUTES = { 1332 'clusterName' : None, 1333 'hosts' : Attr(ApiClusterTemplateHostInfo), 1334 'variables' : Attr(ApiClusterTemplateVariable), 1335 'roleConfigGroups' : Attr(ApiClusterTemplateRoleConfigGroupInfo), 1336 }
1337
1338 -class ApiClusterTemplateService(BaseApiObject):
1339 _ATTRIBUTES = { 1340 'refName' : None, 1341 'serviceType' : None, 1342 'serviceConfigs' : Attr(ApiClusterTemplateConfig), 1343 'roleConfigGroups' : Attr(ApiClusterTemplateRoleConfigGroup), 1344 'displayName' : None, 1345 'roles' : Attr(ApiClusterTemplateRole), 1346 }
1347
1348 -class ApiClusterTemplate(BaseApiObject):
1349 _ATTRIBUTES = { 1350 'cdhVersion' : None, 1351 'displayName' : None, 1352 'cmVersion' : None, 1353 "repositories" : None, 1354 'products' : Attr(ApiProductVersion), 1355 'services' : Attr(ApiClusterTemplateService), 1356 'hostTemplates' : Attr(ApiClusterTemplateHostTemplate), 1357 'instantiator' : Attr(ApiClusterTemplateInstantiator), 1358 }
1359
1360 -def config_to_api_list(dic):
1361 """ 1362 Converts a python dictionary into a list containing the proper 1363 ApiConfig encoding for configuration data. 1364 1365 @param dic: Key-value pairs to convert. 1366 @return: JSON dictionary of an ApiConfig list (*not* an ApiList). 1367 """ 1368 config = [ ] 1369 for k, v in dic.iteritems(): 1370 config.append({ 'name' : k, 'value': v }) 1371 return { ApiList.LIST_KEY : config }
1372
1373 -def config_to_json(dic):
1374 """ 1375 Converts a python dictionary into a JSON payload. 1376 1377 The payload matches the expected "apiConfig list" type used to update 1378 configuration parameters using the API. 1379 1380 @param dic: Key-value pairs to convert. 1381 @return: String with the JSON-encoded data. 1382 """ 1383 return json.dumps(config_to_api_list(dic))
1384
1385 -def json_to_config(dic, full = False):
1386 """ 1387 Converts a JSON-decoded config dictionary to a python dictionary. 1388 1389 When materializing the full view, the values in the dictionary will be 1390 instances of ApiConfig, instead of strings. 1391 1392 @param dic: JSON-decoded config dictionary. 1393 @param full: Whether to materialize the full view of the config data. 1394 @return: Python dictionary with config data. 1395 """ 1396 config = { } 1397 for entry in dic['items']: 1398 k = entry['name'] 1399 if full: 1400 config[k] = ApiConfig.from_json_dict(entry, None) 1401 else: 1402 config[k] = entry.get('value') 1403 return config
1404