1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 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   
 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   
 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   
 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   
 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   
 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   
 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   
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   
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   
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   
144    _ATTRIBUTES = { 
145      'name'        : None, 
146      'displayName' : None, 
147      'description' : None 
148    } 
149   
151      return "<ApiExternalAccountCategory>: %s" % ( 
152          self.name) 
  153   
155    _ATTRIBUTES = { 
156      'name'         : None, 
157      'displayName'  : None, 
158      'type'         : None, 
159      'categoryName' : None, 
160      'description'  : None, 
161      'allowedAccountConfigs' : Attr(ApiConfig) 
162    } 
163   
165      return "<ApiExternalAccountType>: %s (categoryName: %s)" % ( 
166          self.name, self.typeName) 
  167   
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): 
 181   
183      return "<ApiExternalAccount>: %s (typeName: %s)" % ( 
184          self.name, self.typeName) 
 185   
188   
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   
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   
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