~smoser/cloud-init/azure_dhcp

« back to all changes in this revision

Viewing changes to cloudinit/cmd/main.py

  • Committer: Brent Baude
  • Date: 2016-08-04 12:48:46 UTC
  • Revision ID: bbaude@redhat.com-20160804124846-tt1gybhdqpy8zkim
Rather than having the python executable for obtaining and storing the
dhclient information as its own executable, it is integrated into
cloud-init as a sub-command 'dhclient_hook'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE,
48
48
                                CLOUD_CONFIG)
49
49
 
 
50
from cloudinit.dhclient_hook import LogDhclient
 
51
 
50
52
 
51
53
# Pretty little cheetah formatted welcome message template
52
54
WELCOME_MSG_TPL = ("Cloud-init v. ${version} running '${action}' at "
451
453
        # Guess it worked
452
454
        return 0
453
455
 
 
456
def dhclient_hook(name, args):
 
457
    record = LogDhclient()
 
458
    record.check_hooks_dir()
 
459
    record.record()
454
460
 
455
461
def atomic_write_file(path, content, mode='w'):
456
462
    tf = None
627
633
    # This subcommand allows you to run a single module
628
634
    parser_single = subparsers.add_parser('single',
629
635
                                          help=('run a single module '))
630
 
    parser_single.set_defaults(action=('single', main_single))
631
636
    parser_single.add_argument("--name", '-n', action="store",
632
637
                               help="module name to run",
633
638
                               required=True)
644
649
                                     ' pass to this module'))
645
650
    parser_single.set_defaults(action=('single', main_single))
646
651
 
 
652
    parser_dhclient = subparsers.add_parser('dhclient_hook',
 
653
                                            help=('run the dhclient hook'
 
654
                                                  'to record network info'))
 
655
    parser_dhclient.set_defaults(action=('dhclient_hook', dhclient_hook))
 
656
 
647
657
    args = parser.parse_args(args=sysv_args)
648
658
 
649
659
    try:
677
687
                        "running single module %s" % args.name)
678
688
        report_on = args.report
679
689
 
 
690
    elif name == 'dhclient_hook':
 
691
        rname, rdesc = ("dhclient-hook",
 
692
                        "running dhclient-hook module")
 
693
 
680
694
    args.reporter = events.ReportEventStack(
681
695
        rname, rdesc, reporting_enabled=report_on)
 
696
 
682
697
    with args.reporter:
683
698
        return util.log_time(
684
699
            logfunc=LOG.debug, msg="cloud-init mode '%s'" % name,