Package pulp :: Package client :: Package core :: Module core_package
[hide private]
[frames] | no frames]

Source Code for Module pulp.client.core.core_package

  1  #!/usr/bin/python 
  2  # 
  3  # Pulp Registration and subscription module 
  4  # Copyright (c) 2010 Red Hat, Inc. 
  5  # 
  6  # This software is licensed to you under the GNU General Public License, 
  7  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  8  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  9  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 10  # along with this software; if not, see 
 11  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 12  # 
 13  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 14  # granted to use or replicate Red Hat trademarks that are incorporated 
 15  # in this software or its documentation. 
 16  # 
 17   
 18  import sys 
 19  import os.path 
 20  from pulp.client.core.basecore import BaseCore, systemExit 
 21  from pulp.client.connection import RepoConnection, ConsumerConnection, RestlibException 
 22  from pulp.client.connection import ConsumerGroupConnection 
 23  from pulp.client.logutil import getLogger 
 24  from pulp.client.config import Config 
 25  log = getLogger(__name__) 
 26  CFG = Config() 
 27  #TODO: move this to config 
 28  CONSUMERID = "/etc/pulp/consumer" 
 29  import gettext 
 30  _ = gettext.gettext 
 31   
32 -class package(BaseCore):
33 - def __init__(self):
34 usage = "package [OPTIONS]" 35 shortdesc = "package specific actions to pulp server." 36 desc = "" 37 self.name = "package" 38 self.actions = {"info" : "lookup information for a package", 39 "install" : "Schedule a package Install", } 40 BaseCore.__init__(self, "package", usage, shortdesc, desc) 41 self.pconn = None 42 self.cconn = None
43
44 - def load_server(self):
45 self.pconn = RepoConnection(host=CFG.server.host or "localhost", 46 port=443, username=self.username, 47 password=self.password, 48 cert_file=self.cert_filename, 49 key_file=self.key_filename) 50 self.cconn = ConsumerConnection(host=CFG.server.host or "localhost", 51 port=443, username=self.username, 52 password=self.password, 53 cert_file=self.cert_filename, 54 key_file=self.key_filename) 55 self.cgconn = ConsumerGroupConnection(host=CFG.server.host or "localhost", 56 port=443, username=self.username, 57 password=self.password, 58 cert_file=self.cert_filename, 59 key_file=self.key_filename)
60
61 - def generate_options(self):
62 self.action = self._get_action() 63 if self.action == "info": 64 usage = "package info [OPTIONS]" 65 self.setup_option_parser(usage, "", True) 66 self.parser.add_option("-n", "--name", dest="name", 67 help="package name to lookup") 68 self.parser.add_option("--repoid", dest="repoid", 69 help="Repository Label") 70 if self.action == "install": 71 usage = "package install [OPTIONS]" 72 self.setup_option_parser(usage, "", True) 73 self.parser.add_option("-n", "--name", action="append", dest="pnames", 74 help="Packages to be installed. \ 75 To specify multiple packages use multiple -n") 76 self.parser.add_option("--consumerid", dest="consumerid", 77 help="Consumer Id") 78 self.parser.add_option("--consumergroupid", dest="consumergroupid", 79 help="Consumer Group Id")
80
81 - def _do_core(self):
82 if self.action == "info": 83 self._info() 84 if self.action == "install": 85 self._install()
86
87 - def _info(self):
88 if not self.options.name: 89 print("package name required. Try --help") 90 sys.exit(0) 91 if not self.options.repoid: 92 print("repo id required. Try --help") 93 sys.exit(0) 94 try: 95 pkg = self.pconn.get_package(self.options.repoid, self.options.name) 96 if not pkg: 97 print("Package [%s] not found in repo [%s]" % (self.options.name, self.options.repoid)) 98 sys.exit(-1) 99 print """+-------------------------------------------+\n Package Information \n+-------------------------------------------+""" 100 for key, value in pkg.items(): 101 print """%s: \t%-25s""" % (key, value) 102 except RestlibException, re: 103 log.error("Error: %s" % re) 104 systemExit(re.code, re.msg) 105 except Exception, e: 106 log.error("Error: %s" % e) 107 raise
108
109 - def _install(self):
110 if not self.options.consumerid and not self.options.consumergroupid: 111 print("consumer or consumer group id required. Try --help") 112 sys.exit(0) 113 if not self.options.pnames: 114 print("Nothing to Upload.") 115 sys.exit(0) 116 try: 117 if self.options.consumergroupid: 118 pkgs = self.cgconn.installpackages(self.options.consumergroupid, self.options.pnames) 119 print("Successfully Installed Packages %s on consumergroup [%s]" % (pkgs, self.options.consumergroupid)) 120 else: 121 pkgs = self.cconn.installpackages(self.options.consumerid, self.options.pnames) 122 print("Successfully Installed Packages %s on consumer [%s]" % (pkgs, self.options.consumerid)) 123 except RestlibException, re: 124 log.error("Error: %s" % re) 125 systemExit(re.code, re.msg) 126 except Exception, e: 127 log.error("Error: %s" % e) 128 raise
129