~free.ekanayaka/landscape-client/lucid-1.5.2.1-0ubuntu0.10.04.0

« back to all changes in this revision

Viewing changes to landscape/deployment.py

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Free Ekanayaka
  • Date: 2009-07-22 14:54:50 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090722145450-pvbp13gh8734c8ft
Tags: 1.3.2.2-0ubuntu0.9.10.1
[ Free Ekanayaka ]
* New upstream release:
  - Include the README file in landscape-client (LP: #396260)
  - Fix client capturing stderr from run_command when constructing
    hash-id-databases url (LP: #397480)
  - Use substvars to conditionally depend on update-motd or
    libpam-modules (LP: #393454)
  - Fix reporting wrong version to the server (LP: #391225)
  - The init script does not wait for the network to be available
    before checking for EC2 user data (LP: #383336)
  - When the broker is restarted by the watchdog, the state of the client
    is inconsistent (LP: #380633)
  - Package stays unknown forever in the client with hash-id-databases
    support (LP: #381356)
  - Standard error not captured when calling smart-update (LP: #387441)
  - Changer calls reporter without switching groups, just user (LP: #388092)
  - Run smart update in the package-reporter instead of having a cronjob (LP: #362355)
  - Package changer does not inherit proxy settings (LP: #381241)
  - The ./test script doesn't work in landscape-client (LP: #381613)
  - The source package should build on all supported releases (LP: #385098)
  - Strip smart update's output (LP: #387331)
  - The fetch() timeout isn't based on activity (#389224)
  - Client can use a UUID of "None" when fetching the hash-id-database (LP: #381291)
  - Registration should use the fqdn rather than just the hostname (LP: #385730)

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
class BaseConfiguration(object):
45
45
    """Base class for configuration implementations.
46
46
 
47
 
    @var required_options: Optionally, a sequence of key names to require when
 
47
    @cvar required_options: Optionally, a sequence of key names to require when
48
48
        reading or writing a configuration.
49
 
    @var unsaved_options: Optionally, a sequence of key names to never write
 
49
    @cvar unsaved_options: Optionally, a sequence of key names to never write
50
50
        to the configuration file.  This is useful when you want to provide
51
51
        command-line options that should never end up in a configuration file.
52
 
    @var default_config_filenames: A sequence of filenames to check when
 
52
    @cvar default_config_filenames: A sequence of filenames to check when
53
53
        reading or writing a configuration.
54
54
    """
55
55
 
63
63
    config_section = "client"
64
64
 
65
65
    def __init__(self):
 
66
        """Default configuration.
 
67
 
 
68
        Default values for supported options are set as in L{make_parser}.
 
69
        """
66
70
        self._set_options = {}
67
71
        self._command_line_args = []
68
72
        self._command_line_options = {}
78
82
        """Find and return the value of the given configuration parameter.
79
83
 
80
84
        The following sources will be searched:
81
 
          * The attributes that were explicitly set on this object,
82
 
          * The parameters specified on the command line,
83
 
          * The parameters specified in the configuration file, and
84
 
          * The defaults.
 
85
          - The attributes that were explicitly set on this object,
 
86
          - The parameters specified on the command line,
 
87
          - The parameters specified in the configuration file, and
 
88
          - The defaults.
85
89
 
86
90
        If no values are found and the parameter does exist as a possible
87
91
        parameter, C{None} is returned.
107
111
        return value
108
112
 
109
113
    def get(self, name, default=None):
 
114
        """Return the value of the C{name} option or C{default}."""
110
115
        try:
111
116
            return self.__getattr__(name)
112
117
        except AttributeError:
124
129
            self._set_options[name] = value
125
130
 
126
131
    def reload(self):
 
132
        """Reload options using the configured command line arguments.
 
133
 
 
134
        @see: L{load_command_line}
 
135
        """
127
136
        self.load(self._command_line_args)
128
137
 
129
138
    def load(self, args, accept_nonexistent_config=False):
189
198
 
190
199
        Options are considered in the following precedence:
191
200
 
192
 
        1. Manually set options (config.option = value)
193
 
        2. Options passed in the command line
194
 
        3. Previously existent options in the configuration file
195
 
 
196
 
        The filename picked for saving configuration options is:
197
 
 
198
 
        1. self.config, if defined
199
 
        2. The last loaded configuration file, if any
200
 
        3. The first filename in self.default_config_filenames
 
201
          1. Manually set options (C{config.option = value})
 
202
          2. Options passed in the command line
 
203
          3. Previously existent options in the configuration file
 
204
 
 
205
        The filename picked for saving configuration options is the one
 
206
        returned by L{get_config_filename}.
201
207
        """
202
208
        # The filename we'll write to
203
209
        filename = self.get_config_filename()
223
229
        config_file.close()
224
230
 
225
231
    def make_parser(self):
226
 
        """
227
 
        Return an L{OptionParser} preset with options that all
228
 
        landscape-related programs accept.
 
232
        """Parser factory for supported options
 
233
 
 
234
        @return: An L{OptionParser} preset with options that all
 
235
            landscape-related programs accept. These include
 
236
              - C{config} (C{None})
 
237
              - C{bus} (C{system})
229
238
        """
230
239
        parser = OptionParser(version=VERSION)
231
240
        parser.add_option("-c", "--config", metavar="FILE",
237
246
        return parser
238
247
 
239
248
    def get_config_filename(self):
 
249
        """Pick the proper configuration file.
 
250
 
 
251
        The picked filename is:
 
252
          1. C{self.config}, if defined
 
253
          2. The last loaded configuration file, if any
 
254
          3. The first filename in C{self.default_config_filenames}
 
255
        """
240
256
        if self.config:
241
257
            return self.config
242
258
        if self._config_filename:
249
265
        return None
250
266
 
251
267
    def get_command_line_options(self):
 
268
        """Get currently loaded command line options.
 
269
 
 
270
        @see: L{load_command_line}
 
271
        """
252
272
        return self._command_line_options
253
273
 
254
274
 
263
283
        return os.path.join(self.data_path, "hash.db")
264
284
 
265
285
    def make_parser(self):
266
 
        """
267
 
        Return an L{OptionParser} preset with options that all
268
 
        landscape-related programs accept.
 
286
        """Parser factory for supported options.
 
287
 
 
288
        @return: An L{OptionParser} preset for all options
 
289
            from L{BaseConfiguration.make_parser} plus:
 
290
              - C{data_path} (C{"/var/lib/landscape/client/"})
 
291
              - C{quiet} (C{False})
 
292
              - C{log_dir} (C{"/var/log/landscape"})
 
293
              - C{log_level} (C{"info"})
 
294
              - C{ignore_sigint} (C{False})
269
295
        """
270
296
        parser = super(Configuration, self).make_parser()
271
297
        parser.add_option("-d", "--data-path", metavar="PATH",
286
312
 
287
313
 
288
314
def get_versioned_persist(service):
289
 
    """
290
 
    Load a Persist database for the given service and upgrade or mark
291
 
    as current, as necessary.
 
315
    """Get a L{Persist} database with upgrade rules applied.
 
316
 
 
317
    Load a L{Persist} database for the given C{service} and upgrade or
 
318
    mark as current, as necessary.
292
319
    """
293
320
    persist = Persist(filename=service.persist_filename)
294
321
    upgrade_manager = UPGRADE_MANAGERS[service.service_name]
301
328
 
302
329
 
303
330
class LandscapeService(Service, object):
304
 
    """
305
 
    A utility superclass for defining Landscape services.
 
331
    """Utility superclass for defining Landscape services.
306
332
 
307
333
    This sets up the reactor, bpickle/dbus integration, a Persist object, and
308
334
    connects to the bus when started.
309
335
 
 
336
    @ivar reactor: a L{TwistedReactor} object.
310
337
    @cvar service_name: The lower-case name of the service. This is used to
311
338
        generate the bpickle filename.
312
339
    """
322
349
        signal.signal(signal.SIGUSR1, lambda signal, frame: rotate_logs())
323
350
 
324
351
    def startService(self):
 
352
        """Extend L{twisted.application.service.IService.startService}.
 
353
 
 
354
        Create a a new DBus connection (normally using a C{SystemBus}) and
 
355
        save it in the public L{self.bus} instance variable.
 
356
        """
325
357
        Service.startService(self)
326
358
        self.bus = get_bus(self.config.bus)
327
359
        info("%s started on '%s' bus with config %s" % (
353
385
def run_landscape_service(configuration_class, service_class, args, bus_name):
354
386
    """Run a Landscape service.
355
387
 
356
 
    @param configuration_class: A subclass of L{Configuration} for processing
357
 
        the C{args} and config file.
358
 
    @param service_class: A subclass of L{LandscapeService} to create and start.
 
388
    The function will instantiate the given L{LandscapeService} subclass
 
389
    and attach the resulting service object to a Twisted C{Application}.
 
390
 
 
391
    After that it will start the Twisted L{Application} and call the
 
392
    L{TwistedReactor.run} method of the L{LandscapeService}'s reactor.
 
393
 
 
394
    @param configuration_class: The service-specific subclass of L{Configuration} used
 
395
        to parse C{args} and build the C{service_class} object.
 
396
    @param service_class: The L{LandscapeService} subclass to create and start.
359
397
    @param args: Command line arguments.
360
398
    @param bus_name: A bus name used to verify if the service is already
361
399
        running.