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  EXTERNAL_ACCOUNT_CONFIG_FETCH_PATH = "/externalAccounts/account/%s" 
 29  EXTERNAL_ACCOUNT_TYPE_INFO_FETCH_PATH = "/externalAccounts/typeInfo/%s/%s" 
 30   
31 -def get_supported_categories(resource_root):
32 """ 33 Lookup all supported categories. 34 @param resource_root: The root Resource object. 35 @return: An ApiExternalAcccountCategory list 36 """ 37 return call(resource_root.get, EXTERNAL_ACCOUNT_PATH % ("supportedCategories",) , 38 ApiExternalAccountCategory, True)
39
40 -def get_supported_types(resource_root, category_name):
41 """ 42 Lookup all supported types in a category. 43 @param resource_root: The root Resource object. 44 @param category_name: The category name 45 @return: An ApiExternalAcccountType list 46 """ 47 return call(resource_root.get, 48 EXTERNAL_ACCOUNT_FETCH_PATH % ("supportedTypes", category_name,), 49 ApiExternalAccountType, True)
50
51 -def list_commands_by_name(resource_root, type_name):
52 """ 53 Lists all the commands that can be executed by name 54 on the provided external account type. 55 56 @param type_name: Account type 57 @return: A list of command metadata objects 58 @since: API v16 59 """ 60 return call(resource_root.get, 61 EXTERNAL_ACCOUNT_TYPE_INFO_FETCH_PATH % (type_name, "commandsByName"), 62 ApiCommandMetadata, True, api_version=16)
63
64 -def create_external_account(resource_root, name, display_name, type_name, 65 account_configs=None):
66 """ 67 Create an external account 68 @param resource_root: The root Resource object. 69 @param name: Immutable external account name 70 @param display_name: Display name 71 @param type_name: Account type 72 @param account_configs: Optional account configuration (ApiList of ApiConfig objects) 73 @return: An ApiExternalAccount object matching the newly created account 74 """ 75 account = ApiExternalAccount(resource_root, 76 name=name, 77 displayName=display_name, 78 typeName=type_name, 79 accountConfigs=account_configs) 80 return call(resource_root.post, 81 EXTERNAL_ACCOUNT_PATH % ("create",), 82 ApiExternalAccount, False, data=account)
83
84 -def get_external_account(resource_root, name, view=None):
85 """ 86 Lookup an external account by name 87 @param resource_root: The root Resource object. 88 @param name: Account name 89 @param view: View 90 @return: An ApiExternalAccount object 91 """ 92 return call(resource_root.get, 93 EXTERNAL_ACCOUNT_FETCH_PATH % ("account", name,), 94 ApiExternalAccount, False, params=view and dict(view=view) or None)
95
96 -def get_external_account_by_display_name(resource_root, 97 display_name, view=None):
98 """ 99 Lookup an external account by display name 100 @param resource_root: The root Resource object. 101 @param display_name: Account display name 102 @param view: View 103 @return: An ApiExternalAccount object 104 """ 105 return call(resource_root.get, 106 EXTERNAL_ACCOUNT_FETCH_PATH % ("accountByDisplayName", display_name,), 107 ApiExternalAccount, False, params=view and dict(view=view) or None)
108
109 -def get_all_external_accounts(resource_root, type_name, view=None):
110 """ 111 Lookup all external accounts of a particular type, by type name. 112 @param resource_root: The root Resource object. 113 @param type_name: Type name 114 @param view: View 115 @return: An ApiList of ApiExternalAccount objects matching the specified type 116 """ 117 return call(resource_root.get, 118 EXTERNAL_ACCOUNT_FETCH_PATH % ("type", type_name,), 119 ApiExternalAccount, True, params=view and dict(view=view) or None)
120
121 -def update_external_account(resource_root, account):
122 """ 123 Update an external account 124 @param resource_root: The root Resource object. 125 @param account: Account to update, account name must be specified. 126 @return: An ApiExternalAccount object, representing the updated external account 127 """ 128 return call(resource_root.put, 129 EXTERNAL_ACCOUNT_PATH % ("update",), 130 ApiExternalAccount, False, data=account)
131
132 -def delete_external_account(resource_root, name):
133 """ 134 Delete an external account by name 135 @param resource_root: The root Resource object. 136 @param name: Account name 137 @return: The deleted ApiExternalAccount object 138 """ 139 return call(resource_root.delete, 140 EXTERNAL_ACCOUNT_FETCH_PATH % ("delete", name,), 141 ApiExternalAccount, False)
142
143 -class ApiExternalAccountCategory(BaseApiObject):
144 _ATTRIBUTES = { 145 'name' : None, 146 'displayName' : None, 147 'description' : None 148 } 149
150 - def __str__(self):
151 return "<ApiExternalAccountCategory>: %s" % ( 152 self.name)
153
154 -class ApiExternalAccountType(BaseApiObject):
155 _ATTRIBUTES = { 156 'name' : None, 157 'displayName' : None, 158 'type' : None, 159 'categoryName' : None, 160 'description' : None, 161 'allowedAccountConfigs' : Attr(ApiConfig) 162 } 163
164 - def __str__(self):
165 return "<ApiExternalAccountType>: %s (categoryName: %s)" % ( 166 self.name, self.typeName)
167
168 -class ApiExternalAccount(BaseApiResource):
169 _ATTRIBUTES = { 170 'name' : None, 171 'displayName' : None, 172 'typeName' : None, 173 'createdTime' : ROAttr(), 174 'lastModifiedTime' : ROAttr(), 175 'accountConfigs' : Attr(ApiConfig) 176 } 177
178 - def __init__(self, resource_root, name=None, displayName=None, 179 typeName=None, accountConfigs=None):
180 BaseApiResource.init(self, resource_root, locals())
181
182 - def __str__(self):
183 return "<ApiExternalAccount>: %s (typeName: %s)" % ( 184 self.name, self.typeName)
185
186 - def _path(self):
187 return EXTERNAL_ACCOUNT_CONFIG_FETCH_PATH % self.name
188
189 - def get_config(self, view=None):
190 """ 191 Retrieve the external account's configuration. 192 193 The 'summary' view contains strings as the dictionary values. The full 194 view contains ApiConfig instances as the values. 195 196 @param view: View to materialize ('full' or 'summary') 197 @return: Dictionary with configuration data. 198 """ 199 return self._get_config("config", view)
200
201 - def update_config(self, config):
202 """ 203 Update the external account's configuration. 204 205 @param config: Dictionary with configuration to update. 206 @return: Dictionary with updated configuration. 207 """ 208 return self._update_config("config", config)
209
210 - def external_account_cmd_by_name(self, command_name):
211 """ 212 Executes a command on the external account specified 213 by name. 214 215 @param command_name: The name of the command. 216 @return: Reference to the submitted command. 217 @since: API v16 218 """ 219 return self._cmd(command_name, data=self.name, api_version=16)
220