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

Source Code for Module cm_api.endpoints.role_config_groups

  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  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   
25 -def _get_role_config_groups_path(cluster_name, service_name):
26 if cluster_name: 27 return ROLE_CONFIG_GROUPS_PATH % (cluster_name, service_name) 28 else: 29 return CM_ROLE_CONFIG_GROUPS_PATH
30
31 -def _get_role_config_group_path(cluster_name, service_name, name):
32 path = _get_role_config_groups_path(cluster_name, service_name) 33 return "%s/%s" % (path, name)
34
35 -def create_role_config_groups(resource_root, service_name, apigroup_list, 36 cluster_name="default"):
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
50 -def create_role_config_group(resource_root, service_name, name, display_name, 51 role_type, cluster_name="default"):
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
66 -def get_role_config_group(resource_root, service_name, name, 67 cluster_name="default"):
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
79 -def _get_role_config_group(resource_root, path):
80 return call(resource_root.get, path, ApiRoleConfigGroup, api_version=3)
81
82 -def get_all_role_config_groups(resource_root, service_name, 83 cluster_name="default"):
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
96 -def update_role_config_group(resource_root, service_name, name, apigroup, 97 cluster_name="default"):
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
112 -def delete_role_config_group(resource_root, service_name, name, 113 cluster_name="default"):
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
145 -def move_roles_to_base_role_config_group(resource_root, service_name, 146 role_names, cluster_name="default"):
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
163 -class ApiRoleConfigGroup(BaseApiResource):
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):
181 BaseApiObject.init(self, resource_root, locals())
182
183 - def __str__(self):
184 return "<ApiRoleConfigGroup>: %s (cluster: %s; service: %s)" % ( 185 self.name, self.serviceRef.clusterName, self.serviceRef.serviceName)
186
187 - def _api_version(self):
188 return 3
189
190 - def _path(self):
191 return _get_role_config_group_path(self.serviceRef.clusterName, 192 self.serviceRef.serviceName, 193 self.name)
194
195 - def get_config(self, view = None):
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
210 - def update_config(self, config):
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
221 - def get_all_roles(self):
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
229 - def move_roles(self, roles):
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