← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] lp:~harlowja/cloud-init/cloud-init-render-tool into lp:cloud-init

 

I like this, its useful. 

The distro has some affect (at least right now) on the rendering. so it seems we should expose the distro there somehow.


Diff comments:

> 
> === added file 'tools/net-convert.py'
> --- tools/net-convert.py	1970-01-01 00:00:00 +0000
> +++ tools/net-convert.py	2016-06-18 00:17:45 +0000
> @@ -0,0 +1,89 @@
> +#!/usr/bin/python
> +# vi: ts=4 expandtab
> +#
> +#    Copyright (C) 2012 Canonical Ltd.
> +#    Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
> +#    Copyright (C) 2012 Yahoo! Inc.

update these

> +#
> +#    Author: Scott Moser <scott.moser@xxxxxxxxxxxxx>
> +#    Author: Juerg Haefliger <juerg.haefliger@xxxxxx>
> +#    Author: Joshua Harlow <harlowja@xxxxxxxxxxxxx>

and these. no reason to have nayone but you as author and not multiple coypright list on this either.

> +#
> +#    This program is free software: you can redistribute it and/or modify
> +#    it under the terms of the GNU General Public License version 3, as
> +#    published by the Free Software Foundation.
> +#
> +#    This program is distributed in the hope that it will be useful,
> +#    but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#    GNU General Public License for more details.
> +#
> +#    You should have received a copy of the GNU General Public License
> +#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +import argparse
> +import json
> +import os
> +
> +from cloudinit.sources.helpers import openstack
> +
> +from cloudinit.net import eni
> +from cloudinit.net import network_state
> +from cloudinit.net import sysconfig
> +
> +
> +def main():
> +    parser = argparse.ArgumentParser()
> +    parser.add_argument("--network-data", "-p", type=open,

make this a positional requirement since its required.
and is type=argparse.FileType('r') preferable to type=open?

> +                        metavar="PATH", required=True)
> +    parser.add_argument("--kind", "-k",

we can keep this as an option because i'd like to have some sort of "auto" that would do the right thing.

> +                        choices=['eni', 'network_data.json'],
> +                        required=True)
> +    parser.add_argument("-d", "--directory",
> +                        metavar="PATH",
> +                        help="directory to place output in",
> +                        required=True)

make this a positional argument since its required.

> +    parser.add_argument("-m", "--mac",
> +                        metavar="name,mac",
> +                        action='append',
> +                        help="interface name to mac mapping")

maybe 'mac=name' seems more obvious?
  --mac=fe:0a:12:bc:fd:9d=eth0

and maybe some way to use the systems macs?

> +    parser.add_argument("--output-kind", "-ok",
> +                        choices=['eni', 'sysconfig'],
> +                        required=True)
> +    args = parser.parse_args()
> +
> +    if not os.path.isdir(args.directory):
> +        os.makedirs(args.directory)
> +
> +    if args.mac:
> +        known_macs = {}
> +        for item in args.mac:
> +            iface_name, iface_mac = item.split(",", 1)
> +            known_macs[iface_mac] = iface_name
> +    else:
> +        known_macs = None
> +
> +    net_data = args.network_data.read()
> +    if args.kind == "eni":
> +        pre_ns = eni.convert_eni_data(net_data)
> +        ns = network_state.parse_net_config_data(pre_ns)
> +    else:
> +        pre_ns = openstack.convert_net_json(
> +            json.loads(net_data), known_macs=known_macs)
> +        ns = network_state.parse_net_config_data(pre_ns)
> +
> +    if not ns:
> +        raise RuntimeError("No valid network_state object created from"
> +                           "input data")
> +
> +    if args.output_kind == "eni":
> +        r_cls = eni.Renderer
> +    else:
> +        r_cls = sysconfig.Renderer
> +
> +    r = r_cls()
> +    r.render_network_state(args.directory, ns)
> +
> +
> +if __name__ == '__main__':
> +    main()


-- 
https://code.launchpad.net/~harlowja/cloud-init/cloud-init-render-tool/+merge/297816
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/cloud-init-render-tool into lp:cloud-init.


References