6
import dbus.glib # This as side effects, don't remove it!
8
from dbus.service import Object, BusName, method
10
from twisted.internet import glib2reactor
11
glib2reactor.install()
12
from twisted.internet import reactor
14
from landscape.lib.bpickle import loads
15
from landscape.lib.lock import lock_path, LockError
16
from landscape.reactor import TwistedReactor
17
from landscape.deployment import Configuration
18
from landscape.broker.amp import RemoteBrokerConnector
21
BUS_NAME = "com.canonical.landscape.Broker"
22
OBJECT_PATH = "/com/canonical/landscape/Broker"
25
def array_to_string(array):
26
"""Convert an L{Array} of L{Byte}s (or integers) to a Python str."""
31
result.append(chr(item))
32
return "".join(result)
35
class BrokerDBusObject(Object):
36
"""A DBus-published object proxing L{RemoteBroker.send_message}.
38
It is used when upgrading from a DBus-based version of the Landscape client
39
to the newer AMP-based one, for letting the old package-changer process
40
performing the upgrade communicate with the new version of the client.
44
object_path = OBJECT_PATH
46
def __init__(self, config):
47
super(BrokerDBusObject, self).__init__(BusName(
48
self.bus_name, dbus.SystemBus()), object_path=self.object_path)
52
def send_message(self, message, urgent=True):
53
"""Queue the given message in the message exchange."""
54
message = loads(array_to_string(message))
56
def cb_connected(broker):
57
result = broker.send_message(message, urgent=True)
58
return result.addCallback(cb_done)
63
twisted_reactor = TwistedReactor()
64
connector = RemoteBrokerConnector(twisted_reactor, self.config)
65
connected = connector.connect()
66
connected.addCallback(cb_connected)
69
config = Configuration()
70
lock_filename = os.path.join(config.data_path, "package", "changer.lock")
72
lock_path(lock_filename)
74
# The package-changer is running, this means that we're upgrading from
75
# a non-AMP version and that the upgrade is Landscape driven, so let's
76
# expose the DBus broker proxy to give a chance to the package-changer
77
# to send its result message.
78
remote = BrokerDBusObject(config)