Hello Alex Lourie,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/18309

to review the following change.

Change subject: sdk: aligning API initialization with iso-uploader
......................................................................

sdk: aligning API initialization with iso-uploader

Aligning API initialization method with iso-uploader.
This includes:
- fixed creating objects in an insecure way
- align imageuploader.conf with isouploader.conf
- align sdk version requirement

Excludes:
- add the nossl option for the engine connection
(doesn't work correctly)

Change-Id: I59e9d95cd76a961265acc5475be6db7843b75121
Related-To: http://gerrit.ovirt.org/9288
Related-To: http://gerrit.ovirt.org/10815
Bug-Url: https://bugzilla.redhat.com/951100
Signed-off-by: Alex Lourie <[email protected]>
Signed-off-by: Sandro Bonazzola <[email protected]>
---
M ovirt-image-uploader.spec.in
M src/__main__.py
M src/imageuploader.conf
3 files changed, 73 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-image-uploader 
refs/changes/09/18309/1

diff --git a/ovirt-image-uploader.spec.in b/ovirt-image-uploader.spec.in
index ca9f643..859fbb1 100644
--- a/ovirt-image-uploader.spec.in
+++ b/ovirt-image-uploader.spec.in
@@ -29,10 +29,10 @@
 BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}
 BuildArch:     noarch
 Requires:      python
-Requires:      ovirt-engine-sdk
+Requires:      ovirt-engine-sdk >= 3.2.0.10-1
 Requires:      logrotate
-BuildRequires: python2-devel
 BuildRequires: gettext
+BuildRequires: python2-devel
 
 %description
 Image Uploader tool for oVirt Engine
diff --git a/src/__main__.py b/src/__main__.py
index 2628797..728dc2e 100644
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -383,11 +383,9 @@
         else:
             raise Exception(_("A valid command was not specified."))
 
-
-
     def _initialize_api(self):
         """
-        Make a RESTful request to the supplied oVirt method.
+        Make a RESTful request to the supplied oVirt Engine method.
         """
         if not self.configuration:
             raise Exception("No configuration.")
@@ -395,40 +393,83 @@
         if self.api is None:
             # The API has not been initialized yet.
             try:
-                self.configuration.prompt("engine", msg=_("hostname of oVirt 
Engine"))
-                self.configuration.prompt("user", msg=_("REST API username for 
oVirt Engine"))
-                self.configuration.getpass("passwd", msg=_("REST API password 
for the %s oVirt Engine user") % self.configuration.get("user"))
+                self.configuration.prompt(
+                    "engine",
+                    msg=_("hostname of oVirt Engine")
+                )
+                self.configuration.prompt(
+                    "user",
+                    msg=_("REST API username for oVirt Engine")
+                )
+                self.configuration.getpass(
+                    "passwd",
+                    msg=(
+                        _("REST API password for the %s oVirt Engine user") %
+                        self.configuration.get("user")
+                    )
+                )
             except Configuration.SkipException:
-                raise Exception("Insufficient information provided to 
communicate with the oVirt Engine REST API.")
+                raise Exception(
+                    "Insufficient information provided to communicate with "
+                    "the oVirt Engine REST API."
+                )
 
             url = "https://"; + self.configuration.get("engine") + "/api"
+
             try:
-                self.api = API(url=url,
-                               username=self.configuration.get("user"),
-                               password=self.configuration.get("passwd"),
-                               ca_file=self.configuration.get("cert_file"),
-                               insecure=self.configuration.get("insecure"))
+                # If "insecure" option was provided, use it during API creation
+                self.api = API(
+                    url=url,
+                    username=self.configuration.get("user"),
+                    password=self.configuration.get("passwd"),
+                    ca_file=self.configuration.get("cert_file"),
+                    validate_cert_chain=not self.configuration.get("insecure"),
+                )
 
                 pi = self.api.get_product_info()
                 if pi is not None:
-                    vrm = '%s.%s.%s' % (pi.get_version().get_major(),
-                                        pi.get_version().get_minor(),
-                                        pi.get_version().get_revision())
-                    logging.debug("API Vendor(%s)\tAPI Version(%s)" %  
(pi.get_vendor(), vrm))
+                    vrm = '%s.%s.%s' % (
+                        pi.get_version().get_major(),
+                        pi.get_version().get_minor(),
+                        pi.get_version().get_revision()
+                    )
+                    logging.debug(
+                        "API Vendor(%s)\tAPI Version(%s)",
+                        pi.get_vendor(),
+                        vrm
+                    )
                 else:
                     logging.error(_("Unable to connect to REST API."))
                     return False
             except RequestError, re:
-                logging.error(_("Unable to connect to REST API.  Reason: %s") 
%  re.reason)
+                logging.error(
+                    _("Unable to connect to REST API.  Reason: %s"),
+                    re.reason
+                )
                 return False
             except ConnectionError:
-                logging.error(_("Problem connecting to the REST API.  Is the 
service available and does the CA certificate exist?"))
+                logging.error(
+                    _(
+                        "Problem connecting to the REST API.  Is the "
+                        "service available and does the CA certificate "
+                        "exist?"
+                    )
+                )
                 return False
             except NoCertificatesError:
-                logging.error(_("Problem connecting to the REST API.  The CA 
is invalid.  To override use the \'insecure\' option."))
+                logging.error(
+                    _(
+                        "Problem connecting to the REST API.  The CA is "
+                        "invalid.  To override use the \'insecure\' "
+                        "option."
+                    )
+                )
                 return False
             except Exception, e:
-                logging.error(_("Unable to connect to REST API.  Message: %s") 
%  e)
+                logging.error(
+                    _("Unable to connect to REST API.  Message: %s"),
+                    e
+                )
                 return False
         return True
 
diff --git a/src/imageuploader.conf b/src/imageuploader.conf
index 3996ba2..34baf75 100644
--- a/src/imageuploader.conf
+++ b/src/imageuploader.conf
@@ -8,7 +8,8 @@
 #passwd=PASSWORD
 ## hostname or IP address of the oVirt Engine
 #engine=localhost:443
-
+## CA certificate used to validate the engine.
+#cert-file=/etc/pki/ovirt-engine/ca.pem
 
 #
 ###  Export Storage Domain Configuration
@@ -21,3 +22,11 @@
 ## supply this option if you want to rename the template name (i.e. Name) of 
the image
 #template-name=TEMPLATE_NAME
 
+#
+###  SSH Configuration
+## the SSH user that the program will use for SSH file transfers.
+#ssh-user=USER
+## the port to ssh and scp on
+#ssh-port=22
+## the identity file (private key) to be used for accessing the file server.
+#key-file=KEYFILE


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I59e9d95cd76a961265acc5475be6db7843b75121
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-image-uploader
Gerrit-Branch: master
Gerrit-Owner: Sandro Bonazzola <[email protected]>
Gerrit-Reviewer: Alex Lourie <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to