Commit 1caf8013 by Szeberényi Imre

Merge branch 'ci-integration' into 'master'

Bugfix - JS

See merge request !12
parents 7739d371 bdb49d44
......@@ -1364,5 +1364,13 @@ textarea[name="new_members"] {
height: 18px;
margin-right: 8px;
}
#ace-meta-data {
position: absolute;
width: 95%;
height: 150px;
}
#ace-user-data {
position: absolute;
width: 95%;
height: 350px;
}
var Websock_native; // not sure
$(function() {
var meta_data = ace.edit('ace-meta-data', {
if ($("#ace-meta-data").length && $("#ace-user-data").length) {
var meta_data = ace.edit('ace-meta-data', {
mode: "ace/mode/yaml", useWorker: false,
selectionStyle: "text" });
var textarea_meta = $('textarea[name="ci_meta_data"]');
meta_data.getSession().setValue(textarea_meta.val())
meta_data.getSession().on("change", function () {
textarea_meta.val(meta_data.getSession().getValue());
});
var user_data = ace.edit('ace-user-data', {
mode: "ace/mode/yaml", useWorker: false,
selectionStyle: "text" });
var textarea_user = $('textarea[name="ci_user_data"]');
user_data.getSession().setValue(textarea_user.val())
user_data.getSession().on("change", function () {
textarea_user.val(user_data.getSession().getValue());
});
meta_data.session.setTabSize(4);
meta_data.session.setUseSoftTabs(true);
user_data.session.setTabSize(4);
user_data.session.setUseSoftTabs(true);
document.getElementById('ace-meta-data').style.fontSize='14px';
document.getElementById('ace-user-data').style.fontSize='14px';
/* */
$('#vm-details-cidata-save').click(function(e) {
$.ajax({
type: 'POST',
url: $(this).parents("form").prop('action'),
data: $('#resource-cidata-form').serialize(),
success: function(data, textStatus, xhr) {
if(data.success) {
$('a[href="#activity"]').trigger("click");
} else {
addMessage(data.messages.join("<br />"), "danger");
}
$("#vm-details-resources-save i").removeClass('fa-refresh fa-spin').addClass("fa-floppy-o");
},
error: function(xhr, textStatus, error) {
$("#vm-details-resources-save i").removeClass('fa-refresh fa-spin').addClass("fa-floppy-o");
if (xhr.status == 500) {
addMessage("500 Internal Server Error", "danger");
} else {
addMessage(xhr.status + " Unknown Error", "danger");
}
}
var textarea_meta = $('textarea[name="ci_meta_data"]');
meta_data.getSession().setValue(textarea_meta.val())
meta_data.getSession().on("change", function () {
textarea_meta.val(meta_data.getSession().getValue());
});
e.preventDefault()
})
var user_data = ace.edit('ace-user-data', {
mode: "ace/mode/yaml", useWorker: false,
selectionStyle: "text" });
var textarea_user = $('textarea[name="ci_user_data"]');
user_data.getSession().setValue(textarea_user.val())
user_data.getSession().on("change", function () {
textarea_user.val(user_data.getSession().getValue());
});
meta_data.session.setTabSize(4);
meta_data.session.setUseSoftTabs(true);
user_data.session.setTabSize(4);
user_data.session.setUseSoftTabs(true);
document.getElementById('ace-meta-data').style.fontSize='14px';
document.getElementById('ace-user-data').style.fontSize='14px';
/* */
$('#vm-details-cidata-save').click(function(e) {
$.ajax({
type: 'POST',
url: $(this).parents("form").prop('action'),
data: $('#resource-cidata-form').serialize(),
success: function(data, textStatus, xhr) {
if(data.success) {
$('a[href="#activity"]').trigger("click");
} else {
addMessage(data.messages.join("<br />"), "danger");
}
$("#vm-details-resources-save i").removeClass('fa-refresh fa-spin').addClass("fa-floppy-o");
},
error: function(xhr, textStatus, error) {
$("#vm-details-resources-save i").removeClass('fa-refresh fa-spin').addClass("fa-floppy-o");
if (xhr.status == 500) {
addMessage("500 Internal Server Error", "danger");
} else {
addMessage(xhr.status + " Unknown Error", "danger");
}
}
});
e.preventDefault()
})
}
/* save resources */
$('#vm-details-resources-save').click(function(e) {
var error = false;
......
......@@ -21,8 +21,13 @@
<li>{% trans "<code>net.vlans</code> - associated vlans: list of objects (name: vlan name, ipv4/ipv6: host ip in vlan)" %}</li>
<li>{% trans "<code>ssh.keys</code> - owner's ssh-keys dictionary: the key is the ssh-key's name" %}</li>
<li>{% trans "<code>ci.rndstr(len: int)</code> - function: make random string with 'len' charachters lenght" %}</li>
<li>{% trans "<code>ci.loadjson(url: str)</code> - load json object from remote url" %}</li>
</ul>
<p>{% trans "Filters: hash - sha512 hash method" %}</p>
<p>{% trans "Use this commands, to clean cloud-init setup (for save as template example):" %}</p>
<pre>
cloud-init clean
userdel -p -f cloud # delete default user</pre>
<b>Example:</b>
<pre>{% verbatim %}
#cloud-config
......@@ -39,7 +44,7 @@ users:
ssh_authorized_keys:
- {{ ssh.keys['my-key'] }}
{% for u in acl.operators %}
- name: {{i}}
- name: {{u}}
shell: /bin/bash
{% endfor %}
{% endverbatim %}</pre>
......
......@@ -26,6 +26,7 @@
{{ form.req_traits|as_crispy_field }}
{{ form.description|as_crispy_field }}
{{ form.system|as_crispy_field }}
{{ form.has_agent|as_crispy_field }}
<hr/>
{% include "dashboard/_ci-data-help.html" %}
<div class="alert alert-warning">
......
......@@ -43,7 +43,7 @@ import jinja2
from passlib.hash import sha512_crypt
import yaml
import re
import urllib3, json
from model_utils import Choices
from model_utils.managers import QueryManager
......@@ -80,13 +80,14 @@ ACCESS_METHODS = [(key, name) for key, (name, port, transport)
CI_META_DATA_DEF = """
instance-id: {{ hostname }}
local-hostname: {{ hostname }}
cloud-name: circle3
platform: circle3
""".strip()
CI_USER_DATA_DEF = """
#cloud-config
users:
- default
- name: {{ sysuser }}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
......@@ -158,7 +159,7 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
help_text=(_('Name of operating system in format like '
'"Ubuntu 12.04 LTS Desktop amd64".')))
tags = TaggableManager(blank=True, verbose_name=_("tags"))
has_agent = BooleanField(verbose_name=_('has agent'), default=True,
has_agent = BooleanField(verbose_name=_('has agent'), default=False,
help_text=_(
'If the machine has agent installed, and '
'the manager should wait for its start.'))
......@@ -259,6 +260,14 @@ class CITemplate:
def rndstr(self, len):
return ''.join(random.choice(string.ascii_letters) for i in range(int(len)))
def jsonload(self, url):
http = urllib3.PoolManager()
r = http.request('GET', url)
if r.status != 200:
raise forms.ValidationError(f'Status code: {r.status}')
myjson = r.data.decode('utf8')
return json.loads(myjson)
def j2_hash(value, hash='sha512'):
return sha512_crypt.hash(value)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment