1 ##############################################################################
2 # Copyright (c) 2016 Feng Pan (fpan@redhat.com)
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
17 def parse_net_settings(settings_args):
18 settings = apex.NetworkSettings(settings_args.path,
19 settings_args.network_isolation)
23 def find_ip(int_args):
24 interface = apex.ip_utils.get_interface(int_args.interface,
25 int_args.address_family)
30 parser = argparse.ArgumentParser()
31 parser.add_argument('--DEBUG', action='store_true', default=False,
32 help="Turn on debug messages")
33 subparsers = parser.add_subparsers()
35 net_settings = subparsers.add_parser('parse_net_settings',
36 help='Parse network settings file')
37 net_settings.add_argument('-n', '--path', default='network_settings.yaml',
38 help='path to network settings file')
39 net_settings.add_argument('-i', '--network_isolation', type=bool, default=True,
40 help='network isolation')
41 net_settings.set_defaults(func=parse_net_settings)
43 get_int_ip = subparsers.add_parser('find_ip',
44 help='Find interface ip')
45 get_int_ip.add_argument('-i', '--interface', required=True,
46 help='Interface name')
47 get_int_ip.add_argument('-af', '--address_family', default=4, type=int,
49 help='IP Address family')
50 get_int_ip.set_defaults(func=find_ip)
52 args = parser.parse_args(sys.argv[1:])
54 logging.basicConfig(level=logging.DEBUG)
56 apex_log_filename = '/var/log/apex/apex.log'
57 os.makedirs(os.path.dirname(apex_log_filename), exist_ok=True)
58 logging.basicConfig(filename=apex_log_filename,
59 format='%(asctime)s %(levelname)s: %(message)s',
60 datefmt='%m/%d/%Y %I:%M:%S %p',
63 if hasattr(args, 'func'):