Implement apply, cleanup commands
This commit is contained in:
parent
0ad26adb8e
commit
06036fd6db
|
@ -1,5 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
|
@ -12,8 +10,42 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
'''Stable library interface to managing containers with paunch.'''
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
import pbr.version
|
import pbr.version
|
||||||
|
|
||||||
|
from paunch.builder import compose1
|
||||||
|
from paunch import runner
|
||||||
|
|
||||||
__version__ = pbr.version.VersionInfo(
|
__version__ = pbr.version.VersionInfo('paunch').version_string()
|
||||||
'paunch').version_string()
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def apply(config_id, config, managed_by, labels=None):
|
||||||
|
builder = compose1.ComposeV1Builder(
|
||||||
|
config_id=config_id,
|
||||||
|
config=config,
|
||||||
|
managed_by=managed_by,
|
||||||
|
labels=labels
|
||||||
|
)
|
||||||
|
return builder.apply()
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup(config_ids, managed_by):
|
||||||
|
runner.delete_missing_configs(config_ids)
|
||||||
|
runner.rename_containers()
|
||||||
|
|
||||||
|
|
||||||
|
def list():
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
def show(config_id):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
def delete(config_id):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
|
@ -11,25 +11,95 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import collections
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cliff.command import Command
|
from cliff.command import Command
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
import paunch
|
||||||
|
|
||||||
|
|
||||||
class Apply(Command):
|
class Apply(Command):
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(Apply, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'--file',
|
||||||
|
metavar='<file>',
|
||||||
|
required=True,
|
||||||
|
help=('YAML or JSON file containing configuration data'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--label',
|
||||||
|
metavar='<label=value>',
|
||||||
|
dest='labels',
|
||||||
|
default=[],
|
||||||
|
help=('Extra labels to apply to containers in this config, in the '
|
||||||
|
'form label=value.'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--managed-by',
|
||||||
|
metavar='<name>',
|
||||||
|
dest='managed_by',
|
||||||
|
default='paunch',
|
||||||
|
help=('Override the name of the tool managing the containers'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'config_id',
|
||||||
|
metavar='<config_id>',
|
||||||
|
help=('Identifier for the config, unique to the service managing '
|
||||||
|
'the containers'),
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
pass
|
|
||||||
|
labels = collections.OrderedDict()
|
||||||
|
for l in parsed_args.labels:
|
||||||
|
k, v = l.split(('='), 1)
|
||||||
|
labels[k] = v
|
||||||
|
|
||||||
|
with open(parsed_args.file, 'r') as f:
|
||||||
|
config = yaml.safe_load(f)
|
||||||
|
|
||||||
|
paunch.apply(
|
||||||
|
parsed_args.config_id,
|
||||||
|
config,
|
||||||
|
managed_by='paunch',
|
||||||
|
labels=labels
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Cleanup(Command):
|
class Cleanup(Command):
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(Cleanup, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'config_id',
|
||||||
|
metavar='<config_id>',
|
||||||
|
dest='config_ids',
|
||||||
|
help=('Identifiers for the configs which still apply, all others '
|
||||||
|
'will be deleted.'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--managed-by',
|
||||||
|
metavar='<name>',
|
||||||
|
dest='managed_by',
|
||||||
|
default='paunch',
|
||||||
|
help=('Override the name of the tool managing the containers'),
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
pass
|
paunch.cleanup(
|
||||||
|
parsed_args.config_ids,
|
||||||
|
managed_by=parsed_args.managed_by
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Delete(Command):
|
class Delete(Command):
|
||||||
|
@ -45,4 +115,12 @@ class List(Command):
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
pass
|
paunch.list()
|
||||||
|
|
||||||
|
|
||||||
|
class Show(Command):
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
paunch.list()
|
||||||
|
|
Loading…
Reference in New Issue