Migrate an instance from the admin dashboard
Implements blueprint migrate-instance Change-Id: Icdd70752dc089c314fb3f55eb42ace1e976f8d49
This commit is contained in:
parent
869eaf82f7
commit
94726fdfea
@ -53,15 +53,25 @@ horizon.datatables = {
|
||||
success: function (data, textStatus, jqXHR) {
|
||||
var $new_row = $(data);
|
||||
|
||||
if($new_row.hasClass('status_unknown')) {
|
||||
if ($new_row.hasClass('status_unknown')) {
|
||||
var spinner_elm = $new_row.find("td.status_unknown:last");
|
||||
// Replacing spin.js here with an animated gif to reduce CPU
|
||||
spinner_elm.prepend(
|
||||
$("<div />")
|
||||
.addClass("loading_gif")
|
||||
.append(
|
||||
$("<img />")
|
||||
.attr("src", "/static/dashboard/img/loading.gif")));
|
||||
|
||||
if ($new_row.find('a.btn-action-required').length > 0) {
|
||||
spinner_elm.prepend(
|
||||
$("<div />")
|
||||
.addClass("action_required_img")
|
||||
.append(
|
||||
$("<img />")
|
||||
.attr("src", "/static/dashboard/img/action_required.png")));
|
||||
} else {
|
||||
// Replacing spin.js here with an animated gif to reduce CPU
|
||||
spinner_elm.prepend(
|
||||
$("<div />")
|
||||
.addClass("loading_gif")
|
||||
.append(
|
||||
$("<img />")
|
||||
.attr("src", "/static/dashboard/img/loading.gif")));
|
||||
}
|
||||
}
|
||||
|
||||
// Only replace row if the html content has changed
|
||||
|
@ -378,6 +378,18 @@ def server_update(request, instance_id, name):
|
||||
return response
|
||||
|
||||
|
||||
def server_migrate(request, instance_id):
|
||||
novaclient(request).servers.migrate(instance_id)
|
||||
|
||||
|
||||
def server_confirm_resize(request, instance_id):
|
||||
novaclient(request).servers.confirm_resize(instance_id)
|
||||
|
||||
|
||||
def server_revert_resize(request, instance_id):
|
||||
novaclient(request).servers.revert_resize(instance_id)
|
||||
|
||||
|
||||
def server_add_floating_ip(request, server, floating_ip):
|
||||
"""Associates floating IP to server's fixed IP.
|
||||
"""
|
||||
|
@ -26,12 +26,31 @@ from horizon.utils.filters import replace_underscores
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.dashboards.project.instances.tables import (
|
||||
TerminateInstance, EditInstance, ConsoleLink, LogLink, CreateSnapshot,
|
||||
TogglePause, ToggleSuspend, RebootInstance, get_size, UpdateRow,
|
||||
get_ips, get_power_state)
|
||||
TogglePause, ToggleSuspend, RebootInstance, ConfirmResize,
|
||||
RevertResize, get_size, UpdateRow, get_ips, get_power_state,
|
||||
is_deleting, ACTIVE_STATES, STATUS_DISPLAY_CHOICES,
|
||||
TASK_DISPLAY_CHOICES)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MigrateInstance(tables.BatchAction):
|
||||
name = "migrate"
|
||||
action_present = _("Migrate")
|
||||
action_past = _("Scheduled migration (pending confirmation) of")
|
||||
data_type_singular = _("Instance")
|
||||
data_type_plural = _("Instances")
|
||||
classes = ("btn-migrate", "btn-danger")
|
||||
|
||||
def allowed(self, request, instance):
|
||||
return ((instance.status in ACTIVE_STATES
|
||||
or instance.status == 'SHUTOFF')
|
||||
and not is_deleting(instance))
|
||||
|
||||
def action(self, request, obj_id):
|
||||
api.server_migrate(request, obj_id)
|
||||
|
||||
|
||||
class AdminUpdateRow(UpdateRow):
|
||||
def get_data(self, request, instance_id):
|
||||
instance = super(AdminUpdateRow, self).get_data(request, instance_id)
|
||||
@ -54,9 +73,6 @@ class AdminInstancesTable(tables.DataTable):
|
||||
("paused", True),
|
||||
("error", False),
|
||||
)
|
||||
TASK_DISPLAY_CHOICES = (
|
||||
("image_snapshot", "Snapshotting"),
|
||||
)
|
||||
tenant = tables.Column("tenant_name", verbose_name=_("Project"))
|
||||
# NOTE(gabriel): Commenting out the user column because all we have
|
||||
# is an ID, and correlating that at production scale using our current
|
||||
@ -78,7 +94,8 @@ class AdminInstancesTable(tables.DataTable):
|
||||
filters=(title, replace_underscores),
|
||||
verbose_name=_("Status"),
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES)
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
task = tables.Column("OS-EXT-STS:task_state",
|
||||
verbose_name=_("Task"),
|
||||
filters=(title, replace_underscores),
|
||||
@ -95,6 +112,6 @@ class AdminInstancesTable(tables.DataTable):
|
||||
status_columns = ["status", "task"]
|
||||
table_actions = (TerminateInstance,)
|
||||
row_class = AdminUpdateRow
|
||||
row_actions = (EditInstance, ConsoleLink, LogLink, CreateSnapshot,
|
||||
TogglePause, ToggleSuspend, RebootInstance,
|
||||
TerminateInstance)
|
||||
row_actions = (ConfirmResize, RevertResize, EditInstance, ConsoleLink,
|
||||
LogLink, CreateSnapshot, TogglePause, ToggleSuspend,
|
||||
MigrateInstance, RebootInstance, TerminateInstance)
|
||||
|
@ -140,3 +140,37 @@ class InstanceViewTest(test.BaseAdminViewTests):
|
||||
self.assertContains(res, "512MB RAM | 1 VCPU | 0 Disk", 1, 200)
|
||||
self.assertContains(res, "Active", 1, 200)
|
||||
self.assertContains(res, "Running", 1, 200)
|
||||
|
||||
@test.create_stubs({api.nova: ('flavor_list', 'server_list',),
|
||||
api.keystone: ('tenant_list',)})
|
||||
def test_index_options_before_migrate(self):
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest), admin=True).\
|
||||
AndReturn(self.tenants.list())
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
all_tenants=True).AndReturn(self.servers.list())
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).\
|
||||
AndReturn(self.flavors.list())
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(reverse('horizon:admin:instances:index'))
|
||||
self.assertContains(res, "instances__migrate")
|
||||
self.assertNotContains(res, "instances__confirm")
|
||||
self.assertNotContains(res, "instances__revert")
|
||||
|
||||
@test.create_stubs({api.nova: ('flavor_list', 'server_list',),
|
||||
api.keystone: ('tenant_list',)})
|
||||
def test_index_options_after_migrate(self):
|
||||
server = self.servers.first()
|
||||
server.status = "VERIFY_RESIZE"
|
||||
api.keystone.tenant_list(IsA(http.HttpRequest), admin=True).\
|
||||
AndReturn(self.tenants.list())
|
||||
api.nova.server_list(IsA(http.HttpRequest),
|
||||
all_tenants=True).AndReturn(self.servers.list())
|
||||
api.nova.flavor_list(IsA(http.HttpRequest)).\
|
||||
AndReturn(self.flavors.list())
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(reverse('horizon:admin:instances:index'))
|
||||
self.assertContains(res, "instances__confirm")
|
||||
self.assertContains(res, "instances__revert")
|
||||
self.assertNotContains(res, "instances__migrate")
|
||||
|
@ -59,7 +59,7 @@ SUSPEND = 0
|
||||
RESUME = 1
|
||||
|
||||
|
||||
def _is_deleting(instance):
|
||||
def is_deleting(instance):
|
||||
task_state = getattr(instance, "OS-EXT-STS:task_state", None)
|
||||
if not task_state:
|
||||
return False
|
||||
@ -97,7 +97,7 @@ class RebootInstance(tables.BatchAction):
|
||||
def allowed(self, request, instance=None):
|
||||
return ((instance.status in ACTIVE_STATES
|
||||
or instance.status == 'SHUTOFF')
|
||||
and not _is_deleting(instance))
|
||||
and not is_deleting(instance))
|
||||
|
||||
def action(self, request, obj_id):
|
||||
api.server_reboot(request, obj_id)
|
||||
@ -121,7 +121,7 @@ class TogglePause(tables.BatchAction):
|
||||
else:
|
||||
self.current_present_action = PAUSE
|
||||
return ((instance.status in ACTIVE_STATES or self.paused)
|
||||
and not _is_deleting(instance))
|
||||
and not is_deleting(instance))
|
||||
|
||||
def action(self, request, obj_id):
|
||||
if self.paused:
|
||||
@ -150,7 +150,7 @@ class ToggleSuspend(tables.BatchAction):
|
||||
else:
|
||||
self.current_present_action = SUSPEND
|
||||
return ((instance.status in ACTIVE_STATES or self.suspended)
|
||||
and not _is_deleting(instance))
|
||||
and not is_deleting(instance))
|
||||
|
||||
def action(self, request, obj_id):
|
||||
if self.suspended:
|
||||
@ -202,7 +202,7 @@ class EditInstance(tables.LinkAction):
|
||||
classes = ("ajax-modal", "btn-edit")
|
||||
|
||||
def allowed(self, request, instance):
|
||||
return not _is_deleting(instance)
|
||||
return not is_deleting(instance)
|
||||
|
||||
|
||||
class CreateSnapshot(tables.LinkAction):
|
||||
@ -212,7 +212,7 @@ class CreateSnapshot(tables.LinkAction):
|
||||
classes = ("ajax-modal", "btn-camera")
|
||||
|
||||
def allowed(self, request, instance=None):
|
||||
return instance.status in ACTIVE_STATES and not _is_deleting(instance)
|
||||
return instance.status in ACTIVE_STATES and not is_deleting(instance)
|
||||
|
||||
|
||||
class ConsoleLink(tables.LinkAction):
|
||||
@ -222,7 +222,7 @@ class ConsoleLink(tables.LinkAction):
|
||||
classes = ("btn-console",)
|
||||
|
||||
def allowed(self, request, instance=None):
|
||||
return instance.status in ACTIVE_STATES and not _is_deleting(instance)
|
||||
return instance.status in ACTIVE_STATES and not is_deleting(instance)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
base_url = super(ConsoleLink, self).get_link_url(datum)
|
||||
@ -237,7 +237,7 @@ class LogLink(tables.LinkAction):
|
||||
classes = ("btn-log",)
|
||||
|
||||
def allowed(self, request, instance=None):
|
||||
return instance.status in ACTIVE_STATES and not _is_deleting(instance)
|
||||
return instance.status in ACTIVE_STATES and not is_deleting(instance)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
base_url = super(LogLink, self).get_link_url(datum)
|
||||
@ -245,6 +245,30 @@ class LogLink(tables.LinkAction):
|
||||
return "?".join([base_url, tab_query_string])
|
||||
|
||||
|
||||
class ConfirmResize(tables.Action):
|
||||
name = "confirm"
|
||||
verbose_name = _("Confirm Resize/Migrate")
|
||||
classes = ("btn-confirm", "btn-action-required")
|
||||
|
||||
def allowed(self, request, instance):
|
||||
return instance.status == 'VERIFY_RESIZE'
|
||||
|
||||
def single(self, table, request, instance):
|
||||
api.server_confirm_resize(request, instance)
|
||||
|
||||
|
||||
class RevertResize(tables.Action):
|
||||
name = "revert"
|
||||
verbose_name = _("Revert Resize/Migrate")
|
||||
classes = ("btn-revert", "btn-action-required")
|
||||
|
||||
def allowed(self, request, instance):
|
||||
return instance.status == 'VERIFY_RESIZE'
|
||||
|
||||
def single(self, table, request, instance):
|
||||
api.server_revert_resize(request, instance)
|
||||
|
||||
|
||||
class AssociateIP(tables.LinkAction):
|
||||
name = "associate"
|
||||
verbose_name = _("Associate Floating IP")
|
||||
@ -254,7 +278,7 @@ class AssociateIP(tables.LinkAction):
|
||||
def allowed(self, request, instance):
|
||||
if HORIZON_CONFIG["simple_ip_management"]:
|
||||
return False
|
||||
return not _is_deleting(instance)
|
||||
return not is_deleting(instance)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
base_url = urlresolvers.reverse(self.url)
|
||||
@ -273,7 +297,7 @@ class SimpleAssociateIP(tables.Action):
|
||||
def allowed(self, request, instance):
|
||||
if not HORIZON_CONFIG["simple_ip_management"]:
|
||||
return False
|
||||
return not _is_deleting(instance)
|
||||
return not is_deleting(instance)
|
||||
|
||||
def single(self, table, request, instance):
|
||||
try:
|
||||
@ -302,7 +326,7 @@ class SimpleDisassociateIP(tables.Action):
|
||||
def allowed(self, request, instance):
|
||||
if not HORIZON_CONFIG["simple_ip_management"]:
|
||||
return False
|
||||
return not _is_deleting(instance)
|
||||
return not is_deleting(instance)
|
||||
|
||||
def single(self, table, request, instance_id):
|
||||
try:
|
||||
@ -365,6 +389,24 @@ def get_power_state(instance):
|
||||
return POWER_STATES.get(getattr(instance, "OS-EXT-STS:power_state", 0), '')
|
||||
|
||||
|
||||
STATUS_DISPLAY_CHOICES = (
|
||||
("resize", "Resize/Migrate"),
|
||||
("verify_resize", "Confirm or Revert Resize/Migrate"),
|
||||
("revert_resize", "Revert Resize/Migrate"),
|
||||
)
|
||||
|
||||
|
||||
TASK_DISPLAY_CHOICES = (
|
||||
("image_snapshot", "Snapshotting"),
|
||||
("resize_prep", "Preparing Resize or Migrate"),
|
||||
("resize_migrating", "Resizing or Migrating"),
|
||||
("resize_migrated", "Resized or Migrated"),
|
||||
("resize_finish", "Finishing Resize or Migrate"),
|
||||
("resize_confirming", "Confirming Resize or Nigrate"),
|
||||
("resize_reverting", "Reverting Resize or Migrate"),
|
||||
)
|
||||
|
||||
|
||||
class InstancesTable(tables.DataTable):
|
||||
TASK_STATUS_CHOICES = (
|
||||
(None, True),
|
||||
@ -377,9 +419,6 @@ class InstancesTable(tables.DataTable):
|
||||
("paused", True),
|
||||
("error", False),
|
||||
)
|
||||
TASK_DISPLAY_CHOICES = (
|
||||
("image_snapshot", "Snapshotting"),
|
||||
)
|
||||
name = tables.Column("name",
|
||||
link=("horizon:project:instances:detail"),
|
||||
verbose_name=_("Instance Name"))
|
||||
@ -392,7 +431,8 @@ class InstancesTable(tables.DataTable):
|
||||
filters=(title, replace_underscores),
|
||||
verbose_name=_("Status"),
|
||||
status=True,
|
||||
status_choices=STATUS_CHOICES)
|
||||
status_choices=STATUS_CHOICES,
|
||||
display_choices=STATUS_DISPLAY_CHOICES)
|
||||
task = tables.Column("OS-EXT-STS:task_state",
|
||||
verbose_name=_("Task"),
|
||||
filters=(title, replace_underscores),
|
||||
@ -409,7 +449,7 @@ class InstancesTable(tables.DataTable):
|
||||
status_columns = ["status", "task"]
|
||||
row_class = UpdateRow
|
||||
table_actions = (LaunchLink, TerminateInstance)
|
||||
row_actions = (CreateSnapshot, CurrentAssociateIP,
|
||||
SimpleDisassociateIP, EditInstance, ConsoleLink,
|
||||
LogLink, TogglePause, ToggleSuspend, RebootInstance,
|
||||
TerminateInstance)
|
||||
row_actions = (ConfirmResize, RevertResize, CreateSnapshot,
|
||||
CurrentAssociateIP, SimpleDisassociateIP, EditInstance,
|
||||
ConsoleLink, LogLink, TogglePause, ToggleSuspend,
|
||||
RebootInstance, TerminateInstance)
|
||||
|
@ -1020,3 +1020,20 @@ class InstanceTests(test.TestCase):
|
||||
% (url, " ".join(classes), link_name),
|
||||
html=True,
|
||||
msg_prefix="The launch button is not disabled")
|
||||
|
||||
@test.create_stubs({api: ('flavor_list', 'server_list',
|
||||
'tenant_absolute_limits')})
|
||||
def test_index_options_after_migrate(self):
|
||||
server = self.servers.first()
|
||||
server.status = "VERIFY_RESIZE"
|
||||
|
||||
api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list())
|
||||
api.server_list(IsA(http.HttpRequest)).AndReturn(self.servers.list())
|
||||
api.tenant_absolute_limits(IsA(http.HttpRequest), reserved=True) \
|
||||
.MultipleTimes().AndReturn(self.limits['absolute'])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertContains(res, "instances__confirm")
|
||||
self.assertContains(res, "instances__revert")
|
||||
|
BIN
openstack_dashboard/static/dashboard/img/action_required.png
Normal file
BIN
openstack_dashboard/static/dashboard/img/action_required.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1017 B |
@ -826,6 +826,9 @@ td.actions_column {
|
||||
#floating_ips td.actions_column {
|
||||
width: 180px;
|
||||
}
|
||||
#instances td.actions_column {
|
||||
width: 175px;
|
||||
}
|
||||
|
||||
td.actions_column .row_actions a,
|
||||
td.actions_column .row_actions input,
|
||||
@ -847,6 +850,10 @@ td.actions_column .row_actions .hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
td.actions_column .btn-action-required {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Makes size consistent across browsers when mixing "btn-group" and "small" */
|
||||
.btn.hide, .btn-group .hide {
|
||||
display: none;
|
||||
@ -1395,6 +1402,14 @@ label.log-length {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.action_required_img {
|
||||
width: 35px;
|
||||
height: 13px;
|
||||
padding-top: 2px;
|
||||
padding-right: 5px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
//ResourceBrowser
|
||||
@dataTableBorderWidth: 1px;
|
||||
@dataTableBorderColor: #DDD;
|
||||
|
Loading…
Reference in New Issue
Block a user