Author: gnichols
Date: 2012-03-09 12:28:45 +0000 (Fri, 09 Mar 2012)
New Revision: 1217
Added:
trunk/v7/catalog.py
Log:
782191 - FEAT: v7 should be able to open a new certification request
Added: trunk/v7/catalog.py
===================================================================
--- trunk/v7/catalog.py (rev 0)
+++ trunk/v7/catalog.py 2012-03-09 12:28:45 UTC (rev 1217)
@@ -0,0 +1,81 @@
+# Copyright (c) 2012 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Author: Greg Nichols
+#
+# Catalog is the client-side python interface to the hardware catalog web site,
+
+# Notes:
+# The catalog instance (server URL) is taken from the enviroment (/etc/v7.xml).
+
+import xmlrpclib
+import urllib2
+
+from v7.controller import Controller
+from v7.environment import Environment
+from v7.tags import Tags
+
+class Catalog(Controller):
+
+ def __init__(self):
+ Controller.__init__(self)
+ self.environment = Environment()
+
+ def isReachable(self):
+ """ check to see that the catalog server is reachable
"""
+ catalogServer = self.environment.getCatalogURL()
+ # get just the server URL by stripping off the end of the URL (find the / at
least 7 characters from the left).
+ catalogServer = catalogServer[0:catalogServer.index('/', 7)]
+ try:
+ request = urllib2.urlopen(catalogServer)
+ except Exception, e:
+ print "Could not reach catalog server %s" % catalogServer
+ print e
+ return False
+ return True
+
+ def openCertification(self, certificationDocument):
+
+ if not self.ui.promptConfirm("\nWould you like to open a new certification
request?"):
+ return None
+
+ tags = [Tags.make, Tags.model, Tags.vendor, Tags.category, Tags.product_url,
Tags.arch]
+ hardware = dict()
+ for tag in tags:
+ hardware[tag] = certificationDocument.getHardware(tag)
+
+ # get the RHEL version
+ rhelVersion = certificationDocument.getOS(Tags.release)
+
+ login = self.ui.prompt("Red Hat Catalog User Name: ")
+ password = self.ui.promptPassword("Password: ")
+
+ serverProxy = xmlrpclib.ServerProxy(self.environment.getCatalogURL())
+ try:
+ certificationID = serverProxy.Cert.create(login, password,
+ hardware[Tags.make], hardware[Tags.model],
hardware[Tags.vendor], rhelVersion,
+ hardware[Tags.arch], hardware[Tags.category],
hardware[Tags.product_url])
+
+ except xmlrpclib.Fault, error:
+ print "Error: could not open a new certification:"
+ print " Fault code: %d" % error.faultCode
+ print " Fault string: %s" % error.faultString
+ return None
+ except Exception, e:
+ print "Error: could not open a new certification:"
+ print e
+ return None
+
+ certificationDocument.setCertificationID(certificationID)
+
+ return certificationID
Show replies by date