Add fuel_dev_tools Astute commands
Change-Id: I0a028579a745e3faf0332b1603b21fc68363bed9
This commit is contained in:
parent
2fc2b7adaf
commit
85ae518725
|
@ -102,7 +102,7 @@ class DockerMixin(object):
|
|||
iid = self.get_docker_id(get_exited=get_exited)
|
||||
|
||||
iid = self.ssh_command(
|
||||
"docker inspect -f '{{.ID}}' %s" % iid
|
||||
"docker inspect -f '{{.Id}}' %s" % iid
|
||||
).decode('utf-8').strip()
|
||||
|
||||
return iid
|
||||
|
@ -239,6 +239,12 @@ class ShellCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
|||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def container_command(self, *commands):
|
||||
return [
|
||||
#'lxc-attach', '--name', self.get_full_docker_id()
|
||||
'docker', 'exec', self.get_docker_id()
|
||||
] + list(commands)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShellCommand, self).get_parser(prog_name)
|
||||
|
||||
|
@ -263,9 +269,7 @@ class ShellCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
|||
if not command:
|
||||
command = '/bin/bash'
|
||||
|
||||
return self.ssh_command_interactive(
|
||||
'lxc-attach', '--name', self.get_full_docker_id(), command
|
||||
)
|
||||
return self.ssh_command_interactive(self.container_command(command))
|
||||
|
||||
|
||||
class StartCommand(DockerMixin, ssh.SSHMixin, command.Command):
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
# 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 six
|
||||
import subprocess
|
||||
|
||||
from fuel_dev_tools import docker
|
||||
from fuel_dev_tools import info
|
||||
|
||||
|
||||
class DockerAstuteMixin(object):
|
||||
container = 'astute'
|
||||
default_command = '/bin/bash'
|
||||
|
||||
def get_log_directory(self):
|
||||
return '/var/log/docker-logs/astute'
|
||||
|
||||
|
||||
class AstuteInfo(DockerAstuteMixin, info.BasicInfo):
|
||||
@classmethod
|
||||
def get_info(cls):
|
||||
return 'Admin token is stored in /etc/fuel/astute.yaml on Fuel Main.'
|
||||
|
||||
|
||||
class Id(DockerAstuteMixin, docker.IdCommand):
|
||||
"""Print Docker container id."""
|
||||
|
||||
|
||||
class Config(DockerAstuteMixin, docker.ConfigCommand):
|
||||
"""Print Docker container config."""
|
||||
|
||||
|
||||
class Dir(DockerAstuteMixin, docker.DirCommand):
|
||||
"""Print Docker container directory on master."""
|
||||
|
||||
|
||||
class Log(DockerAstuteMixin, docker.LogCommand):
|
||||
"""Display logs for container."""
|
||||
|
||||
|
||||
class Restart(DockerAstuteMixin, docker.RestartCommand):
|
||||
"""Restart Docker container."""
|
||||
|
||||
|
||||
class Rsync(DockerAstuteMixin, docker.RsyncCommand, docker.ShellCommand):
|
||||
"""Rsync local directory to the Docker container."""
|
||||
|
||||
gemspec = 'astute.gemspec'
|
||||
gemfile = 'astute-6.1.0.gem'
|
||||
|
||||
@property
|
||||
def source_path(self):
|
||||
return self.gemfile
|
||||
|
||||
@property
|
||||
def target_path(self):
|
||||
return 'tmp/%s' % self.gemfile
|
||||
|
||||
def pre_sync(self, parsed_args):
|
||||
self.build_gem(parsed_args.source)
|
||||
|
||||
def post_sync(self, parsed_args):
|
||||
self.ssh_command(*self.container_command(
|
||||
'gem install', '--local', '-q', '-f', self.target_path
|
||||
))
|
||||
|
||||
self.restart_container()
|
||||
|
||||
def build_gem(self, source_dir):
|
||||
cmd = (
|
||||
'cd %(cwd)s && '
|
||||
'gem build %(gemspec)s'
|
||||
) % {
|
||||
'cwd': source_dir,
|
||||
'gemspec': self.gemspec,
|
||||
}
|
||||
|
||||
try:
|
||||
result = subprocess.check_output([
|
||||
cmd
|
||||
], shell=True)
|
||||
|
||||
six.print_(result)
|
||||
except subprocess.CalledProcessError as e:
|
||||
six.print_('GEM BUILD ERROR')
|
||||
six.print_(e.output)
|
||||
raise
|
||||
|
||||
|
||||
class Start(DockerAstuteMixin, docker.StartCommand):
|
||||
"""Start Docker container."""
|
||||
|
||||
|
||||
class Stop(DockerAstuteMixin, docker.StopCommand):
|
||||
"""Stop Docker container."""
|
||||
|
||||
|
||||
class Shell(DockerAstuteMixin, docker.ShellCommand):
|
||||
"""Shell into a nailgun Docker container."""
|
||||
|
||||
|
||||
class Tail(DockerAstuteMixin, docker.TailCommand):
|
||||
"""Display logs for container."""
|
||||
|
||||
|
||||
class Volumes(DockerAstuteMixin, docker.VolumesCommand):
|
||||
"""Print all volumes of a container."""
|
|
@ -27,6 +27,7 @@ import traceback
|
|||
from cliff import app
|
||||
from cliff import commandmanager
|
||||
|
||||
from docker import astute
|
||||
from docker import nailgun
|
||||
from docker import nginx
|
||||
import exc
|
||||
|
@ -36,6 +37,18 @@ import info
|
|||
COMMANDS = {
|
||||
'info': info.Info,
|
||||
|
||||
'astute-id': astute.Id,
|
||||
'astute-config': astute.Config,
|
||||
'astute-dir': astute.Dir,
|
||||
'astute-log': astute.Log,
|
||||
'astute-restart': astute.Restart,
|
||||
'astute-rsync': astute.Rsync,
|
||||
'astute-shell': astute.Shell,
|
||||
'astute-start': astute.Start,
|
||||
'astute-stop': astute.Stop,
|
||||
'astute-tail': astute.Tail,
|
||||
'astute-volumes': astute.Volumes,
|
||||
|
||||
'nailgun-id': nailgun.Id,
|
||||
'nailgun-config': nailgun.Config,
|
||||
'nailgun-dir': nailgun.Dir,
|
||||
|
|
Loading…
Reference in New Issue