Repository: ambari
Updated Branches:
  refs/heads/trunk 89203a38b -> 341619701


AMBARI-6554. Python client: add ability to create cluster using blueprint (Greg 
Hell via Subin)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/34161970
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/34161970
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/34161970

Branch: refs/heads/trunk
Commit: 3416197017f766addf22d985900cd94a862dddca
Parents: 89203a3
Author: subin <[email protected]>
Authored: Tue Aug 12 01:39:29 2014 +0530
Committer: subin <[email protected]>
Committed: Tue Aug 12 01:39:29 2014 +0530

----------------------------------------------------------------------
 .../src/main/python/ambari_client/ambari_api.py | 24 ++++++++++++---
 .../python/ambari_client/model/blueprint.py     |  6 ++--
 .../main/python/ambari_client/model/cluster.py  | 31 ++++++++++++++++++++
 3 files changed, 54 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/34161970/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
----------------------------------------------------------------------
diff --git 
a/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py 
b/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
index a79d907..d3832c8 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/ambari_api.py
@@ -145,6 +145,22 @@ class AmbariClient(RestResource):
         """
         return cluster._create_cluster(self, cluster_name, version)
 
+    def create_cluster_from_blueprint(self, cluster_name, blueprint_name, 
+                                      host_groups, configurations=None, 
+                                      default_password=None):
+        """
+        Create a new cluster.
+        @param cluster_name: Cluster cluster_name
+        @param blueprint_name: the name of the blueprint
+        @param host_groups: an array of host_group information
+        @param configurations: an array of configuration overrides
+        @param default_password: the default password to use for all 
password-requiring services
+        @return  ClusterModel object.
+        """
+        return cluster._create_cluster_from_blueprint(self, cluster_name, 
+            blueprint_name, host_groups, configurations=configurations, 
+            default_password=default_password)
+
     def delete_cluster(self, cluster_name):
         """
         Delete a cluster
@@ -240,7 +256,7 @@ class AmbariClient(RestResource):
         """
         return status._get_N_requests(self, cluster_name, noOfrequest)
 
-    def get_blueprint(self, blueprint_name=None):
+    def get_blueprint(self, blueprint_name):
         """
         get blueprint
         @param blueprint_name:blueprint_name name.
@@ -256,7 +272,7 @@ class AmbariClient(RestResource):
         """
         return blueprint.get_cluster_blueprint(self, cluster_name)
 
-    def delete_blueprint(self, blueprint_name=None):
+    def delete_blueprint(self, blueprint_name):
         """
         get blueprint
         @param blueprint_name:blueprint_name name.
@@ -264,13 +280,13 @@ class AmbariClient(RestResource):
         """
         return blueprint.delete_blueprint(self, blueprint_name)
 
-    def create_blueprint(self, blueprint_name=None):
+    def create_blueprint(self, blueprint_name, blueprint_schema):
         """
         get blueprint
         @param blueprint_name:blueprint_name name.
         @return: A BlueprintModel object
         """
-        return blueprint.create_blueprint(self, blueprint_name)
+        return blueprint.create_blueprint(self, blueprint_name, 
blueprint_schema)
 
 
 def get_root_resource(

http://git-wip-us.apache.org/repos/asf/ambari/blob/34161970/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
----------------------------------------------------------------------
diff --git 
a/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py 
b/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
index e207a6b..21b0b33 100644
--- 
a/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
+++ 
b/ambari-client/python-client/src/main/python/ambari_client/model/blueprint.py
@@ -88,16 +88,16 @@ def delete_blueprint(resource_root, blueprint_name):
         "NO_KEY")
 
 
-def create_blueprint(resource_root, blueprint_name, json_data):
+def create_blueprint(resource_root, blueprint_name, blueprint_schema):
     """
     Create a blueprint
     @param root_resource: The root Resource.
     @param blueprint_name: blueprint_name
-    @param json_data: blueprint  json
+    @param blueprint_schema: blueprint  json
     @return: An ClusterModel object
     """
     path = paths.BLUEPRINT_PATH % blueprint_name
-    resp = resource_root.post(path=path, payload=json_data)
+    resp = resource_root.post(path=path, payload=blueprint_schema)
     return utils.ModelUtils.create_model(
         status.StatusModel,
         resp,

http://git-wip-us.apache.org/repos/asf/ambari/blob/34161970/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
----------------------------------------------------------------------
diff --git 
a/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py 
b/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
index 87cd86e..7e0b378 100644
--- a/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
+++ b/ambari-client/python-client/src/main/python/ambari_client/model/cluster.py
@@ -72,6 +72,37 @@ def _create_cluster(root_resource, cluster_name, version):
         "NO_KEY")
 
 
+def _create_cluster_from_blueprint(root_resource, cluster_name, 
blueprint_name, 
+                                   host_groups, configurations=None, 
+                                   default_password=None):
+    """
+    Create a cluster
+    @param root_resource: The root Resource.
+    @param cluster_name: Cluster cluster_name
+    @param blueprint_name: the name of the blueprint
+    @param host_groups: an array of host_group information
+    @param configurations: an array of configuration overrides
+    @param default_password: the default password to use for all 
password-requiring services
+    @return: An StatusModel object
+    """
+    data = {
+      "blueprint" : blueprint_name,
+      "host_groups" : host_groups,
+    }
+    if configurations is not None:
+        data['configurations'] = configurations
+    if default_password is not None:
+        data['default_password'] = default_password
+
+    path = paths.CLUSTERS_PATH + "/%s" % (cluster_name)
+    resp = root_resource.post(path=path, payload=data)
+    return utils.ModelUtils.create_model(
+        status.StatusModel,
+        resp,
+        root_resource,
+        "NO_KEY")
+
+
 def _delete_cluster(root_resource, cluster_name):
     """
     Delete a cluster by name

Reply via email to