You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/07/05 09:13:37 UTC

[1/6] libcloud git commit: change_vm_admin_password as public method.

Repository: libcloud
Updated Branches:
  refs/heads/trunk f817e2026 -> 5cea658c9


change_vm_admin_password as public method.


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

Branch: refs/heads/trunk
Commit: fa4a89af36ce65bbe7424a2a99a0d3f341f744f8
Parents: 9fbf6e7
Author: Juan Font Alonso <ju...@gmail.com>
Authored: Tue Jul 5 09:21:44 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Jul 5 19:12:06 2016 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/vcloud.py   | 4 ++--
 libcloud/test/compute/test_vcloud.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/fa4a89af/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index 722e9b9..f8067c9 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -1490,7 +1490,7 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
         self._change_vm_ipmode(vapp_href, ex_vm_ipmode)
 
         if ex_admin_password is not None:
-            self._change_vm_admin_password(vapp_href, ex_admin_password)
+            self.ex_change_vm_admin_password(vapp_href, ex_admin_password)
 
         # Power on the VM.
         if ex_deploy:
@@ -2010,7 +2010,7 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
             res.object.insert(i, e)
         return res
 
-    def _change_vm_admin_password(self, vapp_or_vm_id, ex_admin_password):
+    def ex_change_vm_admin_password(self, vapp_or_vm_id, ex_admin_password):
         if ex_admin_password is None:
             return
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/fa4a89af/libcloud/test/compute/test_vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_vcloud.py b/libcloud/test/compute/test_vcloud.py
index 1f1dfa3..94ac09a 100644
--- a/libcloud/test/compute/test_vcloud.py
+++ b/libcloud/test/compute/test_vcloud.py
@@ -204,7 +204,7 @@ class VCloud_1_5_Tests(unittest.TestCase, TestCaseMixin):
             '/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6a', ['changed1', 'changed2'])
 
     def test_change_vm_admin_password(self):
-        self.driver._change_vm_admin_password(
+        self.driver.ex_change_vm_admin_password(
             '/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6a', "12345678")
 
     def test_is_node(self):


[6/6] libcloud git commit: Changes for #833

Posted by an...@apache.org.
Changes for #833


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

Branch: refs/heads/trunk
Commit: 5cea658c90463e14de0bcf175d21cde3eca482ab
Parents: 5430cd2
Author: Anthony Shaw <an...@apache.org>
Authored: Tue Jul 5 19:13:27 2016 +1000
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Jul 5 19:13:27 2016 +1000

----------------------------------------------------------------------
 CHANGES.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5cea658c/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index ddac508..c12b58a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,16 @@
 \ufeffChangelog
 =========
 
+Changes in current version of Apache Libcloud
+---------------------------------------------
+
+Compute
+~~~~~~~
+
+- Add support for changing VM admin password in VMware driver
+  (GITHUB-833)
+  [Juan Font Alonso]
+
 Changes with Apache Libcloud 1.1.0
 ----------------------------------
 


[2/6] libcloud git commit: Added support to set the VM admin password from VCloud.

Posted by an...@apache.org.
Added support to set the VM admin password from VCloud.


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

Branch: refs/heads/trunk
Commit: 86969f918f74ffb22025a6d8719db74700e624c3
Parents: f817e20
Author: Juan Font Alonso <ju...@gmail.com>
Authored: Mon Jul 4 16:15:04 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Jul 5 19:12:06 2016 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/vcloud.py | 80 +++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/86969f91/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index d428cad..50cbd9a 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -1433,6 +1433,9 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
                                       Overrides the default task completion
                                       value.
         :type       ex_clone_timeout: ``int``
+
+        :keyword    ex_admin_password: set the node admin password explicitly.
+        :type       ex_admin_password: ``str``
         """
         name = kwargs['name']
         image = kwargs['image']
@@ -1449,6 +1452,7 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
         ex_vdc = kwargs.get('ex_vdc', None)
         ex_clone_timeout = kwargs.get('ex_clone_timeout',
                                       DEFAULT_TASK_COMPLETION_TIMEOUT)
+        ex_admin_password = kwargs.get('ex_admin_password', None)
 
         self._validate_vm_names(ex_vm_names)
         self._validate_vm_cpu(ex_vm_cpu)
@@ -1485,6 +1489,9 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
         self._change_vm_script(vapp_href, ex_vm_script)
         self._change_vm_ipmode(vapp_href, ex_vm_ipmode)
 
+        if ex_admin_password is not None:
+            self._change_vm_admin_password(vapp_href, ex_admin_password)
+
         # Power on the VM.
         if ex_deploy:
             res = self.connection.request(get_url_path(vapp_href))
@@ -1986,6 +1993,79 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
             )
             self._wait_for_task_completion(res.object.get('href'))
 
+    def _update_or_insert_section(self, res, section, prev_section, text):
+        try:
+            res.object.find(
+                fixxpath(res.object, section)).text = text
+        except:
+            # "section" section does not exist, insert it just
+            # before "prev_section"
+            for i, e in enumerate(res.object):
+                if e.tag == \
+                                '{http://www.vmware.com/vcloud/v1.5}%s' % prev_section:
+                    break
+            e = ET.Element(
+                '{http://www.vmware.com/vcloud/v1.5}%s' % section)
+            e.text = text
+            res.object.insert(i, e)
+        return res
+
+    def _change_vm_admin_password(self, vapp_or_vm_id, ex_admin_password):
+        if ex_admin_password is None:
+            return
+
+        vms = self._get_vm_elements(vapp_or_vm_id)
+        for vm in vms:
+            # Get GuestCustomizationSection
+            res = self.connection.request(
+                '%s/guestCustomizationSection' % get_url_path(vm.get('href')))
+
+            headers = {
+                'Content-Type':
+                'application/vnd.vmware.vcloud.guestCustomizationSection+xml'
+            }
+
+            # Fix API quirk.
+            # If AdminAutoLogonEnabled==False the guestCustomizationSection
+            # must have AdminAutoLogonCount==0, even though
+            # it might have AdminAutoLogonCount==1 when requesting it for
+            # the first time.
+            auto_logon_enabled = res.object.find(
+                fixxpath(res.object, "AdminAutoLogonEnabled"))
+            if (auto_logon_enabled is not None
+                and auto_logon_enabled.text=='false'):
+                self._update_or_insert_section(res,
+                                               "AdminAutoLogonCount",
+                                               "ResetPasswordRequired",
+                                               '0')
+
+            # If we are establishing a password we do not want it
+            # to be automatically chosen.
+            self._update_or_insert_section(res,
+                                           'AdminPasswordAuto',
+                                           'AdminPassword',
+                                           'false')
+
+            # API does not allow to set AdminPassword if
+            # AdminPasswordEnabled is not enabled.
+            self._update_or_insert_section(res,
+                                           'AdminPasswordEnabled',
+                                           'AdminPasswordAuto',
+                                           'true')
+
+            self._update_or_insert_section(res,
+                                           'AdminPassword',
+                                           'AdminAutoLogonEnabled',
+                                           ex_admin_password)
+
+            res = self.connection.request(
+                '%s/guestCustomizationSection' % get_url_path(vm.get('href')),
+                data=ET.tostring(res.object),
+                method='PUT',
+                headers=headers
+            )
+            self._wait_for_task_completion(res.object.get('href'))
+
     def _get_network_href(self, network_name):
         network_href = None
 


[5/6] libcloud git commit: Added documentation. Closes #833

Posted by an...@apache.org.
Added documentation.
Closes #833


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

Branch: refs/heads/trunk
Commit: 5430cd25d75e171c2eb0a7dcec5c40c4e19fad8a
Parents: fa4a89a
Author: Juan Font Alonso <ju...@gmail.com>
Authored: Tue Jul 5 09:28:22 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Jul 5 19:12:11 2016 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/vcloud.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5430cd25/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index f8067c9..2766853 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -2011,6 +2011,21 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
         return res
 
     def ex_change_vm_admin_password(self, vapp_or_vm_id, ex_admin_password):
+        """
+        Changes the admin (or root) password of VM or VMs under the vApp. If
+        the vapp_or_vm_id param represents a link to an vApp all VMs that
+        are attached to this vApp will be modified.
+
+        :keyword    vapp_or_vm_id: vApp or VM ID that will be modified. If a
+                                   vApp ID is used here all attached VMs
+                                   will be modified
+        :type       vapp_or_vm_id: ``str``
+
+        :keyword    ex_admin_password: admin password to be used.
+        :type       ex_admin_password: ``str``
+
+        :rtype: ``None``
+        """
         if ex_admin_password is None:
             return
 


[4/6] libcloud git commit: Added basic test for internal method.

Posted by an...@apache.org.
Added basic test for internal method.


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

Branch: refs/heads/trunk
Commit: 4b0fd03f14157c505c8443bfb9e6db629a0d75b2
Parents: 86969f9
Author: Juan Font Alonso <ju...@gmail.com>
Authored: Mon Jul 4 16:48:33 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Jul 5 19:12:06 2016 +1000

----------------------------------------------------------------------
 libcloud/test/compute/test_vcloud.py | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4b0fd03f/libcloud/test/compute/test_vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_vcloud.py b/libcloud/test/compute/test_vcloud.py
index 9ba1d34..1f1dfa3 100644
--- a/libcloud/test/compute/test_vcloud.py
+++ b/libcloud/test/compute/test_vcloud.py
@@ -203,6 +203,10 @@ class VCloud_1_5_Tests(unittest.TestCase, TestCaseMixin):
         self.driver._change_vm_names(
             '/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6a', ['changed1', 'changed2'])
 
+    def test_change_vm_admin_password(self):
+        self.driver._change_vm_admin_password(
+            '/api/vApp/vapp-8c57a5b6-e61b-48ca-8a78-3b70ee65ef6a', "12345678")
+
     def test_is_node(self):
         self.assertTrue(self.driver._is_node(
             Node('testId', 'testNode', state=0, public_ips=[], private_ips=[], driver=self.driver)))


[3/6] libcloud git commit: Fixed small style issues.

Posted by an...@apache.org.
Fixed small style issues.


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

Branch: refs/heads/trunk
Commit: 9fbf6e7871441b67059f21b3de0e46a3ea8d8ef1
Parents: 4b0fd03
Author: Juan Font Alonso <ju...@gmail.com>
Authored: Mon Jul 4 17:12:27 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Jul 5 19:12:06 2016 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/vcloud.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/9fbf6e78/libcloud/compute/drivers/vcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/vcloud.py b/libcloud/compute/drivers/vcloud.py
index 50cbd9a..722e9b9 100644
--- a/libcloud/compute/drivers/vcloud.py
+++ b/libcloud/compute/drivers/vcloud.py
@@ -2001,8 +2001,8 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
             # "section" section does not exist, insert it just
             # before "prev_section"
             for i, e in enumerate(res.object):
-                if e.tag == \
-                                '{http://www.vmware.com/vcloud/v1.5}%s' % prev_section:
+                tag = '{http://www.vmware.com/vcloud/v1.5}%s' % prev_section
+                if e.tag == tag:
                     break
             e = ET.Element(
                 '{http://www.vmware.com/vcloud/v1.5}%s' % section)
@@ -2030,10 +2030,9 @@ class VCloud_1_5_NodeDriver(VCloudNodeDriver):
             # must have AdminAutoLogonCount==0, even though
             # it might have AdminAutoLogonCount==1 when requesting it for
             # the first time.
-            auto_logon_enabled = res.object.find(
+            auto_logon = res.object.find(
                 fixxpath(res.object, "AdminAutoLogonEnabled"))
-            if (auto_logon_enabled is not None
-                and auto_logon_enabled.text=='false'):
+            if auto_logon is not None and auto_logon.text == 'false':
                 self._update_or_insert_section(res,
                                                "AdminAutoLogonCount",
                                                "ResetPasswordRequired",