Merge "Handle Volume launch as instance(NG) in Volume tables."
This commit is contained in:
commit
8cade6356e
@ -328,11 +328,27 @@
|
||||
}
|
||||
);
|
||||
|
||||
var volumeWatcher = $scope.$watchCollection(
|
||||
function getVolumes() {
|
||||
return $scope.model.volumes;
|
||||
},
|
||||
function onVolumesChange() {
|
||||
$scope.initPromise.then(function onInit() {
|
||||
$scope.$applyAsync(function setDefaultVolume() {
|
||||
if ($scope.launchContext.volumeId) {
|
||||
setSourceVolumeWithId($scope.launchContext.volumeId);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
// Explicitly remove watchers on desruction of this controller
|
||||
$scope.$on('$destroy', function() {
|
||||
newSpecWatcher();
|
||||
allocatedWatcher();
|
||||
imagesWatcher();
|
||||
volumeWatcher();
|
||||
});
|
||||
|
||||
// Initialize
|
||||
@ -460,5 +476,14 @@
|
||||
ctrl.currentBootSource = ctrl.bootSourcesOptions[0].type;
|
||||
}
|
||||
}
|
||||
|
||||
function setSourceVolumeWithId(id) {
|
||||
var pre = findSourceById($scope.model.volumes, id);
|
||||
if (pre) {
|
||||
changeBootSource(bootSourceTypes.VOLUME, [pre]);
|
||||
$scope.model.newInstanceSpec.source_type = ctrl.bootSourcesOptions[2];
|
||||
ctrl.currentBootSource = ctrl.bootSourcesOptions[2].type;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
@ -49,7 +49,7 @@
|
||||
newInstanceSpec: { source: [], source_type: '' },
|
||||
images: [ { id: 'image-1' }, { id: 'image-2' } ],
|
||||
imageSnapshots: [],
|
||||
volumes: [],
|
||||
volumes: [ { id: 'volume-1' }, { id: 'volume-2' } ],
|
||||
volumeSnapshots: [],
|
||||
novaLimits: {
|
||||
maxTotalInstances: 10,
|
||||
@ -188,15 +188,26 @@
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults source to volume-2 if launchContext.volumeId = volume-2', function() {
|
||||
scope.launchContext = { volumeId: 'volume-2' };
|
||||
deferred.resolve();
|
||||
|
||||
$browser.defer.flush();
|
||||
|
||||
expect(ctrl.tableData.allocated[0]).toEqual({ id: 'volume-2' });
|
||||
expect(scope.model.newInstanceSpec.source_type.type).toBe('volume');
|
||||
expect(ctrl.currentBootSource).toBe('volume');
|
||||
});
|
||||
|
||||
describe('Scope Functions', function() {
|
||||
|
||||
describe('watchers', function () {
|
||||
it('establishes three watches', function() {
|
||||
expect(scope.$watch.calls.count()).toBe(3);
|
||||
expect(scope.$watch.calls.count()).toBe(4);
|
||||
});
|
||||
|
||||
it("establishes one watch collections", function () {
|
||||
expect(scope.$watchCollection.calls.count()).toBe(1);
|
||||
expect(scope.$watchCollection.calls.count()).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import NoReverseMatch # noqa
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import HttpResponse # noqa
|
||||
@ -62,6 +63,30 @@ class LaunchVolume(tables.LinkAction):
|
||||
return False
|
||||
|
||||
|
||||
class LaunchVolumeNG(LaunchVolume):
|
||||
name = "launch_volume_ng"
|
||||
verbose_name = _("Launch as Instance")
|
||||
url = "horizon:project:volumes:index"
|
||||
classes = ("btn-launch", )
|
||||
ajax = False
|
||||
|
||||
def __init__(self, attrs=None, **kwargs):
|
||||
kwargs['preempt'] = True
|
||||
super(LaunchVolume, self).__init__(attrs, **kwargs)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
url = reverse(self.url)
|
||||
vol_id = "%s:vol" % self.table.get_object_id(datum)
|
||||
ngclick = "modal.openLaunchInstanceWizard(" \
|
||||
"{successUrl: '%s', volumeId: '%s'})" \
|
||||
% (url, vol_id.split(":vol")[0])
|
||||
self.attrs.update({
|
||||
"ng-controller": "LaunchInstanceModalController as modal",
|
||||
"ng-click": ngclick
|
||||
})
|
||||
return "javascript:void(0);"
|
||||
|
||||
|
||||
class DeleteVolume(VolumePolicyTargetMixin, tables.DeleteAction):
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
@ -450,10 +475,18 @@ class VolumesTable(VolumesTableBase):
|
||||
row_class = UpdateRow
|
||||
table_actions = (CreateVolume, AcceptTransfer, DeleteVolume,
|
||||
VolumesFilterAction)
|
||||
row_actions = (EditVolume, ExtendVolume, LaunchVolume, EditAttachments,
|
||||
CreateSnapshot, CreateBackup, RetypeVolume,
|
||||
UploadToImage, CreateTransfer, DeleteTransfer,
|
||||
DeleteVolume)
|
||||
|
||||
launch_actions = ()
|
||||
if getattr(settings, 'LAUNCH_INSTANCE_LEGACY_ENABLED', False):
|
||||
launch_actions = (LaunchVolume,) + launch_actions
|
||||
if getattr(settings, 'LAUNCH_INSTANCE_NG_ENABLED', True):
|
||||
launch_actions = (LaunchVolumeNG,) + launch_actions
|
||||
|
||||
row_actions = ((EditVolume, ExtendVolume,) +
|
||||
launch_actions +
|
||||
(EditAttachments, CreateSnapshot, CreateBackup,
|
||||
RetypeVolume, UploadToImage, CreateTransfer,
|
||||
DeleteTransfer, DeleteVolume))
|
||||
|
||||
|
||||
class DetachVolume(tables.BatchAction):
|
||||
|
Loading…
Reference in New Issue
Block a user