Skip to content

Commit

Permalink
[CF-257] Use migration name for estimate_migration
Browse files Browse the repository at this point in the history
New cloud object queries are defined in migrations section of
configuration file. This commit modify estimate_migration to use
name of migration in this section to provide estimates for that
migration.
  • Loading branch information
antonf committed Mar 18, 2016
1 parent c5cfdf9 commit 61326e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cloudferrylib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def _do_deserialize(self, value):
for field in self.variants:
try:
return field.deserialize(value)
except marshmallow.ValidationError as e:
errors.append(e)
except marshmallow.ValidationError as ex:
errors.append(ex)
raise marshmallow.ValidationError([e.messages for e in errors])


Expand Down
26 changes: 18 additions & 8 deletions cloudferrylib/os/estimation/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ def list_filtered(session, cls, cloud_name, tenant):
if tenant is None or tenant == x.tenant.object_id.id)


def estimate_copy(cloud_name, tenant):
def estimate_copy(cfg, migration_name):
migration = cfg.migrations[migration_name]
query = migration.query
src_cloud = migration.source

with model.Session() as session:
total_ephemeral_size = 0
total_volume_size = 0
total_image_size = 0
accounted_volumes = set()
accounted_images = set()

for server in list_filtered(session, nova.Server, cloud_name, tenant):
for server in query.search(session, src_cloud, nova.Server):
for ephemeral_disk in server.ephemeral_disks:
total_ephemeral_size += ephemeral_disk.size
if server.image is not None \
Expand All @@ -44,14 +48,16 @@ def estimate_copy(cloud_name, tenant):
if volume.object_id not in accounted_volumes:
total_volume_size += volume.size
accounted_volumes.add(volume.object_id)
for volume in list_filtered(session, cinder.Volume, cloud_name,
tenant):

for volume in query.search(session, src_cloud, cinder.Volume):
if volume.object_id not in accounted_volumes:
total_volume_size += volume.size
for image in list_filtered(session, glance.Image, cloud_name, tenant):

for image in query.search(session, src_cloud, glance.Image):
if image.object_id not in accounted_images:
total_image_size += image.size

print 'Migration', migration_name, 'estimates:'
print 'Images:'
print ' Size:', sizeof_format.sizeof_fmt(total_image_size)
print 'Ephemeral disks:'
Expand All @@ -60,7 +66,7 @@ def estimate_copy(cloud_name, tenant):
print ' Size:', sizeof_format.sizeof_fmt(total_volume_size, 'G')


def show_largest_servers(count, cloud_name, tenant):
def show_largest_servers(cfg, count, migration_name):
def server_size(server):
size = 0
if server.image is not None:
Expand All @@ -72,15 +78,19 @@ def server_size(server):
return size

output = []
migration = cfg.migrations[migration_name]
with model.Session() as session:
for index, server in enumerate(
heapq.nlargest(
count,
list_filtered(session, nova.Server, cloud_name, tenant),
migration.query.search(session, migration.source,
nova.Server),
key=server_size),
start=1):
output.append(
' {0}. {1.object_id.id} {1.name}'.format(index, server))
' {0}. {1.object_id.id} {1.name} - {2}'.format(
index, server,
sizeof_format.sizeof_fmt(server_size(server))))
if output:
print '\n{0} largest servers:'.format(len(output))
for line in output:
Expand Down
13 changes: 10 additions & 3 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,18 @@ def discover(config_path, debug=False):


@task
def estimate_migration(config_path, source, tenant=None, debug=False):
def estimate_migration(config_path, migration, debug=False):
cfg = config.load(load_yaml_config(config_path, debug))
if migration not in cfg.migrations:
print 'No such migration:', migration
print '\nPlease choose one of this:'
for name in sorted(cfg.migrations.keys()):
print ' -', name
return -1

stage.execute_stage('cloudferrylib.os.discovery.stages.DiscoverStage', cfg)
procedures.estimate_copy(source, tenant)
procedures.show_largest_servers(10, source, tenant)
procedures.estimate_copy(cfg, migration)
procedures.show_largest_servers(cfg, 10, migration)


@task
Expand Down

0 comments on commit 61326e8

Please sign in to comment.