1
2
3
4
5
6
7
8
9
10
11
12
13
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
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
50 """
51 Package management object.
52 """
53
54 @remotemethod
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
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
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