1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 16   
 17  from cm_api.endpoints.types import * 
 18  from cm_api.endpoints.roles import ApiRole 
 19   
 20  __docformat__ = "epytext" 
 21   
 22  ROLE_CONFIG_GROUPS_PATH = "/clusters/%s/services/%s/roleConfigGroups" 
 23  CM_ROLE_CONFIG_GROUPS_PATH = "/cm/service/roleConfigGroups" 
 24   
 30   
 34   
 37    """ 
 38    Create role config groups. 
 39    @param resource_root: The root Resource object. 
 40    @param service_name: Service name. 
 41    @param apigroup_list: List of role config groups to create. 
 42    @param cluster_name: Cluster name. 
 43    @return: New ApiRoleConfigGroup object. 
 44    @since: API v3 
 45    """ 
 46    return call(resource_root.post, 
 47        _get_role_config_groups_path(cluster_name, service_name), 
 48        ApiRoleConfigGroup, True, data=apigroup_list, api_version=3) 
  49   
 52    """ 
 53    Create a role config group. 
 54    @param resource_root: The root Resource object. 
 55    @param service_name: Service name. 
 56    @param name: The name of the new group. 
 57    @param display_name: The display name of the new group. 
 58    @param role_type: The role type of the new group. 
 59    @param cluster_name: Cluster name. 
 60    @return: List of created role config groups. 
 61    """ 
 62    apigroup = ApiRoleConfigGroup(resource_root, name, display_name, role_type) 
 63    return create_role_config_groups(resource_root, service_name, [apigroup], 
 64        cluster_name)[0] 
  65   
 68    """ 
 69    Find a role config group by name. 
 70    @param resource_root: The root Resource object. 
 71    @param service_name: Service name. 
 72    @param name: Role config group name. 
 73    @param cluster_name: Cluster name. 
 74    @return: An ApiRoleConfigGroup object. 
 75    """ 
 76    return _get_role_config_group(resource_root, _get_role_config_group_path( 
 77        cluster_name, service_name, name)) 
  78   
 81   
 84    """ 
 85    Get all role config groups in the specified service. 
 86    @param resource_root: The root Resource object. 
 87    @param service_name: Service name. 
 88    @param cluster_name: Cluster name. 
 89    @return: A list of ApiRoleConfigGroup objects. 
 90    @since: API v3 
 91    """ 
 92    return call(resource_root.get, 
 93        _get_role_config_groups_path(cluster_name, service_name), 
 94        ApiRoleConfigGroup, True, api_version=3) 
  95   
 98    """ 
 99    Update a role config group by name. 
100    @param resource_root: The root Resource object. 
101    @param service_name: Service name. 
102    @param name: Role config group name. 
103    @param apigroup: The updated role config group. 
104    @param cluster_name: Cluster name. 
105    @return: The updated ApiRoleConfigGroup object. 
106    @since: API v3 
107    """ 
108    return call(resource_root.put, 
109        _get_role_config_group_path(cluster_name, service_name, name), 
110        ApiRoleConfigGroup, data=apigroup, api_version=3) 
 111   
114    """ 
115    Delete a role config group by name. 
116    @param resource_root: The root Resource object. 
117    @param service_name: Service name. 
118    @param name: Role config group name. 
119    @param cluster_name: Cluster name. 
120    @return: The deleted ApiRoleConfigGroup object. 
121    @since: API v3 
122    """ 
123    return call(resource_root.delete, 
124        _get_role_config_group_path(cluster_name, service_name, name), 
125        ApiRoleConfigGroup, api_version=3) 
 126   
127 -def move_roles(resource_root, service_name, name, role_names, 
128      cluster_name="default"): 
 129    """ 
130    Moves roles to the specified role config group. 
131   
132    The roles can be moved from any role config group belonging 
133    to the same service. The role type of the destination group 
134    must match the role type of the roles. 
135   
136    @param name: The name of the group the roles will be moved to. 
137    @param role_names: The names of the roles to move. 
138    @return: List of roles which have been moved successfully. 
139    @since: API v3 
140    """ 
141    return call(resource_root.put, 
142        _get_role_config_group_path(cluster_name, service_name, name) + '/roles', 
143        ApiRole, True, data=role_names, api_version=3) 
 144   
147    """ 
148    Moves roles to the base role config group. 
149   
150    The roles can be moved from any role config group belonging to the same 
151    service. The role type of the roles may vary. Each role will be moved to 
152    its corresponding base group depending on its role type. 
153   
154    @param role_names: The names of the roles to move. 
155    @return: List of roles which have been moved successfully. 
156    @since: API v3 
157    """ 
158    return call(resource_root.put, 
159        _get_role_config_groups_path(cluster_name, service_name) + '/roles', 
160        ApiRole, True, data=role_names, api_version=3) 
 161   
162   
164    """ 
165    name is RW only temporarily; once all RCG names are unique, 
166    this property will be auto-generated and Read-only 
167   
168    @since: API v3 
169    """ 
170    _ATTRIBUTES = { 
171      'name'        : None, 
172      'displayName' : None, 
173      'roleType'    : None, 
174      'config'      : Attr(ApiConfig), 
175      'base'        : ROAttr(), 
176      'serviceRef'  : ROAttr(ApiServiceRef), 
177    } 
178   
179 -  def __init__(self, resource_root, name=None, displayName=None, roleType=None, 
180        config=None): 
 182   
184      return "<ApiRoleConfigGroup>: %s (cluster: %s; service: %s)" % ( 
185          self.name, self.serviceRef.clusterName, self.serviceRef.serviceName) 
 186   
189   
194   
196      """ 
197      Retrieve the group's configuration. 
198   
199      The 'summary' view contains strings as the dictionary values. The full 
200      view contains ApiConfig instances as the values. 
201   
202      @param view: View to materialize ('full' or 'summary'). 
203      @return: Dictionary with configuration data. 
204      """ 
205      path = self._path() + '/config' 
206      resp = self._get_resource_root().get(path, 
207          params = view and dict(view=view) or None) 
208      return json_to_config(resp, view == 'full') 
 209   
211      """ 
212      Update the group's configuration. 
213   
214      @param config: Dictionary with configuration to update. 
215      @return: Dictionary with updated configuration. 
216      """ 
217      path = self._path() + '/config' 
218      resp = self._get_resource_root().put(path, data = config_to_json(config)) 
219      return json_to_config(resp) 
 220   
222      """ 
223      Retrieve the roles in this role config group. 
224   
225      @return: List of roles in this role config group. 
226      """ 
227      return self._get("roles", ApiRole, True) 
 228   
230      """ 
231      Moves roles to this role config group. 
232   
233      The roles can be moved from any role config group belonging 
234      to the same service. The role type of the destination group 
235      must match the role type of the roles. 
236   
237      @param roles: The names of the roles to move. 
238      @return: List of roles which have been moved successfully. 
239      """ 
240      return move_roles(self._get_resource_root(), self.serviceRef.serviceName, 
241          self.name, roles, self.serviceRef.clusterName) 
  242