1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17 from spacewalk.common.rhnLog import log_debug
18 from spacewalk.common.usix import raise_with_tb
19 from spacewalk.server.rhnLib import InvalidAction, ShadowAction
20 from spacewalk.server.action.utils import SubscribedChannel,\
21 ChannelPackage, \
22 PackageInstallScheduler, \
23 NoActionInfo, \
24 PackageNotFound
25 from spacewalk.server.rhnChannel import subscribe_to_tools_channel
26
27 __rhnexport__ = ['schedule_virt_host_pkg_install', 'add_tools_channel']
28
29
36
37
39 """
40 ShadowAction that schedules a package installation action for the
41 rhn-virtualization-host and osad packages.
42 """
43 log_debug(3)
44
45 virt_host_package_name = "rhn-virtualization-host"
46 messaging_package_name = "osad"
47
48 tools_channel = SubscribedChannel(server_id, "rhn-tools")
49 found_tools_channel = tools_channel.is_subscribed_to_channel()
50
51 if not found_tools_channel:
52 raise InvalidAction("System not subscribed to the RHN Tools channel.")
53
54 rhn_v12n_package = ChannelPackage(server_id, virt_host_package_name)
55
56 if not rhn_v12n_package.exists():
57 raise InvalidAction("Could not find the rhn-virtualization-host package.")
58
59 messaging_package = ChannelPackage(server_id, messaging_package_name)
60
61 if not messaging_package.exists():
62 raise InvalidAction("Could not find the osad package.")
63
64 try:
65 rhn_v12n_install_scheduler = PackageInstallScheduler(server_id, action_id, rhn_v12n_package)
66 messaging_package = PackageInstallScheduler(server_id, action_id, messaging_package)
67 if (not dry_run):
68 rhn_v12n_install_scheduler.schedule_package_install()
69 messaging_package.schedule_package_install()
70 else:
71 log_debug(4, "dry run requested")
72 except NoActionInfo:
73 nai = sys.exc_info()[1]
74 raise_with_tb(InvalidAction(str(nai)), sys.exc_info()[2])
75 except PackageNotFound:
76 pnf = sys.exc_info()[1]
77 raise_with_tb(InvalidAction(str(pnf)), sys.exc_info()[2])
78 except Exception:
79 e = sys.exc_info()[1]
80 raise_with_tb(InvalidAction(str(e)), sys.exc_info()[2])
81
82 log_debug(3, "Completed scheduling install of rhn-virtualization-host and osad!")
83 raise ShadowAction("Scheduled installation of RHN Virtualization Host packages.")
84