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

Source Code for Module cm_api.endpoints.external_accounts

  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  from cm_api.endpoints.types import * 
 23   
 24  __docformat__ = "epytext" 
 25   
 26  EXTERNAL_ACCOUNT_PATH = "/externalAccounts/%s" 
 27  EXTERNAL_ACCOUNT_FETCH_PATH = "/externalAccounts/%s/%s" 
 28   
29 -def get_supported_categories(resource_root):
30 """ 31 Lookup all supported categories. 32 @param resource_root: The root Resource object. 33 @return: An ApiExternalAcccountCategory list 34 """ 35 return call(resource_root.get, EXTERNAL_ACCOUNT_PATH % ("supportedCategories",) , 36 ApiExternalAccountCategory, True)
37
38 -def get_supported_types(resource_root, category_name):
39 """ 40 Lookup all supported types in a category. 41 @param resource_root: The root Resource object. 42 @param category_name: The category name 43 @return: An ApiExternalAcccountType list 44 """ 45 return call(resource_root.get, 46 EXTERNAL_ACCOUNT_FETCH_PATH % ("supportedTypes", category_name,), 47 ApiExternalAccountType, True)
48
49 -def create_external_account(resource_root, name, display_name, type_name, 50 account_configs=None):
51 """ 52 Create an external account 53 @param resource_root: The root Resource object. 54 @param name: Immutable external account name 55 @param display_name: Display name 56 @param type_name: Account type 57 @param account_configs: Optional account configuration (ApiList of ApiConfig objects) 58 @return: An ApiExternalAccount object matching the newly created account 59 """ 60 account = ApiExternalAccount(resource_root, 61 name=name, 62 displayName=display_name, 63 typeName=type_name, 64 accountConfigs=account_configs) 65 return call(resource_root.post, 66 EXTERNAL_ACCOUNT_PATH % ("create",), 67 ApiExternalAccount, False, data=account)
68
69 -def get_external_account(resource_root, name, view=None):
70 """ 71 Lookup an external account by name 72 @param resource_root: The root Resource object. 73 @param name: Account name 74 @param view: View 75 @return: An ApiExternalAccount object 76 """ 77 return call(resource_root.get, 78 EXTERNAL_ACCOUNT_FETCH_PATH % ("account", name,), 79 ApiExternalAccount, False, params=view and dict(view=view) or None)
80
81 -def get_external_account_by_display_name(resource_root, 82 display_name, view=None):
83 """ 84 Lookup an external account by display name 85 @param resource_root: The root Resource object. 86 @param display_name: Account display name 87 @param view: View 88 @return: An ApiExternalAccount object 89 """ 90 return call(resource_root.get, 91 EXTERNAL_ACCOUNT_FETCH_PATH % ("accountByDisplayName", display_name,), 92 ApiExternalAccount, False, params=view and dict(view=view) or None)
93
94 -def get_all_external_accounts(resource_root, type_name, view=None):
95 """ 96 Lookup all external accounts of a particular type, by type name. 97 @param resource_root: The root Resource object. 98 @param type_name: Type name 99 @param view: View 100 @return: An ApiList of ApiExternalAccount objects matching the specified type 101 """ 102 return call(resource_root.get, 103 EXTERNAL_ACCOUNT_FETCH_PATH % ("type", type_name,), 104 ApiExternalAccount, True, params=view and dict(view=view) or None)
105
106 -def update_external_account(resource_root, account):
107 """ 108 Update an external account 109 @param resource_root: The root Resource object. 110 @param account: Account to update, account name must be specified. 111 @return: An ApiExternalAccount object, representing the updated external account 112 """ 113 return call(resource_root.put, 114 EXTERNAL_ACCOUNT_PATH % ("update",), 115 ApiExternalAccount, False, data=account)
116
117 -def delete_external_account(resource_root, name):
118 """ 119 Delete an external account by name 120 @param resource_root: The root Resource object. 121 @param name: Account name 122 @return: The deleted ApiExternalAccount object 123 """ 124 return call(resource_root.delete, 125 EXTERNAL_ACCOUNT_FETCH_PATH % ("delete", name,), 126 ApiExternalAccount, False)
127 128
129 -class ApiExternalAccountCategory(BaseApiObject):
130 _ATTRIBUTES = { 131 'name' : None, 132 'displayName' : None, 133 'description' : None 134 } 135
136 - def __str__(self):
137 return "<ApiExternalAccountCategory>: %s" % ( 138 self.name)
139
140 -class ApiExternalAccountType(BaseApiObject):
141 _ATTRIBUTES = { 142 'name' : None, 143 'displayName' : None, 144 'type' : None, 145 'categoryName' : None, 146 'description' : None, 147 'allowedAccountConfigs' : Attr(ApiConfig) 148 } 149
150 - def __str__(self):
151 return "<ApiExternalAccountType>: %s (categoryName: %s)" % ( 152 self.name, self.typeName)
153
154 -class ApiExternalAccount(BaseApiObject):
155 _ATTRIBUTES = { 156 'name' : None, 157 'displayName' : None, 158 'typeName' : None, 159 'createdTime' : ROAttr(), 160 'lastModifiedTime' : ROAttr(), 161 'accountConfigs' : Attr(ApiConfig) 162 } 163
164 - def __init__(self, resource_root, name=None, displayName=None, 165 typeName=None, accountConfigs=None):
166 BaseApiObject.init(self, resource_root, locals())
167
168 - def __str__(self):
169 return "<ApiExternalAccount>: %s (typeName: %s)" % ( 170 self.name, self.typeName)
171