Adding and removing instances from the Global Slice
Change-Id: Ib6658d643f2e468e43084b0fd8f11020f0975c40
diff --git a/views/ngXosViews/globalXos/src/js/main.js b/views/ngXosViews/globalXos/src/js/main.js
index 31effcc..16beca1 100644
--- a/views/ngXosViews/globalXos/src/js/main.js
+++ b/views/ngXosViews/globalXos/src/js/main.js
@@ -30,7 +30,7 @@
const self = this;
$q.all([
Controllers.query({backend_type: 'CORD'}).$promise,
- Slices.query().$promise // NOTE why this is queryFromAll??
+ Slices.query().$promise
])
.then(res => {
[this.xoss, this.gSlices] = res;
@@ -42,15 +42,218 @@
}
};
+ const getGlobalInstances = (item) => {
+ $uibModal.open({
+ animation: true,
+ size: 'lg',
+ templateUrl: 'listInstances.html',
+ controllerAs: 'vm',
+ resolve: {
+ slice: function () {
+ return {
+ name: item.name,
+ xos: {
+ name: 'G-XOS'
+ }
+ };
+ }
+ },
+ controller: function($uibModalInstance, slice, LocalInstances, LocalSlices) {
+ this.slice = slice;
+
+ this.config = {
+ columns: [
+ {
+ label: 'Name',
+ prop: 'name',
+ }
+ ],
+ actions: [
+ {
+ label: 'Add Instance',
+ icon: 'remove',
+ color: 'red',
+ cb: (item) => {
+ console.log(item);
+ LocalInstances.deleteFromLocal(item)
+ .then(() => {
+ _.remove(this.instances, i => i.id === item.id);
+ });
+ }
+ }
+ ]
+ };
+
+ LocalSlices.queryFromAll(self.xoss).$promise
+ .then(slices => {
+ // keep only the slice that match the name
+ this.slicesId = slices
+ .filter(s => s.name.indexOf(this.slice.name) > -1)
+ .reduce((o, s) => {
+ o[s.xos.id] = s.id;
+ return o;
+ }, {});
+ return LocalInstances.queryFromAll(self.xoss).$promise;
+ })
+ .then(instances => {
+ this.instances = instances.filter(i => this.slicesId[i.xos.id] === i.slice);
+ })
+ .catch(e => {
+ this.instances = [];
+ });
+
+ this.close = () => {
+ $uibModalInstance.dismiss('cancel');
+ }
+ }
+ })
+ };
+
+ const createGlobalInstance = (item) => {
+ $uibModal.open({
+ animation: true,
+ size: 'lg',
+ templateUrl: 'addInstance.html',
+ controller: function($scope, $q, $uibModalInstance, slice, LocalInstances, LocalAuth){
+ this.slice = slice;
+
+ this.model = {
+ // isolation: 'vm'
+ };
+
+ let xos;
+
+ Controllers.query({backend_type: 'CORD'}).$promise
+ .then((xos) => {
+ this.xoss = xos;
+ this.config.fields['xos'].options = _.map(xos, item => {
+ return {id: item.id, label: item.name}
+ });
+ });
+
+ $scope.$watch(() => this.model.xos, () => {
+ if(!this.model.xos){
+ return;
+ }
+ xos = _.find(this.xoss, {id: this.model.xos});
+ LocalInstances.getLocalInfo(xos)
+ .then((res) => {
+ [
+ this.config.fields['deployment'].options,
+ this.config.fields['image'].options,
+ this.config.fields['flavor'].options,
+ this.config.fields['node'].options
+ ] = res;
+ return $q.all([
+ LocalSlices.getLocalByName(xos, this.slice.name),
+ LocalAuth.getUserByName(xos, xos.admin_user)
+ ]);
+ })
+ .then((res) => {
+ console.log('aaaa: ', res);
+ [this.localSlice, this.user] = res;
+ });
+ });
+
+
+ this.config = {
+ formName: 'instanceForm',
+ order: ['xos', 'name'],
+ excludedFields: ['xos', 'slice'],
+ actions: [
+ {
+ label: 'Save',
+ icon: 'ok',
+ cb: (instance) => {
+ instance.xos = xos;
+ instance.slice = this.localSlice.id;
+ instance.creator = this.user.id;
+ LocalInstances.createOnLocal(instance)
+ .then(res => {
+ slice.instance_total = slice.instance_total + 1;
+ $uibModalInstance.close();
+ });
+ },
+ class: 'success'
+ },
+ {
+ label: 'Cancel',
+ icon: 'remove',
+ cb: () => {
+ $uibModalInstance.dismiss('cancel');
+ },
+ class: 'warning'
+ }
+ ],
+ fields: {
+ xos: {
+ type: 'select',
+ validators: {
+ required: true
+ }
+ },
+ name: {
+ type: 'text',
+ validators: {
+ required: true
+ }
+ },
+ deployment: {
+ type: 'select',
+ validators: {
+ required: true
+ }
+ },
+ node: {
+ type: 'select',
+ validators: {
+ required: true
+ }
+ },
+ image: {
+ type: 'select',
+ validators: {
+ required: true,
+ }
+ },
+ flavor: {
+ type: 'select',
+ validators: {
+ required: true,
+ }
+ },
+ isolation: {
+ type: 'select',
+ options: [
+ {id: 'vm', label: 'VM'},
+ {id: 'container', label: 'Container'},
+ {id: 'container_vm', label: 'Container in VM'}
+ ],
+ validators: {
+ required: true,
+ }
+ },
+ }
+ };
+ },
+ controllerAs: 'vm',
+ resolve: {
+ slice: function () {
+ return item;
+ }
+ }
+ });
+ };
+
const baseSliceCols = [
{
label: 'Name',
prop: 'name',
},
- {
- label: 'Mount Data Sets',
- prop: 'mount_data_sets'
- }
+ // {
+ // label: 'Mount Data Sets',
+ // prop: 'mount_data_sets'
+ // }
];
const lXosSliceCols = [
@@ -77,58 +280,12 @@
{
label: 'Get Instances',
icon: 'search',
- cb: (item) => {
- $uibModal.open({
- animation: true,
- size: 'lg',
- templateUrl: 'listInstances.html',
- controllerAs: 'vm',
- resolve: {
- slice: function () {
- return {
- name: item.name,
- xos: {
- name: 'G-XOS'
- }
- };
- }
- },
- controller: function($uibModalInstance, slice, LocalInstances, LocalSlices) {
- this.slice = slice;
-
- this.config = {
- columns: [
- {
- label: 'Name',
- prop: 'name',
- }
- ]
- };
-
- LocalSlices.queryFromAll(self.xoss).$promise
- .then(slices => {
- // keep only the slice that match the name
- this.slicesId = slices
- .filter(s => s.name.indexOf(this.slice.name) > -1)
- .reduce((o, s) => {
- o[s.xos.id] = s.id;
- return o;
- }, {});
- return LocalInstances.queryFromAll(self.xoss).$promise;
- })
- .then(instances => {
- this.instances = instances.filter(i => this.slicesId[i.xos.id] === i.slice);
- })
- .catch(e => {
- this.instances = [];
- });
-
- this.close = () => {
- $uibModalInstance.dismiss('cancel');
- }
- }
- })
- }
+ cb: getGlobalInstances
+ },
+ {
+ label: 'Add Instances',
+ icon: 'plus',
+ cb: createGlobalInstance
},
]
};
@@ -195,7 +352,7 @@
this.slice = slice;
this.model = {};
-
+ console.log(slice);
LocalInstances.getLocalInfo(slice.xos)
.then((res) => {
[
@@ -216,7 +373,7 @@
cb: (instance) => {
instance.xos = slice.xos;
instance.slice = slice.id;
- instance.creator = instance.xos.user.id;
+ instance.creator = this.user.id;
LocalInstances.createOnLocal(instance)
.then(res => {
slice.instance_total = slice.instance_total + 1;
diff --git a/views/ngXosViews/globalXos/src/js/rest.js b/views/ngXosViews/globalXos/src/js/rest.js
index 012daa8..2ad47bc 100644
--- a/views/ngXosViews/globalXos/src/js/rest.js
+++ b/views/ngXosViews/globalXos/src/js/rest.js
@@ -94,15 +94,58 @@
});
return d.promise;
+ };
+
+ this.getUserByName = (xos, username) => {
+ const d = $q.defer();
+ console.log(username);
+ $http.get(`${xos.auth_url}api/core/users/`, {
+ params: {
+ username: username
+ },
+ headers: {
+ Authorization: `Basic ${btoa(xos.admin_user + ':' + xos.admin_password)}`
+ }
+ })
+ .then((res) => {
+ d.resolve(res.data[0]);
+ })
+ .catch(e => {
+ d.reject(e);
+ });
+
+ return d.promise;
}
})
- .service('LocalSlices', function(GXOS){
+ .service('LocalSlices', function($q, $http, GXOS){
const baseUrl = `api/utility/slicesplus/`;
// TODO build a global resource
this.queryFromAll = (targets) => {
return GXOS.buildQueryEndpoint(baseUrl, targets)();
};
+
+ this.getLocalByName = (xos, sliceName) => {
+ const d = $q.defer();
+
+ $http.get(`${xos.auth_url}${baseUrl}`, {
+ // params: params,
+ headers: {
+ Authorization: `Basic ${btoa(xos.admin_user + ':' + xos.admin_password)}`
+ }
+ })
+ .then((res) => {
+ const slice = _.filter(res.data, (s) => {
+ return s.name.indexOf(sliceName) > -1;
+ });
+ d.resolve(slice[0]);
+ })
+ .catch(e => {
+ d.reject(e);
+ });
+
+ return d.promise;
+ };
})
.service('LocalUsers', function(GXOS){
const baseUrl = `api/core/users/`;
@@ -155,6 +198,24 @@
return d.promise;
};
+ this.deleteFromLocal = (instance) => {
+ console.log('deleteFromLocal');
+ const d = $q.defer();
+ $http.delete(`${instance.xos.auth_url}${baseUrl}${instance.id}/`, {
+ headers: {
+ Authorization: `Basic ${btoa(instance.xos.admin_user + ':' + instance.xos.admin_password)}`
+ }
+ })
+ .then((inst) => {
+ d.resolve(inst.data);
+ })
+ .catch(e => {
+ d.reject(e);
+ });
+
+ return d.promise;
+ };
+
this.getLocalInfo = (xos) => {
const d = $q.defer();
$q.all([
diff --git a/xos/core/xoslib/static/js/xosGlobalXos.js b/xos/core/xoslib/static/js/xosGlobalXos.js
index e699684..e665832 100644
--- a/xos/core/xoslib/static/js/xosGlobalXos.js
+++ b/xos/core/xoslib/static/js/xosGlobalXos.js
@@ -1 +1 @@
-"use strict";var _slicedToArray=function(){function e(e,n){var o=[],t=!0,i=!1,s=void 0;try{for(var a,r=e[Symbol.iterator]();!(t=(a=r.next()).done)&&(o.push(a.value),!n||o.length!==n);t=!0);}catch(l){i=!0,s=l}finally{try{!t&&r["return"]&&r["return"]()}finally{if(i)throw s}}return o}return function(n,o){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,o);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();angular.module("xos.globalXos",["ngResource","ngCookies","ui.router","xos.helpers","ui.bootstrap.modal","ui.bootstrap.tpls"]).config(["$stateProvider",function(e){e.state("xos-list",{url:"/",template:"<xos-list></xos-list>"})}]).config(["$httpProvider",function(e){e.interceptors.push("NoHyperlinks")}]).value("LXOS",[]).directive("xosList",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"vm",templateUrl:"templates/xos-list.tpl.html",controller:["$window","$q","_","Controllers","LXOS","LocalAuth","LocalSlices","LocalUsers","$uibModal","Slices",function(e,n,o,t,i,s,a,r,l,c){var u=this,d=this;n.all([t.query({backend_type:"CORD"}).$promise,c.query().$promise]).then(function(e){var n=_slicedToArray(e,2);u.xoss=n[0],u.gSlices=n[1]}),this.openLocally=function(n){return function(o){e.open(o.xos.auth_url+"admin/core/"+n+"/"+o.id,"_blank")}};var m=[{label:"Name",prop:"name"},{label:"Mount Data Sets",prop:"mount_data_sets"}],f=[{label:"Max Instances",prop:"max_instances"},{label:"Instances",prop:"instance_total"},{label:"L-XOS",type:"custom",formatter:function(e){return e.xos.name}}];this.gSliceTableCgf={columns:m,filter:"field",order:!0,actions:[{label:"Get Instances",icon:"search",cb:function(e){l.open({animation:!0,size:"lg",templateUrl:"listInstances.html",controllerAs:"vm",resolve:{slice:function(){return{name:e.name,xos:{name:"G-XOS"}}}},controller:["$uibModalInstance","slice","LocalInstances","LocalSlices",function(e,n,o,t){var i=this;this.slice=n,this.config={columns:[{label:"Name",prop:"name"}]},t.queryFromAll(d.xoss).$promise.then(function(e){return i.slicesId=e.filter(function(e){return e.name.indexOf(i.slice.name)>-1}).reduce(function(e,n){return e[n.xos.id]=n.id,e},{}),o.queryFromAll(d.xoss).$promise}).then(function(e){i.instances=e.filter(function(e){return i.slicesId[e.xos.id]===e.slice})})["catch"](function(e){i.instances=[]}),this.close=function(){e.dismiss("cancel")}}]})}}]},this.sliceTableCfg={columns:m.concat(f),actions:[{label:"open locally",icon:"open",cb:this.openLocally("slice")},{label:"Get Instances",icon:"search",cb:function(e){l.open({animation:!0,size:"lg",templateUrl:"listInstances.html",controllerAs:"vm",resolve:{slice:function(){return e}},controller:["$uibModalInstance","slice","LocalInstances",function(e,n,o){var t=this;this.slice=n,this.config={columns:[{label:"Name",prop:"name"},{label:"deployment",prop:"deployment"}]},o.getFromLocal(n.xos).then(function(e){t.instances=e.filter(function(e){return e.slice===n.id})}),this.close=function(){e.dismiss("cancel")}}]})}},{label:"Add Instance",icon:"plus",cb:function(e){l.open({animation:!0,size:"lg",templateUrl:"addInstance.html",controller:["$uibModalInstance","slice","LocalInstances",function(e,n,o){var t=this;this.slice=n,this.model={},o.getLocalInfo(n.xos).then(function(e){var n=_slicedToArray(e,4);t.config.fields.deployment.options=n[0],t.config.fields.image.options=n[1],t.config.fields.flavor.options=n[2],t.config.fields.node.options=n[3]}),this.config={formName:"instanceForm",excludedFields:["xos","slice"],actions:[{label:"Save",icon:"ok",cb:function(t){t.xos=n.xos,t.slice=n.id,t.creator=t.xos.user.id,o.createOnLocal(t).then(function(o){n.instance_total=n.instance_total+1,e.close()})},"class":"success"},{label:"Cancel",icon:"remove",cb:function(){e.dismiss("cancel")},"class":"warning"}],fields:{name:{type:"text",validators:{required:!0}},deployment:{type:"select",validators:{required:!0}},node:{type:"select",validators:{required:!0}},image:{type:"select",validators:{required:!0}},flavor:{type:"select",validators:{required:!0}},isolation:{type:"select",options:[{id:"vm",label:"VM"},{id:"container",label:"Container"},{id:"container_vm",label:"Container in VM"}],validators:{required:!0}}}}}],controllerAs:"vm",resolve:{slice:function(){return e}}})}}],filter:"field",order:!0},this.usersTableCfg={columns:[{label:"Name",type:"custom",formatter:function(e){return e.firstname+" "+e.lastname}},{label:"E-Mail",prop:"email"},{label:"User Name",prop:"username"},{label:"Time Zone",prop:"timezone"},{label:"L-XOS",type:"custom",formatter:function(e){return e.xos.name}}],actions:[{label:"open locally",icon:"open",cb:this.openLocally("user")}],filter:"field",order:!0},this.toggleXos=function(e){o.findIndex(i,{id:e.id})>-1?(e.active=!1,o.remove(i,{id:e.id})):(e.active=!0,i.push(e)),s.login().then(function(){return n.all([a.queryFromAll().$promise,r.queryFromAll().$promise])}).then(function(e){var n=_slicedToArray(e,2);u.localSlices=n[0],u.localUsers=n[1]})["catch"](function(e){console.log(e)})}}]}}),angular.module("xos.globalXos").run(["$templateCache",function(e){e.put("templates/xos-list.tpl.html",'<div class="container">\n <div class="row">\n <h2>Select XOS to synch:</h2>\n </div>\n <div class="row">\n <div class="col-xs-12">\n <h2>G-XOS Slices:</h2>\n </div>\n <div class="col-xs-12">\n <xos-table\n config="vm.gSliceTableCgf"\n data="vm.gSlices">\n </xos-table>\n </div>\n </div>\n <div class="row">\n <div class="col-xs-12">\n <h2>Get L-XOS details:</h2>\n </div>\n <div\n ng-repeat="xos in vm.xoss"\n class="col-sm-2">\n <div\n class="well"\n ng-class="{active: xos.active}"\n ng-click="vm.toggleXos(xos)">\n {{xos.humanReadableName || xos.name}}\n </div>\n </div>\n </div>\n <div class="row" ng-if="vm.localSlices.length > 0">\n <div class="col-xs-12">\n <h2>L-XOS Slices:</h2>\n </div>\n <div class="col-xs-12">\n <xos-table\n config="vm.sliceTableCfg"\n data="vm.localSlices">\n </xos-table>\n </div>\n </div>\n <div class="row" ng-if="vm.localSlices.length > 0">\n <div class="col-xs-12">\n <h2>L-XOS Users:</h2>\n </div>\n <div class="col-xs-12">\n <xos-table\n config="vm.usersTableCfg"\n data="vm.localUsers">\n </xos-table>\n </div>\n </div>\n</div>\n<script type="text/ng-template" id="addInstance.html">\n <div class="modal-header">\n <h3 class="modal-title" id="modal-title">Add Instance to {{vm.slice.name}} on {{vm.slice.xos.name}}</h3>\n </div>\n <div class="modal-body" id="modal-body">\n <xos-form ng-model="vm.model" config="vm.config"></xos-form>\n </div>\n</script>\n<script type="text/ng-template" id="listInstances.html">\n <div class="modal-header">\n <h3 class="modal-title" id="modal-title">Get Instances from {{vm.slice.name}} on {{vm.slice.xos.name}}</h3>\n </div>\n <div class="modal-body" id="modal-body">\n <xos-table data="vm.instances" config="vm.config"></xos-table>\n </div>\n <div class="modal-footer">\n <a ng-click="vm.close()" class="btn btn-warning">Close</a>\n </div>\n</script>')}]),function(){angular.module("xos.globalXos").service("Controllers",["$resource",function(e){return e("/api/core/controllers/:id",{id:"@id"})}]).service("GXOS",["$q","$resource","_","LXOS",function(e,n,o,t){var i=this;this.attachXosToItem=function(e){var n=arguments.length<=1||void 0===arguments[1]?t:arguments[1];return o.map(e,function(e,t){var i=n[t];return o.map(e,function(e){return e.xos=i,e})})},this.buildQueryEndpoint=function(s){var a=arguments.length<=1||void 0===arguments[1]?t:arguments[1];return function(){var t=e.defer(),r=[],l=[];return o.forEach(a,function(e,o){var t=n(""+e.auth_url+s,{id:"@id"},{query:{isArray:!0,headers:{Authorization:"Basic "+btoa(e.admin_user+":"+e.admin_password)}}});r.push(t),l.push(r[o].query().$promise)}),e.all(l).then(function(e){e=i.attachXosToItem(e,a),t.resolve(o.flatten(e))})["catch"](t.reject),{$promise:t.promise}}},this.buildLocalResource=function(e,o){var t={Authorization:"Basic "+btoa(o.admin_user+":"+o.admin_password)},i=n(""+o.auth_url+e,{id:"@id"},{query:{isArray:!0,headers:t}});return i}}]).service("LocalAuth",["$q","$http","_","LXOS",function(e,n,o,t){var i="api/utility/login/";this.login=function(){var s=e.defer(),a=[];return o.forEach(t,function(e,o){var t=n.post(""+e.auth_url+i,{username:e.admin_user,password:e.admin_password});a.push(t)}),e.all(a).then(function(e){o.forEach(e,function(e,n){t[n].xoscsrftoken=e.data.xoscsrftoken,t[n].xossessionid=e.data.xossessionid,t[n].user=JSON.parse(e.data.user)}),s.resolve()})["catch"](function(e){s.reject(e)}),s.promise}}]).service("LocalSlices",["GXOS",function(e){var n="api/utility/slicesplus/";this.queryFromAll=function(o){return e.buildQueryEndpoint(n,o)()}}]).service("LocalUsers",["GXOS",function(e){var n="api/core/users/";this.queryFromAll=e.buildQueryEndpoint(n)}]).service("LocalInstances",["$q","$http","GXOS","LocalDeployments","LocalImages","LocalFlavor","LocalNode",function(e,n,o,t,i,s,a){var r="api/core/instances/";this.queryFromAll=function(e){return o.buildQueryEndpoint(r,e)()},this.createOnLocal=function(o){var t=e.defer(),i=o.xos;return delete o.xos,n.post(""+i.auth_url+r,o,{headers:{Authorization:"Basic "+btoa(i.admin_user+":"+i.admin_password)}}).then(function(e){t.resolve(e)})["catch"](function(e){t.reject(e)}),t.promise},this.getFromLocal=function(o,t){var i=e.defer();return n.get(""+o.auth_url+r,{params:t,headers:{Authorization:"Basic "+btoa(o.admin_user+":"+o.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise},this.getLocalInfo=function(n){var o=e.defer();return e.all([t.queryFromLocal(n),i.queryFromLocal(n),s.queryFromLocal(n),a.queryFromLocal(n)]).then(function(e){e=_.map(e,function(e){return _.map(e,function(e){return{id:e.id,label:e.name}})}),o.resolve(e)})["catch"](o.reject),o.promise}}]).service("LocalDeployments",["$q","$http",function(e,n){var o="api/core/deployments/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalImages",["$q","$http",function(e,n){var o="api/core/images/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalFlavor",["$q","$http",function(e,n){var o="api/core/flavors/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalNode",["$q","$http",function(e,n){var o="api/core/nodes/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}])}(),angular.module("xos.globalXos").run(["$location",function(e){e.path("/")}]);
\ No newline at end of file
+"use strict";var _slicedToArray=function(){function e(e,n){var o=[],t=!0,i=!1,a=void 0;try{for(var s,r=e[Symbol.iterator]();!(t=(s=r.next()).done)&&(o.push(s.value),!n||o.length!==n);t=!0);}catch(l){i=!0,a=l}finally{try{!t&&r["return"]&&r["return"]()}finally{if(i)throw a}}return o}return function(n,o){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,o);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();angular.module("xos.globalXos",["ngResource","ngCookies","ui.router","xos.helpers","ui.bootstrap.modal","ui.bootstrap.tpls"]).config(["$stateProvider",function(e){e.state("xos-list",{url:"/",template:"<xos-list></xos-list>"})}]).config(["$httpProvider",function(e){e.interceptors.push("NoHyperlinks")}]).value("LXOS",[]).directive("xosList",function(){return{restrict:"E",scope:{},bindToController:!0,controllerAs:"vm",templateUrl:"templates/xos-list.tpl.html",controller:["$window","$q","_","Controllers","LXOS","LocalAuth","LocalSlices","LocalUsers","$uibModal","Slices",function(e,n,o,t,i,a,s,r,l,c){var u=this,d=this;n.all([t.query({backend_type:"CORD"}).$promise,c.query().$promise]).then(function(e){var n=_slicedToArray(e,2);u.xoss=n[0],u.gSlices=n[1]}),this.openLocally=function(n){return function(o){e.open(o.xos.auth_url+"admin/core/"+n+"/"+o.id,"_blank")}};var m=function(e){l.open({animation:!0,size:"lg",templateUrl:"listInstances.html",controllerAs:"vm",resolve:{slice:function(){return{name:e.name,xos:{name:"G-XOS"}}}},controller:["$uibModalInstance","slice","LocalInstances","LocalSlices",function(e,n,t,i){var a=this;this.slice=n,this.config={columns:[{label:"Name",prop:"name"}],actions:[{label:"Add Instance",icon:"remove",color:"red",cb:function(e){console.log(e),t.deleteFromLocal(e).then(function(){o.remove(a.instances,function(n){return n.id===e.id})})}}]},i.queryFromAll(d.xoss).$promise.then(function(e){return a.slicesId=e.filter(function(e){return e.name.indexOf(a.slice.name)>-1}).reduce(function(e,n){return e[n.xos.id]=n.id,e},{}),t.queryFromAll(d.xoss).$promise}).then(function(e){a.instances=e.filter(function(e){return a.slicesId[e.xos.id]===e.slice})})["catch"](function(e){a.instances=[]}),this.close=function(){e.dismiss("cancel")}}]})},f=function(e){l.open({animation:!0,size:"lg",templateUrl:"addInstance.html",controller:["$scope","$q","$uibModalInstance","slice","LocalInstances","LocalAuth",function(e,n,i,a,r,l){var c=this;this.slice=a,this.model={};var u=void 0;t.query({backend_type:"CORD"}).$promise.then(function(e){c.xoss=e,c.config.fields.xos.options=o.map(e,function(e){return{id:e.id,label:e.name}})}),e.$watch(function(){return c.model.xos},function(){c.model.xos&&(u=o.find(c.xoss,{id:c.model.xos}),r.getLocalInfo(u).then(function(e){var o=_slicedToArray(e,4);return c.config.fields.deployment.options=o[0],c.config.fields.image.options=o[1],c.config.fields.flavor.options=o[2],c.config.fields.node.options=o[3],n.all([s.getLocalByName(u,c.slice.name),l.getUserByName(u,u.admin_user)])}).then(function(e){console.log("aaaa: ",e);var n=_slicedToArray(e,2);c.localSlice=n[0],c.user=n[1]}))}),this.config={formName:"instanceForm",order:["xos","name"],excludedFields:["xos","slice"],actions:[{label:"Save",icon:"ok",cb:function(e){e.xos=u,e.slice=c.localSlice.id,e.creator=c.user.id,r.createOnLocal(e).then(function(e){a.instance_total=a.instance_total+1,i.close()})},"class":"success"},{label:"Cancel",icon:"remove",cb:function(){i.dismiss("cancel")},"class":"warning"}],fields:{xos:{type:"select",validators:{required:!0}},name:{type:"text",validators:{required:!0}},deployment:{type:"select",validators:{required:!0}},node:{type:"select",validators:{required:!0}},image:{type:"select",validators:{required:!0}},flavor:{type:"select",validators:{required:!0}},isolation:{type:"select",options:[{id:"vm",label:"VM"},{id:"container",label:"Container"},{id:"container_vm",label:"Container in VM"}],validators:{required:!0}}}}}],controllerAs:"vm",resolve:{slice:function(){return e}}})},h=[{label:"Name",prop:"name"}],v=[{label:"Max Instances",prop:"max_instances"},{label:"Instances",prop:"instance_total"},{label:"L-XOS",type:"custom",formatter:function(e){return e.xos.name}}];this.gSliceTableCgf={columns:h,filter:"field",order:!0,actions:[{label:"Get Instances",icon:"search",cb:m},{label:"Add Instances",icon:"plus",cb:f}]},this.sliceTableCfg={columns:h.concat(v),actions:[{label:"open locally",icon:"open",cb:this.openLocally("slice")},{label:"Get Instances",icon:"search",cb:function(e){l.open({animation:!0,size:"lg",templateUrl:"listInstances.html",controllerAs:"vm",resolve:{slice:function(){return e}},controller:["$uibModalInstance","slice","LocalInstances",function(e,n,o){var t=this;this.slice=n,this.config={columns:[{label:"Name",prop:"name"},{label:"deployment",prop:"deployment"}]},o.getFromLocal(n.xos).then(function(e){t.instances=e.filter(function(e){return e.slice===n.id})}),this.close=function(){e.dismiss("cancel")}}]})}},{label:"Add Instance",icon:"plus",cb:function(e){l.open({animation:!0,size:"lg",templateUrl:"addInstance.html",controller:["$uibModalInstance","slice","LocalInstances",function(e,n,o){var t=this;this.slice=n,this.model={},console.log(n),o.getLocalInfo(n.xos).then(function(e){var n=_slicedToArray(e,4);t.config.fields.deployment.options=n[0],t.config.fields.image.options=n[1],t.config.fields.flavor.options=n[2],t.config.fields.node.options=n[3]}),this.config={formName:"instanceForm",excludedFields:["xos","slice"],actions:[{label:"Save",icon:"ok",cb:function(i){i.xos=n.xos,i.slice=n.id,i.creator=t.user.id,o.createOnLocal(i).then(function(o){n.instance_total=n.instance_total+1,e.close()})},"class":"success"},{label:"Cancel",icon:"remove",cb:function(){e.dismiss("cancel")},"class":"warning"}],fields:{name:{type:"text",validators:{required:!0}},deployment:{type:"select",validators:{required:!0}},node:{type:"select",validators:{required:!0}},image:{type:"select",validators:{required:!0}},flavor:{type:"select",validators:{required:!0}},isolation:{type:"select",options:[{id:"vm",label:"VM"},{id:"container",label:"Container"},{id:"container_vm",label:"Container in VM"}],validators:{required:!0}}}}}],controllerAs:"vm",resolve:{slice:function(){return e}}})}}],filter:"field",order:!0},this.usersTableCfg={columns:[{label:"Name",type:"custom",formatter:function(e){return e.firstname+" "+e.lastname}},{label:"E-Mail",prop:"email"},{label:"User Name",prop:"username"},{label:"Time Zone",prop:"timezone"},{label:"L-XOS",type:"custom",formatter:function(e){return e.xos.name}}],actions:[{label:"open locally",icon:"open",cb:this.openLocally("user")}],filter:"field",order:!0},this.toggleXos=function(e){o.findIndex(i,{id:e.id})>-1?(e.active=!1,o.remove(i,{id:e.id})):(e.active=!0,i.push(e)),a.login().then(function(){return n.all([s.queryFromAll().$promise,r.queryFromAll().$promise])}).then(function(e){var n=_slicedToArray(e,2);u.localSlices=n[0],u.localUsers=n[1]})["catch"](function(e){console.log(e)})}}]}}),angular.module("xos.globalXos").run(["$templateCache",function(e){e.put("templates/xos-list.tpl.html",'<div class="container">\n <div class="row">\n <h2>Select XOS to synch:</h2>\n </div>\n <div class="row">\n <div class="col-xs-12">\n <h2>G-XOS Slices:</h2>\n </div>\n <div class="col-xs-12">\n <xos-table\n config="vm.gSliceTableCgf"\n data="vm.gSlices">\n </xos-table>\n </div>\n </div>\n <div class="row">\n <div class="col-xs-12">\n <h2>Get L-XOS details:</h2>\n </div>\n <div\n ng-repeat="xos in vm.xoss"\n class="col-sm-2">\n <div\n class="well"\n ng-class="{active: xos.active}"\n ng-click="vm.toggleXos(xos)">\n {{xos.humanReadableName || xos.name}}\n </div>\n </div>\n </div>\n <div class="row" ng-if="vm.localSlices.length > 0">\n <div class="col-xs-12">\n <h2>L-XOS Slices:</h2>\n </div>\n <div class="col-xs-12">\n <xos-table\n config="vm.sliceTableCfg"\n data="vm.localSlices">\n </xos-table>\n </div>\n </div>\n <div class="row" ng-if="vm.localSlices.length > 0">\n <div class="col-xs-12">\n <h2>L-XOS Users:</h2>\n </div>\n <div class="col-xs-12">\n <xos-table\n config="vm.usersTableCfg"\n data="vm.localUsers">\n </xos-table>\n </div>\n </div>\n</div>\n<script type="text/ng-template" id="addInstance.html">\n <div class="modal-header">\n <h3 class="modal-title" id="modal-title">Add Instance to {{vm.slice.name}} on {{vm.slice.xos.name}}</h3>\n </div>\n <div class="modal-body" id="modal-body">\n <xos-form ng-model="vm.model" config="vm.config"></xos-form>\n </div>\n</script>\n<script type="text/ng-template" id="listInstances.html">\n <div class="modal-header">\n <h3 class="modal-title" id="modal-title">Get Instances from {{vm.slice.name}} on {{vm.slice.xos.name}}</h3>\n </div>\n <div class="modal-body" id="modal-body">\n <xos-table data="vm.instances" config="vm.config"></xos-table>\n </div>\n <div class="modal-footer">\n <a ng-click="vm.close()" class="btn btn-warning">Close</a>\n </div>\n</script>')}]),function(){angular.module("xos.globalXos").service("Controllers",["$resource",function(e){return e("/api/core/controllers/:id",{id:"@id"})}]).service("GXOS",["$q","$resource","_","LXOS",function(e,n,o,t){var i=this;this.attachXosToItem=function(e){var n=arguments.length<=1||void 0===arguments[1]?t:arguments[1];return o.map(e,function(e,t){var i=n[t];return o.map(e,function(e){return e.xos=i,e})})},this.buildQueryEndpoint=function(a){var s=arguments.length<=1||void 0===arguments[1]?t:arguments[1];return function(){var t=e.defer(),r=[],l=[];return o.forEach(s,function(e,o){var t=n(""+e.auth_url+a,{id:"@id"},{query:{isArray:!0,headers:{Authorization:"Basic "+btoa(e.admin_user+":"+e.admin_password)}}});r.push(t),l.push(r[o].query().$promise)}),e.all(l).then(function(e){e=i.attachXosToItem(e,s),t.resolve(o.flatten(e))})["catch"](t.reject),{$promise:t.promise}}},this.buildLocalResource=function(e,o){var t={Authorization:"Basic "+btoa(o.admin_user+":"+o.admin_password)},i=n(""+o.auth_url+e,{id:"@id"},{query:{isArray:!0,headers:t}});return i}}]).service("LocalAuth",["$q","$http","_","LXOS",function(e,n,o,t){var i="api/utility/login/";this.login=function(){var a=e.defer(),s=[];return o.forEach(t,function(e,o){var t=n.post(""+e.auth_url+i,{username:e.admin_user,password:e.admin_password});s.push(t)}),e.all(s).then(function(e){o.forEach(e,function(e,n){t[n].xoscsrftoken=e.data.xoscsrftoken,t[n].xossessionid=e.data.xossessionid,t[n].user=JSON.parse(e.data.user)}),a.resolve()})["catch"](function(e){a.reject(e)}),a.promise},this.getUserByName=function(o,t){var i=e.defer();return console.log(t),n.get(o.auth_url+"api/core/users/",{params:{username:t},headers:{Authorization:"Basic "+btoa(o.admin_user+":"+o.admin_password)}}).then(function(e){i.resolve(e.data[0])})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalSlices",["$q","$http","GXOS",function(e,n,o){var t="api/utility/slicesplus/";this.queryFromAll=function(e){return o.buildQueryEndpoint(t,e)()},this.getLocalByName=function(o,i){var a=e.defer();return n.get(""+o.auth_url+t,{headers:{Authorization:"Basic "+btoa(o.admin_user+":"+o.admin_password)}}).then(function(e){var n=_.filter(e.data,function(e){return e.name.indexOf(i)>-1});a.resolve(n[0])})["catch"](function(e){a.reject(e)}),a.promise}}]).service("LocalUsers",["GXOS",function(e){var n="api/core/users/";this.queryFromAll=e.buildQueryEndpoint(n)}]).service("LocalInstances",["$q","$http","GXOS","LocalDeployments","LocalImages","LocalFlavor","LocalNode",function(e,n,o,t,i,a,s){var r="api/core/instances/";this.queryFromAll=function(e){return o.buildQueryEndpoint(r,e)()},this.createOnLocal=function(o){var t=e.defer(),i=o.xos;return delete o.xos,n.post(""+i.auth_url+r,o,{headers:{Authorization:"Basic "+btoa(i.admin_user+":"+i.admin_password)}}).then(function(e){t.resolve(e)})["catch"](function(e){t.reject(e)}),t.promise},this.getFromLocal=function(o,t){var i=e.defer();return n.get(""+o.auth_url+r,{params:t,headers:{Authorization:"Basic "+btoa(o.admin_user+":"+o.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise},this.deleteFromLocal=function(o){console.log("deleteFromLocal");var t=e.defer();return n["delete"](""+o.xos.auth_url+r+o.id+"/",{headers:{Authorization:"Basic "+btoa(o.xos.admin_user+":"+o.xos.admin_password)}}).then(function(e){t.resolve(e.data)})["catch"](function(e){t.reject(e)}),t.promise},this.getLocalInfo=function(n){var o=e.defer();return e.all([t.queryFromLocal(n),i.queryFromLocal(n),a.queryFromLocal(n),s.queryFromLocal(n)]).then(function(e){e=_.map(e,function(e){return _.map(e,function(e){return{id:e.id,label:e.name}})}),o.resolve(e)})["catch"](o.reject),o.promise}}]).service("LocalDeployments",["$q","$http",function(e,n){var o="api/core/deployments/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalImages",["$q","$http",function(e,n){var o="api/core/images/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalFlavor",["$q","$http",function(e,n){var o="api/core/flavors/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}]).service("LocalNode",["$q","$http",function(e,n){var o="api/core/nodes/";this.queryFromLocal=function(t){var i=e.defer();return n.get(""+t.auth_url+o,{headers:{Authorization:"Basic "+btoa(t.admin_user+":"+t.admin_password)}}).then(function(e){i.resolve(e.data)})["catch"](function(e){i.reject(e)}),i.promise}}])}(),angular.module("xos.globalXos").run(["$location",function(e){e.path("/")}]);
\ No newline at end of file