Skip to content

Commit

Permalink
Merge pull request #82 from nbesimi/feature/container-type
Browse files Browse the repository at this point in the history
Implement Container Type on Create
  • Loading branch information
ailegion authored Apr 6, 2018
2 parents 5245698 + 2f71144 commit 865fe73
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/__metadata__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME = 'LXDUI'
APP_CLI_CMD = 'lui'
VERSION = '2.0'
VERSION = '2.0-beta'
GIT_URL = 'https://github.com/AdaptiveScale/lxdui.git'
LXD_URL = 'http://localhost:8443'
LICENSE = 'Apache 2.0'
Expand Down
3 changes: 3 additions & 0 deletions app/api/controllers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ def startContainer(name):
def stopContainer(name):
try:
container = LXCContainer({'name': name})
ephemeral = container.info()['ephemeral']
container.stop()
if ephemeral:
return response.replySuccess(data={}, message='success')
return response.replySuccess(container.info())
except ValueError as e:
return response.replyFailed(message=e.__str__())
Expand Down
14 changes: 13 additions & 1 deletion app/api/models/LXCContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def __init__(self, input):
else:
self.setBootType(True)

if input.get('stateful') != None:
self.setEphemeral(not input.get('stateful'))
else:
self.setEphemeral(False)


def setImageType(self, input):
# Detect image type (alias or fingerprint)
Expand Down Expand Up @@ -99,6 +104,10 @@ def setBootType(self, input):
self.initConfig()
self.data['config']['boot.autostart'] = '1' if input else '0'

def setEphemeral(self, input):
self.initConfig()
self.data['ephemeral'] = input

def info(self):
try:
c = self.client.containers.get(self.data.get('name'))
Expand Down Expand Up @@ -126,7 +135,10 @@ def create(self, waitIt=True):
def delete(self, force=False):
try:
container = self.client.containers.get(self.data.get('name'))
if force and self.info().get('status') == 'Running':
if self.info().get('ephemeral'):
container.stop(wait=True)
return
elif force and self.info().get('status') == 'Running':
container.stop(wait=True)
container.delete()
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion app/ui/static/js/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ App.containers = App.containers || {
tableSettings: {
rowId:'name',
searching:true,
responsive: true,
responsive: false,
select: true,
columnDefs: [
{
Expand Down
2 changes: 1 addition & 1 deletion app/ui/static/js/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ App.images = App.images || {
specs['cpu']['hardLimitation']=Boolean(specs['cpu']['hardLimitation']) || false;
specs['memory']['sizeInMB']=Number(specs['memory']['sizeInMB']);
specs['memory']['hardLimitation']=Boolean(specs['memory']['hardLimitation']) || false;
specs['stateful']=Boolean(specs['stateful']) || true;
specs['stateful']=Boolean(specs['stateful']);
specs['autostart']=Boolean(specs['autostart']);
if($('#'+specs.image+'_profiles').val()){
specs['profiles'] = $('#'+specs.image+'_profiles').val();
Expand Down
11 changes: 11 additions & 0 deletions app/ui/templates/container-details.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<div class="col-lg-12 main-div">
{% if container == None %}
<div class="alert alert-danger" role="alert"> CONTAINER <b>{{name}}</b> : {{message}} !</div>
<script>
window.location = '/ui/containers';
</script>
{% else %}
<script>
$(function () {
Expand Down Expand Up @@ -43,6 +46,14 @@ <h5 style="display:inline">Currently Running Processes :</h5>
</div>
{% endif %}
</div>
<div class="form-group">
<h5 style="display:inline">Type :</h5>
{% if container.ephemeral %}
<b>Ephemeral</b>
{% else %}
<b>Persistent</b>
{% endif %}
</div>
<div class="form-group">
<h5 style="display:inline">Architecture :</h5>
<b>{{container.architecture}}</b>
Expand Down
8 changes: 7 additions & 1 deletion app/ui/templates/containers.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<th>Name</th>
<th>Status</th>
<th>IP Address</th>
<th>Type</th>
<th>OS image</th>
<th>Created On</th>
<th>Actions</th>
Expand All @@ -56,6 +57,11 @@
{% else %}
<td>N/A</td>
{% endif %}
{% if container.ephemeral %}
<td>Ephemeral</td>
{% else %}
<td>Persistent</td>
{% endif %}
<td>{{container.config['image.distribution']}} {{container.config['image.release']}} {{container.config['image.architecture']}}</td>
<td>{{container.created_at}}</td>
<td style="width:157px !important;">
Expand Down Expand Up @@ -107,7 +113,7 @@
</div>
</div>
<div class="form-group">
<label class="form-check-label col-md-2 control-label" for="containerStateful">Stateful</label>
<label class="form-check-label col-md-2 control-label" for="containerStateful">Persistent</label>
<div class="col-md-3">
<input type="checkbox" class="form-check-input" id="containerStateful" name="stateful" checked value="true">
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/ui/templates/images.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ <h4 class="panel-title">
<div class="form-group">
<label class="col-sm-4 control-label">Container Name</label>
<label class="col-sm-2 control-label">Number</label>
<label class="col-sm-2 form-check-label">Stateful</label>
<label class="col-sm-2 form-check-label">Persistent</label>
<label class="col-sm-2 form-check-label">Autostart</label>
<div class="clearfix"></div>
<div class="col-sm-4">
Expand Down

0 comments on commit 865fe73

Please sign in to comment.