/usr/share/conjure/bundleplacer/cli.py is in conjure 0.0.8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | # Copyright 2015 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import logging
import os
import sys
import urwid
from bundleplacer import async
from bundleplacer.maas import connect_to_maas
from bundleplacer.config import Config
from bundleplacer.controller import BundleWriter, PlacementController
from bundleplacer.log import setup_logger
from bundleplacer.placerview import PlacerView
from bundleplacer.fixtures.maas import FakeMaasState
from ubuntui.ev import EventLoop
from ubuntui.palette import STYLES
from ubuntui.anchors import Header, Footer
log = None
class PlacerUI(urwid.Frame):
def __init__(self, placerview):
super().__init__(body=placerview, header=Header(), footer=Footer())
def parse_options(argv):
parser = argparse.ArgumentParser(description='Juju Bundle Placer',
prog='placer',
argument_default=argparse.SUPPRESS)
parser.add_argument("bundle_filename", metavar='bundle',
help="Bundle file to edit")
parser.add_argument("--metadata", dest="metadata_filename",
metavar='metadatafile',
help="Optional metadata file describing constraints "
"on services in bundle")
parser.add_argument("--fake-maas", dest="fake_maas",
action="store_true", default=False)
parser.add_argument("--maas-ip", dest="maas_ip", default=None)
parser.add_argument("--maas-cred", dest="maas_cred", default=None)
parser.add_argument("-o", dest="out_filename", default=None)
return parser.parse_args(argv)
def main():
opts = parse_options(sys.argv[1:])
config = Config('bundle-placer', opts.__dict__)
config.save()
setup_logger(cfg_path=config.cfg_path)
log = logging.getLogger('bundleplacer')
log.debug(opts.__dict__)
log.info("Editing file: {}".format(opts.bundle_filename))
if opts.maas_ip and opts.maas_cred:
creds = dict(api_host=opts.maas_ip,
api_key=opts.maas_cred)
maas, maas_state = connect_to_maas(creds)
elif opts.fake_maas:
maas = None
maas_state = FakeMaasState()
else:
maas = None
maas_state = None
placement_controller = PlacementController(config=config,
maas_state=maas_state)
def cb():
if maas:
maas.tag_name(maas.nodes)
bw = BundleWriter(placement_controller)
if opts.out_filename:
outfn = opts.out_filename
else:
path, ext = os.path.splitext(opts.bundle_filename)
outfn = "{}-out{}".format(path, ext)
bw.write_bundle(outfn)
async.shutdown()
raise urwid.ExitMainLoop()
has_maas = (maas_state is not None)
mainview = PlacerView(placement_controller, config, cb, has_maas=has_maas)
ui = PlacerUI(mainview)
def unhandled_input(key):
if key in ['q', 'Q']:
async.shutdown()
raise urwid.ExitMainLoop()
EventLoop.build_loop(ui, STYLES, unhandled_input=unhandled_input)
mainview.loop = EventLoop.loop
mainview.update()
EventLoop.run()
|