Sandro Bonazzola has uploaded a new change for review.

Change subject: bin: add the host to a specific cluster
......................................................................

bin: add the host to a specific cluster

Fix bz #1059950 - Ask the user which cluster to use. Default cluster is
'Default' if exists. Otherwise, the default is engine_api.clusters.list()[0]

Change-Id: I00167e70296645e5cf732b64d87efa1cf66ca783
Signed-off-by: Meital Bourvine <mbour...@redhat.com>
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
Bug-Url: http://bugzilla.redhat.com/1059950
Bug-Url: http://bugzilla.redhat.com/1043906
(cherry picked from commit 122b1e2b180bb73c2444f2faa1a8ded805aba1cf)
---
M src/plugins/ovirt-hosted-engine-setup/engine/add_host.py
1 file changed, 29 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/53/26353/1

diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py 
b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py
index cd6449d..8f11a9f 100644
--- a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py
+++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py
@@ -1,6 +1,6 @@
 #
 # ovirt-hosted-engine-setup -- ovirt hosted engine setup
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013-2014 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -399,6 +399,8 @@
     def _closeup(self):
         self._getPKICert()
         self._getSSHkey()
+        cluster_name = None
+        default_cluster_name = 'Default'
         try:
             self.logger.debug('Connecting to the Engine')
             engine_api = self._ovirtsdk_api.API(
@@ -414,6 +416,19 @@
                 ca_file=self.cert,
             )
             self.logger.debug('Adding the host to the cluster')
+            cluster_l = [c.get_name() for c in engine_api.clusters.list()]
+            cluster_name = default_cluster_name if default_cluster_name in \
+                cluster_l else cluster_l[0]
+            cluster_name = self.dialog.queryString(
+                name='cluster_name',
+                note=_(
+                    'Enter the name of the cluster to which you want to add '
+                    'the host (@VALUES@) [@DEFAULT@]: '
+                ),
+                prompt=True,
+                default=cluster_name,
+                validValues=cluster_l,
+            )
             engine_api.hosts.add(
                 self._ovirtsdk_xml.params.Host(
                     name=self.environment[
@@ -421,7 +436,7 @@
                     ],
                     address=self._getIPAddress(),
                     reboot_after_installation=False,
-                    cluster=engine_api.clusters.get('Default'),
+                    cluster=engine_api.clusters.get(cluster_name),
                     ssh=self._ovirtsdk_xml.params.SSH(
                         authentication_method='publickey',
                         port=self.environment[
@@ -433,14 +448,17 @@
             )
         except ovirtsdk.infrastructure.errors.RequestError as e:
             self.logger.debug(
-                'Cannot add the host to the Default cluster',
+                'Cannot add the host to cluster {cluster}'.format(
+                    cluster=cluster_name,
+                ),
                 exc_info=True,
             )
             self.logger.error(
                 _(
                     'Cannot automatically add the host '
-                    'to the Default cluster:\n{details}\n'
+                    'to cluster {cluster:}\n{details}\n'
                 ).format(
+                    cluster=cluster_name,
                     details=e.detail
                 )
             )
@@ -462,7 +480,7 @@
             #This works only if the host is up.
             self.logger.debug('Setting CPU for the cluster')
             try:
-                cluster = engine_api.clusters.get('Default')
+                cluster = engine_api.clusters.get(cluster_name)
                 self.logger.debug(cluster.__dict__)
                 cpu = self._wait_cluster_cpu_ready(cluster)
                 self.logger.debug(cpu.__dict__)
@@ -471,14 +489,17 @@
                 cluster.update()
             except ovirtsdk.infrastructure.errors.RequestError as e:
                 self.logger.debug(
-                    'Cannot set the CPU level to the Default cluster',
+                    'Cannot set CPU level of cluster {cluster}'.format(
+                        cluster=cluster_name,
+                    ),
                     exc_info=True,
                 )
                 self.logger.error(
                     _(
-                        'Cannot automatically set the CPU '
-                        'to the Default cluster:\n{details}\n'
+                        'Cannot automatically set CPU level '
+                        'of cluster {cluster}:\n{details}\n'
                     ).format(
+                        cluster=cluster_name,
                         details=e.detail
                     )
                 )


-- 
To view, visit http://gerrit.ovirt.org/26353
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I00167e70296645e5cf732b64d87efa1cf66ca783
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: ovirt-hosted-engine-setup-1.1
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
Gerrit-Reviewer: Meital Bourvine <mbour...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to