Skip to content

Commit

Permalink
Merge pull request #843 from MirantisWorkloadMobility/devel
Browse files Browse the repository at this point in the history
Release 2016-02-14
  • Loading branch information
MirantisWorkloadMobility committed Feb 14, 2016
2 parents 369a603 + bff94ea commit 2e28ba1
Show file tree
Hide file tree
Showing 24 changed files with 253 additions and 153 deletions.
4 changes: 2 additions & 2 deletions cfglib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
help='Keystone service endpoint for authorization'),
cfg.StrOpt('host', default='-',
help='ip-address controller for cloud'),
cfg.StrOpt('ssh_host', default='$host',
cfg.StrOpt('ssh_host', default=None,
help='ip-address of cloud node for ssh connect'),
cfg.ListOpt('ext_cidr', default=[], help='external network CIDR'),
cfg.StrOpt('user', default='-',
Expand Down Expand Up @@ -43,7 +43,7 @@
help='Keystone service endpoint for authorization'),
cfg.StrOpt('host', default='-',
help='ip-address controller for cloud'),
cfg.StrOpt('ssh_host', default='$host',
cfg.StrOpt('ssh_host', default=None,
help='ip-address of cloud node for ssh connect'),
cfg.ListOpt('ext_cidr', default=[], help='external network CIDR'),
cfg.StrOpt('user', default='-',
Expand Down
6 changes: 3 additions & 3 deletions cloudferrylib/os/actions/check_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def check_access(self, node):
gateway = cfg.ssh_host
runner = remote_runner.RemoteRunner(node, cfg.ssh_user,
password=cfg.ssh_sudo_password,
timeout=60)
timeout=60,
gateway=gateway)
try:
with api.settings(gateway=gateway,
abort_on_prompts=True):
with api.settings(abort_on_prompts=True):
runner.run('echo')
except remote_runner.RemoteExecutionError as e:
LOG.debug('Check access error: %s', e, exc_info=True)
Expand Down
12 changes: 8 additions & 4 deletions cloudferrylib/os/actions/check_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ def run(self, **kwargs):
src_users = src_keystone_client.users.list()
dst_users = dst_keystone_client.users.list()

src_user_names = set(map(attrgetter('name'), src_users))
dst_user_names = set(map(attrgetter('name'), dst_users))
src_user_names = {name.lower(): name
for name in map(attrgetter('name'), src_users)}
dst_user_names = {name.lower(): name
for name in map(attrgetter('name'), dst_users)}

users_missing_on_dst = src_user_names - dst_user_names
users_missing_on_dst = \
set(src_user_names.keys()) - set(dst_user_names.keys())

if users_missing_on_dst:
msg = "{n} missing users on destination: {users}".format(
n=len(users_missing_on_dst),
users=", ".join(users_missing_on_dst))
users=", ".join(src_user_names[key]
for key in users_missing_on_dst))
LOG.error(msg)
raise cf_exceptions.AbortMigrationError(msg)

Expand Down
33 changes: 16 additions & 17 deletions cloudferrylib/os/actions/cinder_database_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import os
import time

from fabric.context_managers import settings

from cloudferrylib.base.action import action
from cloudferrylib.base.exception import AbortMigrationError
from cloudferrylib.views import cinder_storage_view
Expand Down Expand Up @@ -81,10 +79,11 @@


def _remote_runner(cloud):
return remote_runner.RemoteRunner(cloud[CFG].get(SSH_HOST),
return remote_runner.RemoteRunner(cloud[CFG].get(HOST),
cloud[CFG].ssh_user,
cloud[CFG].ssh_sudo_password,
sudo=True)
sudo=True,
gateway=cloud[CFG].get(SSH_HOST))


def _volume_types_map(data):
Expand Down Expand Up @@ -380,11 +379,9 @@ def fix_metadata(self, data):

def _run_cmd(self, cloud, cmd):
runner = _remote_runner(cloud)
with settings(gateway=cloud[CFG].get(SSH_HOST),
connection_attempts=self.ssh_attempts):
output = runner.run(cmd)
res = output.split('\r\n')
return res if len(res) > 1 else res[0]
output = runner.run(cmd)
res = output.split('\r\n')
return res if len(res) > 1 else res[0]

def run_repeat_on_errors(self, cloud, cmd):
"""Run remote command cmd.
Expand All @@ -393,12 +390,10 @@ def run_repeat_on_errors(self, cloud, cmd):
"""
runner = _remote_runner(cloud)
with settings(gateway=cloud[CFG].get(SSH_HOST),
connection_attempts=self.ssh_attempts):
try:
runner.run_repeat_on_errors(cmd)
except remote_runner.RemoteExecutionError as e:
return e.message
try:
runner.run_repeat_on_errors(cmd)
except remote_runner.RemoteExecutionError as e:
return e.message

def find_dir(self, position, paths, v):
"""
Expand All @@ -407,15 +402,17 @@ def find_dir(self, position, paths, v):
:return: path to the file
"""
volume_filename = self.storage[position].volume_name_template + v['id']
LOG.debug('Looking for %s in %s', volume_filename, repr(paths))
if not paths:
return None
volume_filename = self.storage[position].volume_name_template + v['id']
for p in paths:
cmd = 'ls -1 %s' % p
lst = self._run_cmd(self.clouds[position], cmd)
if lst and not isinstance(lst, list):
lst = [lst]
if volume_filename in lst:
LOG.debug('Found %s in %s', volume_filename, p)
return '%s/%s' % (p, volume_filename)

def run_rsync(self, src, dst):
Expand All @@ -426,7 +423,7 @@ def run_rsync(self, src, dst):
"""
cmd = RSYNC_CMD
cmd += ' %s %s@%s:%s' % (src, self.clouds[DST][CFG].ssh_user,
self.clouds[DST][CFG].get(SSH_HOST), dst)
self.clouds[DST][CFG].get(HOST), dst)
err = self.run_repeat_on_errors(self.clouds[SRC], cmd)
if err:
LOG.warning("Failed copying to %s", dst)
Expand Down Expand Up @@ -756,6 +753,8 @@ def _volumes_size_map(self):
volumes_size_map = {}
for position in self.clouds:
for v in self.data[position]['volumes']:
LOG.debug('Calculating size of volume %s on %s cloud',
v['id'], position)
volume_type_id = v.get('volume_type_id', None)
srcpaths = self._paths(position, volume_type_id)
src = self.find_dir(position, srcpaths, v)
Expand Down
17 changes: 9 additions & 8 deletions cloudferrylib/os/compute/nova_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def deploy(self, instance, create_params, client_conf):
try:
return self.nc.deploy_instance(create_params, client_conf)
except exception.TimeoutException:
az = instance['availability_zone']
az = self.nc.get_availability_zone(instance['availability_zone'])
hosts = self.nc.get_compute_hosts(availability_zone=az)
random.seed()
random.shuffle(hosts)
Expand Down Expand Up @@ -959,15 +959,16 @@ def dissociate_floatingip(self, instance_id, floatingip):
def get_hypervisor_statistics(self):
return self.nova_client.hypervisors.statistics()

def get_compute_hosts(self, availability_zone=None):
if availability_zone:
try:
self.nova_client.availability_zones.find(
def get_availability_zone(self, availability_zone):
try:
self.nova_client.availability_zones.find(
zoneName=availability_zone)
except nova_exc.NotFound:
availability_zone = \
self.config.migrate.default_availability_zone
except nova_exc.NotFound:
availability_zone = \
self.config.migrate.default_availability_zone
return availability_zone

def get_compute_hosts(self, availability_zone=None):
hosts = self.nova_client.hosts.list(zone=availability_zone)
az_host_names = set([h.host_name for h in hosts])

Expand Down
Loading

0 comments on commit 2e28ba1

Please sign in to comment.