def create_cluster(resource_root, name, version=None, fullVersion=None): """Create a cluster :param resource_root: The root Resource object. :param name: Cluster name :param version: Cluster CDH major version (eg: "CDH4") - The CDH minor version will be assumed to be the latest released version for CDH4, or 5.0 for CDH5. :param fullVersion: Cluster's full CDH version. (eg: "5.1.1") - If specified, 'version' will be ignored. - Since: v6 :return: An ApiCluster object """ if version is None and fullVersion is None: raise ex.CMApiVersionError( _("Either 'version' or 'fullVersion' must be specified")) if fullVersion is not None: api_version = 6 version = None else: api_version = 1 apicluster = ApiCluster(resource_root, name, version, fullVersion) return types.call(resource_root.post, CLUSTERS_PATH, ApiCluster, True, data=[apicluster], api_version=api_version)[0]
def get_all_hosts(resource_root, view=None): """Get all hosts :param resource_root: The root Resource object. :return: A list of ApiHost objects. """ return types.call(resource_root.get, HOSTS_PATH, ApiHost, True, params=(dict(view=view) if view else None))
def get_all_clusters(resource_root, view=None): """Get all clusters :param resource_root: The root Resource object. :return: A list of ApiCluster objects. """ return types.call(resource_root.get, CLUSTERS_PATH, ApiCluster, True, params=(dict(view=view) if view else None))
def delete_host(resource_root, host_id): """Delete a host by id :param resource_root: The root Resource object. :param host_id: Host id :return: The deleted ApiHost object """ return types.call(resource_root.delete, "%s/%s" % (HOSTS_PATH, host_id), ApiHost)
def get_user(resource_root, username): """Look up a user by username. @param resource_root: The root Resource object @param username: Username to look up @return: An ApiUser object """ return types.call(resource_root.get, '%s/%s' % (USERS_PATH, username), ApiUser)
def get_cluster(resource_root, name): """Lookup a cluster by name :param resource_root: The root Resource object. :param name: Cluster name :return: An ApiCluster object """ return types.call(resource_root.get, "%s/%s" % (CLUSTERS_PATH, name), ApiCluster)
def delete_service(resource_root, name, cluster_name="default"): """Delete a service by name :param resource_root: The root Resource object. :param name: Service name :param cluster_name: Cluster name :return: The deleted ApiService object """ return types.call(resource_root.delete, "%s/%s" % (SERVICES_PATH % (cluster_name, ), name), ApiService)
def get_all_services(resource_root, cluster_name="default", view=None): """Get all services :param resource_root: The root Resource object. :param cluster_name: Cluster name :return: A list of ApiService objects. """ return types.call(resource_root.get, SERVICES_PATH % (cluster_name, ), ApiService, True, params=(dict(view=view) if view else None))
def get_all_roles(resource_root, service_name, cluster_name="default", view=None): """Get all roles :param resource_root: The root Resource object. :param service_name: Service name :param cluster_name: Cluster name :return: A list of ApiRole objects. """ return types.call(resource_root.get, _get_roles_path(cluster_name, service_name), ApiRole, True, params=(dict(view=view) if view else None))
def delete_role(resource_root, service_name, name, cluster_name="default"): """Delete a role by name :param resource_root: The root Resource object. :param service_name: Service name :param name: Role name :param cluster_name: Cluster name :return: The deleted ApiRole object """ return types.call(resource_root.delete, _get_role_path(cluster_name, service_name, name), ApiRole)
def update_user(resource_root, user): """Update a user. Replaces the user's details with those provided. @param resource_root: The root Resource object @param user: An ApiUser object @return: An ApiUser object """ return types.call(resource_root.put, '%s/%s' % (USERS_PATH, user.name), ApiUser, data=user)
def create_service(resource_root, name, service_type, cluster_name="default"): """Create a service :param resource_root: The root Resource object. :param name: Service name :param service_type: Service type :param cluster_name: Cluster name :return: An ApiService object """ apiservice = ApiService(resource_root, name, service_type) return types.call(resource_root.post, SERVICES_PATH % (cluster_name, ), ApiService, True, data=[apiservice])[0]
def get_all_role_config_groups(resource_root, service_name, cluster_name="default"): """Get all role config groups in the specified service :param resource_root: The root Resource object. :param service_name: Service name. :param cluster_name: Cluster name. :return: A list of ApiRoleConfigGroup objects. :since: API v3 """ return types.call(resource_root.get, _get_role_config_groups_path(cluster_name, service_name), ApiRoleConfigGroup, True, api_version=3)
def create_role(resource_root, service_name, role_type, role_name, host_id, cluster_name="default"): """Create a role :param resource_root: The root Resource object. :param service_name: Service name :param role_type: Role type :param role_name: Role name :param cluster_name: Cluster name :return: An ApiRole object """ apirole = ApiRole(resource_root, role_name, role_type, types.ApiHostRef(resource_root, host_id)) return types.call(resource_root.post, _get_roles_path(cluster_name, service_name), ApiRole, True, data=[apirole])[0]
def _get_service(resource_root, path): return types.call(resource_root.get, path, ApiService)
def _get_role(resource_root, path): return types.call(resource_root.get, path, ApiRole)