From 02bf9dcaaea842bf0582cb4e116b32629d60aab8 Mon Sep 17 00:00:00 2001
From: tengqm <tengqim@cn.ibm.com>
Date: Mon, 26 Jan 2015 13:33:55 +0800
Subject: [PATCH] Initial support to cluster create

---
 senlinclient/v1/client.py |  5 ++++-
 senlinclient/v1/models.py |  3 +--
 senlinclient/v1/shell.py  | 15 ++++++++++-----
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/senlinclient/v1/client.py b/senlinclient/v1/client.py
index b34f7d49..56bacc5c 100644
--- a/senlinclient/v1/client.py
+++ b/senlinclient/v1/client.py
@@ -69,7 +69,10 @@ class Client(object):
 
     def create(self, cls, params):
         obj = cls.new(**params)
-        return obj.create(self.session)
+        try:
+            return obj.create(self.session)
+        except exc.HttpException as ex:
+            client_exc.parse_exception(ex)
 
     def get(self, cls, options=None):
         try:
diff --git a/senlinclient/v1/models.py b/senlinclient/v1/models.py
index f9d64253..136e7503 100644
--- a/senlinclient/v1/models.py
+++ b/senlinclient/v1/models.py
@@ -186,7 +186,7 @@ class Cluster(resource.Resource):
     allow_list = True
 
     # Properties
-    links = resource.prop('links', type=dict)
+    id = resource.prop('id')
     name = resource.prop('name')
     profile_id = resource.prop('profile_id')
     user = resource.prop('user')
@@ -256,7 +256,6 @@ class Node(resource.Resource):
     allow_list = True
 
     # Properties
-    links = resource.prop('links', type=dict)
     id = resource.prop('id')
     name = resource.prop('name')
     physical_id = resource.prop('physical_id')
diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py
index 16de6442..ff8f5c3e 100644
--- a/senlinclient/v1/shell.py
+++ b/senlinclient/v1/shell.py
@@ -260,8 +260,9 @@ def do_cluster_list(sc, args=None):
            help=_('Profile Id used for this cluster.'))
 @utils.arg('-n', '--size', metavar='<NUMBER>',
            help=_('Initial size of the cluster.'))
-@utils.arg('-t', '--timeout', metavar='<TIMEOUT>',
-           type=int,
+@utils.arg('-o', '--parent', metavar='<PARENT_ID>',
+           help=_('ID of the parent cluster, if exists.'))
+@utils.arg('-t', '--timeout', metavar='<TIMEOUT>', type=int,
            help=_('Cluster creation timeout in minutes.'))
 @utils.arg('-g', '--tags', metavar='<KEY1=VALUE1;KEY2=VALUE2...>',
            help=_('Tag values to be attached to the cluster. '
@@ -275,13 +276,17 @@ def do_cluster_create(sc, args):
     params = {
         'name': args.name,
         'profile_id': args.profile,
-        'tags': utils.format_parameters(args.tags),
         'size': args.size,
+        'parent': args.parent,
+        'tags': utils.format_parameters(args.tags),
         'timeout': args.timeout
     }
 
-    sc.create(models.Cluster, params)
-    do_cluster_list(sc)
+    cluster, resp = sc.create(models.Cluster, params)
+    print(_('Action CLUSTER_CREATE(%(action)s) scheduled for '
+            'cluster %(cluster)s') % {
+                'action': resp['action_id'],
+                'cluster': resp['id']})
 
 
 @utils.arg('id', metavar='<NAME or ID>', nargs='+',