From a9b6e5a1cd346eab52d0d993cf47e09a1b7c4dd2 Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Thu, 18 Dec 2014 15:46:04 -0700 Subject: [PATCH] TTY, LXC, Memory options on container create --- app/pods/hosts/container-new/controller.js | 67 ++++++++++++++++++++- app/pods/hosts/container-new/template.hbs | 69 +++++++++++++++------- app/pods/hosts/container-new/view.js | 30 +++++++++- app/pods/hosts/item/template.hbs | 2 +- app/styles/bootstrap-tweak.scss | 4 ++ app/templates/container/edit-lxc.hbs | 40 +++++++++++++ package.json | 2 +- 7 files changed, 187 insertions(+), 27 deletions(-) create mode 100644 app/templates/container/edit-lxc.hbs diff --git a/app/pods/hosts/container-new/controller.js b/app/pods/hosts/container-new/controller.js index 309d274d5..faf9e0644 100644 --- a/app/pods/hosts/container-new/controller.js +++ b/app/pods/hosts/container-new/controller.js @@ -65,6 +65,13 @@ export default Ember.ObjectController.extend(NewOrEditContainer, { removeDnsSearch: function(obj) { this.get('dnsSearchArray').removeObject(obj); }, + + addLxc: function() { + this.get('lxcArray').pushObject({key: '', value: ''}); + }, + removeLxc: function(obj) { + this.get('lxcArray').removeObject(obj); + }, }, validate: function() { @@ -85,6 +92,7 @@ export default Ember.ObjectController.extend(NewOrEditContainer, { this.initDns(); this.initDnsSearch(); this.initCapability(); + this.initLxc(); this.userImageUuidDidChange(); }, @@ -112,7 +120,7 @@ export default Ember.ObjectController.extend(NewOrEditContainer, { // Environment Vars environmentArray: null, initEnvironment: function() { - var obj = this.get('environment')||[]; + var obj = this.get('environment')||{}; var keys = Object.keys(obj); var out = []; keys.forEach(function(key) { @@ -324,4 +332,61 @@ export default Ember.ObjectController.extend(NewOrEditContainer, { this.set('capAdd',[]); this.set('capDrop',[]); }, + + // Memory + memoryDidChange: function() { + // The actual parameter we're interested in is 'memorySwap', in bytes. + var mem = parseInt(this.get('memoryMb'),10); + if ( isNaN(mem) ) + { + this.set('memoryMb',''); + this.set('memorySwap',null); + } + else + { + this.set('memorySwap', mem * 1024 * 1024); + } + }.observes('memoryMb'), + + // Terminal + terminal: 'both', + terminalChoices: [ + {label: 'Yes (-i and -t)', value: 'both'}, + {label: 'Interactive (-i)', value: 'interactive'}, + {label: 'TTY (-t)', value: 'terminal'}, + {label: 'No', value: 'none'}, + ], + terminalDidChange: function() { + var val = this.get('terminal'); + var stdinOpen = ( val === 'interactive' || val === 'both' ); + var tty = (val === 'tty' || val === 'both'); + this.set('tty', tty); + this.set('stdinOpen', stdinOpen); + }.observes('terminal'), + + // LXC Config + lxcArray: null, + initLxc: function() { + var obj = this.get('lxcConf')||{}; + var keys = Object.keys(obj); + var out = []; + keys.forEach(function(key) { + out.push({ key: key, value: obj[key] }); + }); + + this.set('lxcArray', out); + }, + + lxcChanged: function() { + // Sync with the actual environment object + var out = {}; + this.get('lxcArray').forEach(function(row) { + if ( row.key ) + { + out[row.key] = row.value; + } + }); + this.set('lxcConf', out); + }.observes('lxcArray.@each.{key,value}'), + }); diff --git a/app/pods/hosts/container-new/template.hbs b/app/pods/hosts/container-new/template.hbs index 6ad44dcc0..56879c505 100644 --- a/app/pods/hosts/container-new/template.hbs +++ b/app/pods/hosts/container-new/template.hbs @@ -11,14 +11,14 @@
- + {{! @TODO: department of redundancy department }} The Basics Ports Command Links Volumes DNS - Security + Security/Host
@@ -27,7 +27,7 @@
- {{input id="name" type="text" value=name classNames="form-control" placeholder="e.g. web01"}} + {{input id="name" type="text" value=name classNames="form-control" placeholder="e.g. app01"}}
@@ -38,11 +38,22 @@
{{partial "container/edit-image"}} +
+ + {{view "select" + class="form-control" + id="terminal" + content=terminalChoices + optionLabelPath="content.label" + optionValuePath="content.value" + value=terminal + }} +
+
{{view "select" class="form-control" - disabled=editing id="networkId" content=networks optionLabelPath="content.displayName" @@ -95,34 +106,48 @@
- +
+ +
+ {{input id="memoryMb" type="number" min="1" step="1" value=memoryMb classNames="form-control" placeholder="No limit"}} +
MB
+
+
+ +
+ + {{input id="cpuSet" type="text" value=cpuSet classNames="form-control" placeholder="e.g. 0,1,3"}} +
+ +
+
+
-
-
+
- - {{input id="cpuSet" type="text" value=cpuSet classNames="form-control" placeholder="e.g. 0,1,3"}} + + {{view "select" class="form-control select-cap-add" content=capabilityChoices selection=capAdd multiple="true" optionValuePath="content" optionLabelPath="content"}}
+ +
+ + {{view "select" class="form-control select-cap-drop" content=capabilityChoices selection=capDrop multiple="true" optionValuePath="content" optionLabelPath="content"}} +
+ + + Capabilities allow you to provide fine-grained control over superuser privileges available to the container. + More information +

- -
-
- - {{view "select" class="form-control select-cap-add" content=capabilityChoices selection=capAdd multiple="true" optionValuePath="content" optionLabelPath="content"}} -
-
- - {{view "select" class="form-control select-cap-drop" content=capabilityChoices selection=capDrop multiple="true" optionValuePath="content" optionLabelPath="content"}} -
-
+ {{partial "container/edit-lxc"}} - Capabilities allow you to provide fine-grained control over superuser privileges available to the container. - More information + This allows you to directly set or override any low-level options for the container. Do not include the leading "lxc." + More information
diff --git a/app/pods/hosts/container-new/view.js b/app/pods/hosts/container-new/view.js index 6399d4d8c..a08fcfaa0 100644 --- a/app/pods/hosts/container-new/view.js +++ b/app/pods/hosts/container-new/view.js @@ -69,6 +69,14 @@ export default OverlayEdit.extend({ }); }, + addLxc: function() { + var self = this; + this.controller.send('addLxc'); + Ember.run.next(function() { + self.$('.lxc-key').last().focus(); + }); + }, + selectTab: function(name) { this.set('context.tab',name); this.$('.tab').removeClass('active'); @@ -86,7 +94,7 @@ export default OverlayEdit.extend({ var opts = { maxHeight: 200, - buttonClass: 'btn btn-default btn-sm', + buttonClass: 'btn btn-default', buttonWidth: '100%', numberDisplayed: 2, @@ -134,5 +142,23 @@ export default OverlayEdit.extend({ this.$('.select-cap-add').multiselect(opts); this.$('.select-cap-drop').multiselect(opts); - } + }, + + priviligedDidChange: function() { + var add = this.$('.select-cap-add'); + var drop = this.$('.select-cap-drop'); + if ( add && drop ) + { + if ( this.get('controller.privileged') ) + { + add.multiselect('disable'); + drop.multiselect('disable'); + } + else + { + add.multiselect('enable'); + drop.multiselect('enable'); + } + } + }.observes('controller.privileged') }); diff --git a/app/pods/hosts/item/template.hbs b/app/pods/hosts/item/template.hbs index 5d704ba66..ed4299f1e 100644 --- a/app/pods/hosts/item/template.hbs +++ b/app/pods/hosts/item/template.hbs @@ -18,7 +18,7 @@
No containers yet.
{{/each}} -{{#link-to "hosts.containerNew" this.id tagName="div" classNames="add-to-host" tooltip="Create Container"}} +{{#link-to "hosts.containerNew" this.id (query-params tab="basic") tagName="div" classNames="add-to-host" tooltip="Create Container"}} diff --git a/app/styles/bootstrap-tweak.scss b/app/styles/bootstrap-tweak.scss index 9f453b58b..02666f680 100644 --- a/app/styles/bootstrap-tweak.scss +++ b/app/styles/bootstrap-tweak.scss @@ -110,3 +110,7 @@ HR { .block { display: block; } + +.input-group-addon { + padding: 10px; +} diff --git a/app/templates/container/edit-lxc.hbs b/app/templates/container/edit-lxc.hbs new file mode 100644 index 000000000..feb9b19d4 --- /dev/null +++ b/app/templates/container/edit-lxc.hbs @@ -0,0 +1,40 @@ + +{{#if lxcArray.length}} + + + + + + + + {{#each obj in lxcArray}} + + + + + + + + + + {{/each}} +
Key Value 
+ {{input class="form-control input-sm lxc-key" type="text" value=obj.key placeholder="e.g. aa_profile"}} + +

=

+
+ {{input class="form-control input-sm" type="text" value=obj.value placeholder="e.g. unconfined"}} + + + +
+{{else}} +
+ None +
+{{/if}} diff --git a/package.json b/package.json index 8cb62c907..ae2668679 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "0.7.0", + "version": "0.7.1", "private": true, "directories": { "doc": "doc",