Puppet info & rsync commands added
Change-Id: If7a1a42ad54a482ba3dab3d86c1096554e7eae55
This commit is contained in:
parent
a0a1a92cc2
commit
01b0c92fda
|
@ -18,4 +18,4 @@ from fuel_dev_tools import debug
|
|||
|
||||
|
||||
class BaseCommand(debug.DebugMixin, command.Command):
|
||||
pass
|
||||
pass
|
||||
|
|
|
@ -28,8 +28,12 @@ DOCKER_CONTAINER_PATH = '/var/lib/docker/containers/'
|
|||
DOCKER_DEVICEMAPPER_PATH = '/var/lib/docker/devicemapper/mnt/'
|
||||
|
||||
|
||||
class DockerMixin(object):
|
||||
class DockerMixin(ssh.SSHMixin):
|
||||
container = None
|
||||
default_command = None
|
||||
|
||||
def get_log_directory(self):
|
||||
return ''
|
||||
|
||||
def container_command(self, *commands):
|
||||
return [
|
||||
|
@ -153,22 +157,22 @@ class DockerMixin(object):
|
|||
self.print_debug(result)
|
||||
|
||||
|
||||
class IdCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class IdCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(self.get_docker_id(get_exited=True))
|
||||
|
||||
|
||||
class ConfigCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class ConfigCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(json.dumps(self.get_container_config(), indent=2))
|
||||
|
||||
|
||||
class DirCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class DirCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(self.get_container_directory())
|
||||
|
||||
|
||||
class LogCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class LogCommand(command.BaseCommand):
|
||||
def get_log_directory(self):
|
||||
raise NotImplementedError('No log directory for this command')
|
||||
|
||||
|
@ -192,14 +196,12 @@ class LogCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
|||
)
|
||||
|
||||
|
||||
class RestartCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class RestartCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.restart_container()
|
||||
|
||||
|
||||
class RsyncCommand(DockerMixin,
|
||||
rsync.RsyncMixin,
|
||||
ssh.SSHMixin,
|
||||
class RsyncCommand(rsync.RsyncMixin,
|
||||
command.BaseCommand):
|
||||
def pre_sync(self, parsed_args):
|
||||
pass
|
||||
|
@ -215,18 +217,6 @@ class RsyncCommand(DockerMixin,
|
|||
def target_path(self):
|
||||
return ''
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RsyncCommand, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'-s', '--source',
|
||||
nargs='?',
|
||||
default='.',
|
||||
help='Source of the rsync-ed directory.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.pre_sync(parsed_args)
|
||||
|
||||
|
@ -248,7 +238,7 @@ class RsyncCommand(DockerMixin,
|
|||
self.post_sync(parsed_args)
|
||||
|
||||
|
||||
class ShellCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class ShellCommand(command.BaseCommand):
|
||||
default_command = None
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -282,17 +272,17 @@ class ShellCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
|||
)
|
||||
|
||||
|
||||
class StartCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class StartCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.start_container()
|
||||
|
||||
|
||||
class StopCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class StopCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
self.stop_container()
|
||||
|
||||
|
||||
class TailCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class TailCommand(command.BaseCommand):
|
||||
def get_log_directory(self):
|
||||
raise NotImplementedError('No log directory for this command')
|
||||
|
||||
|
@ -314,7 +304,7 @@ class TailCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
|||
)
|
||||
|
||||
|
||||
class VolumesCommand(DockerMixin, ssh.SSHMixin, command.BaseCommand):
|
||||
class VolumesCommand(command.BaseCommand):
|
||||
def take_action(self, parsed_args):
|
||||
six.print_(
|
||||
json.dumps(
|
||||
|
|
|
@ -19,7 +19,7 @@ from fuel_dev_tools import docker
|
|||
from fuel_dev_tools import info
|
||||
|
||||
|
||||
class DockerAstuteMixin(object):
|
||||
class DockerAstuteMixin(docker.DockerMixin):
|
||||
container = 'astute'
|
||||
default_command = '/bin/bash'
|
||||
|
||||
|
@ -30,7 +30,10 @@ class DockerAstuteMixin(object):
|
|||
class AstuteInfo(DockerAstuteMixin, info.BasicInfo):
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
return 'Admin token is stored in /etc/fuel/astute.yaml on Fuel Main.'
|
||||
return """Admin token is stored in /etc/fuel/astute.yaml on Fuel Main.
|
||||
|
||||
If you want to send custom receiverd response from Astute: http://sprunge.us/UJfb
|
||||
"""
|
||||
|
||||
|
||||
class Id(DockerAstuteMixin, docker.IdCommand):
|
||||
|
|
|
@ -12,14 +12,10 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
from fabric import api as fabric_api
|
||||
|
||||
from fuel_dev_tools import docker
|
||||
|
||||
|
||||
class DockerMcollectiveMixin(object):
|
||||
class DockerMcollectiveMixin(docker.DockerMixin):
|
||||
container = 'mcollective'
|
||||
default_command = '/bin/bash'
|
||||
|
||||
|
|
|
@ -15,10 +15,9 @@
|
|||
from fuel_dev_tools import command
|
||||
from fuel_dev_tools import docker
|
||||
from fuel_dev_tools import info
|
||||
from fuel_dev_tools import ssh
|
||||
|
||||
|
||||
class DockerNailgunMixin(object):
|
||||
class DockerNailgunMixin(docker.DockerMixin):
|
||||
container = 'nailgun'
|
||||
default_command = 'python'
|
||||
|
||||
|
@ -44,8 +43,6 @@ class Config(DockerNailgunMixin, docker.ConfigCommand):
|
|||
|
||||
|
||||
class DBReset(DockerNailgunMixin,
|
||||
docker.DockerMixin,
|
||||
ssh.SSHMixin,
|
||||
command.BaseCommand):
|
||||
"""Reset the whole database to defaults."""
|
||||
def take_action(self, parsed_args):
|
||||
|
@ -79,7 +76,7 @@ CREATE DATABASE nailgun WITH OWNER nailgun;
|
|||
cmd = self.container_command('manage.py', 'syncdb')
|
||||
p.ssh_command(*cmd)
|
||||
|
||||
cmd = self.container_command('manage.py', 'loaddefault')
|
||||
self.container_command('manage.py', 'loaddefault')
|
||||
|
||||
|
||||
class Dir(DockerNailgunMixin, docker.DirCommand):
|
||||
|
|
|
@ -19,7 +19,7 @@ from fabric import api as fabric_api
|
|||
from fuel_dev_tools import docker
|
||||
|
||||
|
||||
class DockerNginxMixin(object):
|
||||
class DockerNginxMixin(docker.DockerMixin):
|
||||
container = 'nginx'
|
||||
default_command = '/bin/bash'
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ from fuel_dev_tools import docker
|
|||
from fuel_dev_tools import info
|
||||
|
||||
|
||||
class DockerPostgresMixin(object):
|
||||
class DockerPostgresMixin(docker.DockerMixin):
|
||||
container = 'postgres'
|
||||
default_command = 'su - postgres -c "psql -d nailgun"'
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ from fuel_dev_tools import docker
|
|||
from fuel_dev_tools import info
|
||||
|
||||
|
||||
class DockerRabbitMQMixin(object):
|
||||
class DockerRabbitMQMixin(docker.DockerMixin):
|
||||
container = 'RabbitMQ'
|
||||
default_command = '/bin/bash'
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
# Copyright 2015 Mirantis, Inc.
|
||||
#
|
||||
# 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
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
from fuel_dev_tools import info
|
||||
from fuel_dev_tools import command
|
||||
from fuel_dev_tools import docker
|
||||
from fuel_dev_tools import rsync
|
||||
from fuel_dev_tools import ssh
|
||||
|
||||
|
||||
class PuppetInfo(info.BasicInfo):
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
return ''
|
||||
|
||||
|
||||
class Rsync(rsync.RsyncMixin,
|
||||
ssh.SSHMixin,
|
||||
command.BaseCommand):
|
||||
"""Rsync local directory to the Docker container."""
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
source_dir = os.path.join(parsed_args.source, 'deployment', 'puppet/')
|
||||
|
||||
# Target is in /etc/puppet/<release-version>
|
||||
release_version = self.ssh_command(
|
||||
'ls', '/etc/puppet'
|
||||
).decode('utf-8').split()[0]
|
||||
target_dir = os.path.join(
|
||||
'/etc', 'puppet', release_version, 'modules'
|
||||
)
|
||||
|
||||
target, args = self.build_app_args_target(target_dir)
|
||||
|
||||
self.print_debug('Rsyncing to master')
|
||||
self.rsync(source_dir, target, *args)
|
||||
|
||||
updated_containers = set([None])
|
||||
|
||||
# Get DockerMixin subclasses which are also subclasses of
|
||||
# command.Basecommand -- only such classes can be used by
|
||||
# SSHMixin which requires self.app IP, port and user data
|
||||
command_mixins = []
|
||||
for docker_mixin_klass in docker.DockerMixin.__subclasses__():
|
||||
command_mixins.extend(docker_mixin_klass.__subclasses__())
|
||||
|
||||
for klass in command_mixins:
|
||||
if not issubclass(klass, command.BaseCommand) or \
|
||||
klass.container in updated_containers:
|
||||
continue
|
||||
|
||||
self.print_debug('Rsyncing to container %s' % klass.container)
|
||||
|
||||
executor = klass(self.app, self.app_args)
|
||||
|
||||
target_dir = os.path.join(
|
||||
executor.get_container_directory(),
|
||||
'rootfs', 'etc', 'puppet', release_version, 'modules'
|
||||
)
|
||||
|
||||
target, args = self.build_app_args_target(target_dir)
|
||||
|
||||
self.rsync(source_dir, target, *args)
|
||||
|
||||
updated_containers.add(klass.container)
|
|
@ -16,6 +16,18 @@ import subprocess
|
|||
|
||||
|
||||
class RsyncMixin(object):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(RsyncMixin, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'-s', '--source',
|
||||
nargs='?',
|
||||
default='.',
|
||||
help='Source of the rsync-ed directory.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def build_app_args_target(self, target):
|
||||
target = '{}@{}:{}'.format(self.app_args.user, self.app_args.ip, target)
|
||||
args = ['-e', 'ssh -p {}'.format(self.app_args.port)]
|
||||
|
|
|
@ -36,6 +36,7 @@ from fuel_dev_tools.docker import rabbitmq
|
|||
from fuel_dev_tools.slaves import mcagent
|
||||
from fuel_dev_tools import exc
|
||||
from fuel_dev_tools import info
|
||||
from fuel_dev_tools import puppet
|
||||
from fuel_dev_tools import ssh
|
||||
|
||||
|
||||
|
@ -86,6 +87,8 @@ COMMANDS = {
|
|||
'postgres-tail': postgres.Tail,
|
||||
'postgres-volumes': postgres.Volumes,
|
||||
|
||||
'puppet-rsync': puppet.Rsync,
|
||||
|
||||
'rabbitmq-id': rabbitmq.Id,
|
||||
'rabbitmq-config': rabbitmq.Config,
|
||||
'rabbitmq-dir': rabbitmq.Dir,
|
||||
|
|
|
@ -25,18 +25,6 @@ class Rsync(slaves.SlavesMixin,
|
|||
rsync.RsyncMixin,
|
||||
command.BaseCommand):
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(Rsync, self).get_parser(prog_name)
|
||||
|
||||
parser.add_argument(
|
||||
'-s', '--source',
|
||||
nargs='?',
|
||||
default='.',
|
||||
help='Source of the rsync-ed directory.'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def target_for_slave(self, slave):
|
||||
if slave['status'] in ['discover', 'error']:
|
||||
return '/usr/libexec/mcollective/mcollective/agent'
|
||||
|
|
Loading…
Reference in New Issue