diff --git a/magnum_ui/api/magnum.py b/magnum_ui/api/magnum.py index 731ca75d..37746650 100644 --- a/magnum_ui/api/magnum.py +++ b/magnum_ui/api/magnum.py @@ -106,14 +106,14 @@ def bay_show(request, id): return magnumclient(request).bays.get(id) -def container_create(request, bay_id, **kwargs): +def container_create(request, bay_uuid, **kwargs): """Creates a container object :param request: Request context - :param bay_id: ID of a bay (Required) + :param bay_uuid: ID of a bay (Required) :param kwargs: Image ID, Name, Command, Memory :returns: Container object """ - return magnumclient(request).containers.create(bay_id=bay_id, **kwargs) + return magnumclient(request).containers.create(bay_uuid=bay_uuid, **kwargs) def container_delete(request, id): diff --git a/magnum_ui/static/dashboard/containers/containers.scss b/magnum_ui/static/dashboard/containers/containers.scss index bb28c275..4609a00b 100644 --- a/magnum_ui/static/dashboard/containers/containers.scss +++ b/magnum_ui/static/dashboard/containers/containers.scss @@ -7,3 +7,4 @@ @import "baymodel/baymodel"; @import "bay/bay"; +@import "containers/containers"; diff --git a/magnum_ui/static/dashboard/containers/containers/containers.scss b/magnum_ui/static/dashboard/containers/containers/containers.scss new file mode 100644 index 00000000..371da264 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/containers.scss @@ -0,0 +1,2 @@ +// Custom Style Variables +@import "create/info/info"; diff --git a/magnum_ui/static/dashboard/containers/containers/create/container-model.js b/magnum_ui/static/dashboard/containers/containers/create/container-model.js new file mode 100644 index 00000000..cf1f9773 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/container-model.js @@ -0,0 +1,74 @@ +/** + * Copyright 2015 Cisco Systems, 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. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.containers.containers') + .factory('containerModel', containerModel); + + containerModel.$inject = [ + 'horizon.app.core.openstack-service-api.magnum' + ]; + + function containerModel(magnum) { + var model = { + newContainerSpec: {}, + + // API methods + init: init, + createContainer: createContainer + }; + + function initNewContainerSpec() { + model.newContainerSpec = { + name: null, + bay_uuid: null, + image: null, + memory: null, + memorysize: null, + memoryunit: "m", + command: null + }; + } + + function init() { + // Reset the new Bay spec + initNewContainerSpec(); + } + + function createContainer() { + var finalSpec = angular.copy(model.newContainerSpec); + + cleanNullProperties(finalSpec); + + return magnum.createContainer(finalSpec); + } + + function cleanNullProperties(finalSpec) { + // Initially clean fields that don't have any value. + for (var key in finalSpec) { + if (finalSpec.hasOwnProperty(key) && finalSpec[key] === null + || key === "memorysize" || key === "memoryunit") { + delete finalSpec[key]; + } + } + } + + return model; + } +})(); diff --git a/magnum_ui/static/dashboard/containers/containers/create/create-workflow.service.js b/magnum_ui/static/dashboard/containers/containers/create/create-workflow.service.js new file mode 100644 index 00000000..f5f6aa47 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/create-workflow.service.js @@ -0,0 +1,57 @@ +/** + * Copyright 2015 Cisco Systems, 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. + */ + +(function() { + 'use strict'; + + angular + .module('horizon.dashboard.containers.containers') + .factory('horizon.dashboard.containers.containers.workflow', containerWorkflow); + + containerWorkflow.$inject = [ + 'horizon.dashboard.containers.basePath', + 'horizon.app.core.workflow.factory' + ]; + + function containerWorkflow(basePath, dashboardWorkflow) { + return dashboardWorkflow({ + title: gettext('Create Container'), + + steps: [ + { + title: gettext('Info'), + templateUrl: basePath + 'containers/create/info/info.html', + helpUrl: basePath + 'containers/create/info/info.help.html', + formName: 'containerInfoForm' + }, + { + title: gettext('Spec'), + templateUrl: basePath + 'containers/create/spec/spec.html', + helpUrl: basePath + 'containers/create/spec/spec.help.html', + formName: 'containerSpecForm' + } + ], + + btnText: { + finish: gettext('Create') + }, + + btnIcon: { + finish: 'fa fa-cloud-download' + } + }); + } +})(); diff --git a/magnum_ui/static/dashboard/containers/containers/create/info/container.info.controller.js b/magnum_ui/static/dashboard/containers/containers/create/info/container.info.controller.js new file mode 100644 index 00000000..bc9824ea --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/info/container.info.controller.js @@ -0,0 +1,89 @@ +/** + * Copyright 2015 NEC Corporation + * + * 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. + */ + +(function() { + 'use strict'; + + /** + * @ngdoc controller + * @name createContainerInfoController + * @ngController + * + * @description + * Controller for the container info step in create workflow + */ + angular + .module('horizon.dashboard.containers.containers') + .controller('createContainerInfoController', createContainerInfoController); + + createContainerInfoController.$inject = [ + '$q', + '$scope', + 'horizon.dashboard.containers.basePath', + 'horizon.app.core.openstack-service-api.magnum' + ]; + + function createContainerInfoController($q, $scope, basePath, magnum) { + var ctrl = this; + ctrl.bays = [{id:"", name: gettext("Choose a Bay")}]; + $scope.model.newContainerSpec.bay_uuid = ""; + $scope.baydetail = { + name: "", + id: "", + baymodel: "", + master_count: "", + node_count: "", + discovery_url: "", + timeout: "" + }; + + $scope.changeBay = function(){ + // show Bay Detail + if(!$scope.model.newContainerSpec.bay_uuid){ + $("#bay_detail").hide(); + $("#bay_detail_none").show(); + } else { + angular.forEach(ctrl.bays, function(bay, idx){ + if($scope.model.newContainerSpec.bay_uuid === bay.id){ + $("#bay_detail").show(); + $("#bay_detail_none").hide(); + $scope.baydetail.name = bay.name; + $scope.baydetail.id = bay.id; + $scope.baydetail.baymodel_id = bay.baymodel_id; + $scope.baydetail.master_count = bay.master_count; + $scope.baydetail.node_count = bay.node_count; + $scope.baydetail.discovery_url = bay.discovery_url; + $scope.baydetail.timeout = bay.timeout; + } + }); + } + }; + + init(); + $("#bay_detail").hide(); + $("#bay_detail_none").show(); + + function init() { + magnum.getBays({paginate: false}).success(onGetBays); + } + + function onGetBays(response) { + Array.prototype.push.apply(ctrl.bays, response.items); + } + + } + +})(); diff --git a/magnum_ui/static/dashboard/containers/containers/create/info/info.help.html b/magnum_ui/static/dashboard/containers/containers/create/info/info.help.html new file mode 100644 index 00000000..9a433105 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/info/info.help.html @@ -0,0 +1,4 @@ +
+

Description:

+

Specify container name and choose bay.

+
diff --git a/magnum_ui/static/dashboard/containers/containers/create/info/info.html b/magnum_ui/static/dashboard/containers/containers/create/info/info.html new file mode 100644 index 00000000..808d0fcc --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/info/info.html @@ -0,0 +1,47 @@ +
+

Container Details

+ +
+
Please provide the name of the Container.
+ +
+
+ + +
+
+ + +
+
+ +

Bay Detail

+
+ Choose a Bay +
+
+
+
Name
+
{$ baydetail.name $}
+
ID
+
{$ baydetail.id $}
+
BayModel ID
+
{$ baydetail.baymodel_id $}
+
Master Count
+
{$ baydetail.master_count $}
+
Node Count
+
{$ baydetail.node_count $}
+
Timeout
+
{$ baydetail.timeout $}
+
+
+ +
+
diff --git a/magnum_ui/static/dashboard/containers/containers/create/info/info.scss b/magnum_ui/static/dashboard/containers/containers/create/info/info.scss new file mode 100644 index 00000000..23da86c1 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/info/info.scss @@ -0,0 +1,13 @@ +.container-memory { + .input-group { + width: 100%; + + .container-memorysize { + width: 70%; + } + + .container-memoryunit { + width: 30%; + } + } +} \ No newline at end of file diff --git a/magnum_ui/static/dashboard/containers/containers/create/modal.controller.js b/magnum_ui/static/dashboard/containers/containers/create/modal.controller.js new file mode 100644 index 00000000..65c52eb9 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/modal.controller.js @@ -0,0 +1,71 @@ +/** + * Copyright 2015 Cisco Systems, 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. + */ + +(function() { + 'use strict'; + + /** + * @ngdoc overview + * @name containersContainerModalController + * @ngController + * + * @description + * Controller for the container create modal + */ + angular + .module('horizon.dashboard.containers.containers') + .controller('containersContainerModalController', containersContainerModalController); + + containersContainerModalController.$inject = [ + '$modal', + '$window', + 'horizon.dashboard.containers.basePath', + 'horizon.app.core.openstack-service-api.magnum' + ]; + + function containersContainerModalController($modal, $window, basePath, magnum) { + var ctrl = this; + + ctrl.openContainerCreateWizard = openContainerCreateWizard; + + function openContainerCreateWizard(launchContext) { + var options = { + controller: 'ModalContainerController', + backdrop: 'static', + template: '', + windowClass: 'modal-dialog-wizard', + resolve: { + launchContext: function() { + return launchContext; + } + } + }; + var launchInstanceModal = $modal.open(options); + var handleModalClose = function (redirectPropertyName) { + return function () { + if (launchContext && launchContext[redirectPropertyName]) { + $window.location.href = launchContext[redirectPropertyName]; + } + }; + }; + launchInstanceModal.result.then( + handleModalClose('successUrl'), + handleModalClose('dismissUrl') + ); + } + } + +})(); diff --git a/magnum_ui/static/dashboard/containers/containers/create/modal.spec.js b/magnum_ui/static/dashboard/containers/containers/create/modal.spec.js new file mode 100644 index 00000000..e69de29b diff --git a/magnum_ui/static/dashboard/containers/containers/create/spec/container.spec.controller.js b/magnum_ui/static/dashboard/containers/containers/create/spec/container.spec.controller.js new file mode 100644 index 00000000..c94d71a7 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/spec/container.spec.controller.js @@ -0,0 +1,61 @@ +/** + * Copyright 2015 NEC Corporation + * + * 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. + */ + +(function() { + 'use strict'; + + /** + * @ngdoc controller + * @name createContainerSpecController + * @ngController + * + * @description + * Controller for the container spec step in create workflow + */ + angular + .module('horizon.dashboard.containers.containers') + .controller('createContainerSpecController', createContainerSpecController); + + createContainerSpecController.$inject = [ + '$q', + '$scope', + 'horizon.dashboard.containers.basePath', + 'horizon.app.core.openstack-service-api.magnum' + ]; + + function createContainerSpecController($q, $scope, basePath, magnum) { + var ctrl = this; + ctrl.memoryunits = [{unit: "b", label: gettext("bytes")}, + {unit: "k", label: gettext("KB")}, + {unit: "m", label: gettext("MB")}, + {unit: "g", label: gettext("GB")}]; + + $scope.changeMemory = function(){ + if($scope.model.newContainerSpec.memorysize > 0){ + $scope.model.newContainerSpec.memory = $scope.model.newContainerSpec.memorysize + $scope.model.newContainerSpec.memoryunit; + }else{ + $scope.model.newContainerSpec.memory = ""; + } + }; + $scope.changeMemoryUnit = function(){ + $scope.changeMemory(); + }; + $scope.changeMemorySize = function(){ + $scope.changeMemory(); + }; + } + +})(); diff --git a/magnum_ui/static/dashboard/containers/containers/create/spec/spec.help.html b/magnum_ui/static/dashboard/containers/containers/create/spec/spec.help.html new file mode 100644 index 00000000..857c2538 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/spec/spec.help.html @@ -0,0 +1,4 @@ +
+

Description:

+

Specify the specs for the container.

+
diff --git a/magnum_ui/static/dashboard/containers/containers/create/spec/spec.html b/magnum_ui/static/dashboard/containers/containers/create/spec/spec.html new file mode 100644 index 00000000..aaada952 --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/spec/spec.html @@ -0,0 +1,44 @@ +
+

Container Spec

+ +
+
Please provide the specs for this Container.
+ +
+
+ + +
+
+ +
+ + +
+ +
+
+ + +
+
+ +
+
diff --git a/magnum_ui/static/dashboard/containers/containers/create/wizard.controller.js b/magnum_ui/static/dashboard/containers/containers/create/wizard.controller.js new file mode 100644 index 00000000..e589b30d --- /dev/null +++ b/magnum_ui/static/dashboard/containers/containers/create/wizard.controller.js @@ -0,0 +1,45 @@ +/** + * Copyright 2015 Cisco Systems, 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. + */ + +(function() { + 'use strict'; + + /** + * @ngdoc overview + * @name createContainerWizardController + * @ngController + * + * @description + * Controller for the container create modal + */ + angular + .module('horizon.dashboard.containers.containers') + .controller('createContainerWizardController', createContainerWizardController); + + createContainerWizardController.$inject = [ + '$scope', + 'containerModel', + 'horizon.dashboard.containers.containers.workflow' + ]; + + function createContainerWizardController($scope, model, workflow) { + $scope.workflow = workflow; + $scope.model = model; + $scope.model.init(); + $scope.submit = $scope.model.createContainer; + } + +})(); diff --git a/magnum_ui/static/dashboard/containers/containers/table/table.html b/magnum_ui/static/dashboard/containers/containers/table/table.html index 4b953670..62008eab 100644 --- a/magnum_ui/static/dashboard/containers/containers/table/table.html +++ b/magnum_ui/static/dashboard/containers/containers/table/table.html @@ -20,6 +20,14 @@ + + + Create Container + +