Package pulp :: Package client :: Package agent :: Package plugins :: Module remote
[hide private]
[frames] | no frames]

Source Code for Module pulp.client.agent.plugins.remote

  1  # 
  2  # Copyright (c) 2010 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15   
 16  """ 
 17  Remoted class for pulp agent. 
 18  """ 
 19   
 20  import os 
 21  from pulp.client import * 
 22  from pulp.client.repolib import RepoLib 
 23  from pulp.client.config import Config 
 24  from pulp.messaging.decorators import remote, remotemethod 
 25  from yum import YumBase 
 26  from logging import getLogger 
 27   
 28  log = getLogger(__name__) 
29 30 31 @remote 32 -class Repo:
33 """ 34 Pulp (pulp.repo) yum repository object. 35 """ 36 37 @remotemethod
38 - def update(self):
39 """ 40 Update the pulp.repo based on information 41 retrieved from pulp server. 42 """ 43 log.info('updating yum repo') 44 rlib = RepoLib() 45 rlib.update()
46
47 48 @remote 49 -class Packages:
50 """ 51 Package management object. 52 """ 53 54 @remotemethod
55 - def install(self, packageinfo):
56 """ 57 Install packages by name. 58 @param packageinfo: A list of strings for pkg names 59 or tuples for name/arch info. 60 @type packageinfo: str or tuple 61 """ 62 installed = [] 63 yb = YumBase() 64 log.info('installing packages: %s', packageinfo) 65 for info in packageinfo: 66 if isinstance(info, list): 67 pkgs = yb.pkgSack.returnNewestByNameArch(tuple(info)) 68 else: 69 pkgs = yb.pkgSack.returnNewestByName(info) 70 for p in pkgs: 71 installed.append(str(p)) 72 yb.tsInfo.addInstall(p) 73 yb.resolveDeps() 74 yb.processTransaction() 75 return installed
76
77 @remote 78 -class PackageGroups:
79 """ 80 PackageGroup management object 81 """ 82 83 @remotemethod
84 - def install(self, packagegroupids):
85 """ 86 Install packagegroups by id. 87 @param packagegroupids: A list of package ids. 88 @param packagegroupids: str 89 """ 90 log.info('installing packagegroups: %s', packagegroupids) 91 yb = YumBase() 92 for grp_id in packagegroupids: 93 txmbrs = yb.selectGroup(grp_id) 94 log.info("Added '%s' group to transaction, packages: %s", grp_id, txmbrs) 95 yb.resolveDeps() 96 yb.processTransaction()
97
98 @remote 99 -class AgentAdmin:
100 101 @remotemethod
102 - def hello(self):
103 s = [] 104 cfg = Config() 105 cid = ConsumerId() 106 s.append('Hello, I am agent "%s"' % cid.uuid) 107 s.append('Here is my configuration:\n%s' % cfg) 108 s.append('Status: ready') 109 return '\n'.join(s)
110
111 112 @remote 113 -class Shell:
114 115 @remotemethod
116 - def run(self, cmd):
117 """ 118 Run a shell command. 119 @param cmd: The command & arguments. 120 @type cmd: str 121 @return: The command output. 122 @rtype: str 123 """ 124 f = os.popen(cmd) 125 try: 126 return f.read() 127 finally: 128 f.close()
129