Commit 1e204ec1 by Szabolcs Gelencser

Implement some network creation and details

parent feb51452
No preview for this file type
......@@ -267,10 +267,10 @@ PIPELINE = {
),
"output_filename": "editor.js",
},
"new-network": {"source_filenames": (
"vue": {"source_filenames": (
"vue/dist/vue.js",
),
"output_filename": "new-network.js",
"output_filename": "vue.js",
},
},
}
......
......@@ -1022,11 +1022,17 @@ class VmPlainImageCreate(LoginRequiredMixin, TemplateView):
return self.render_to_response(context)
def post(self, request, *args, **kwargs):
#TODO: if there is a network available use it, of there isn't use none
# there could be some checkboxes for the user to decide
# could create default network, setup internet access
server_created = openstack_api.nova.server_create(
request,
request.POST.get("name"),
request.POST.get("image"),
request.POST.get("flavor"),
# nics=({
# 'uuid': 'fc7ba14c-53d8-4810-9030-a0f00985c036'
# })
)
return HttpResponseRedirect("vm/%s#activity" % server_created.id)
......
......@@ -381,5 +381,6 @@ class VxlanForm(forms.Form):
}))
networkAddress = forms.CharField(required=False)
isDhcpEnabled = forms.BooleanField(required=False)
isAdvancedConfig = forms.BooleanField(required=False)
#TODO: validate
......@@ -19,13 +19,13 @@
{{ form.name|as_crispy_field }}
{% verbatim %}
<div id="vuepart" v-bind:class="{ well: isAdvancedConfig }">
<input v-model="isAdvancedConfig" type="checkbox"> Advanced configuration
<input name="isAdvancedConfig" v-model="isAdvancedConfig" type="checkbox"> Advanced configuration
<div v-cloak v-if="isAdvancedConfig">
<div class="form-group">
<label for="id_network_address"> Network address <i class="asteriskField">*</i></label>
<input type="text" name="name" required class="form-control textinput textInput form-control" id="id_network_address">
<input name="isDhcpEnabled" type="checkbox"> Enable DHCP
<input name="isDhcpEnabled" type="checkbox" v-model="isDhcpEnabled"> Enable DHCP
</div>
</div>
</div>
......@@ -38,13 +38,14 @@
{% endblock %}
{% block extra_js %}
{% javascript 'new-network' %}
{% javascript 'vue' %}
<script>
var app = new Vue({
el: '#vuepart',
data: {
isAdvancedConfig: false
isAdvancedConfig: false,
isDhcpEnabled: true
}
})
</script>
......
......@@ -8,19 +8,39 @@
{% block title-page %}{{ form.name.value }} | {% trans "vxlan" %}{% endblock %}
{% block content %}
{% if isMultipleSubnetsAvailable %}
<div class="alert alert-warning alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Warning!</strong> Selecting a default subnet for network but there are more than one subnets available.
This network might have been created outside of CIRCLE and might not work as expected!
{#TODO: users should use default subnet here (or merge subnets?)#}
</div>
{% endif %}
{% if isSubnetMissing %}
<div class="alert alert-danger alert-dismissible">
<strong>Error!</strong> There must be at least one subnet allocated for network!
This network might have been created outside of CIRCLE and might not work as expected!
Click <a href="">here</a> to allocate subnet for network.
{#TODO: implement. Could be a little more sophisticated?#}
</div>
{% endif %}
<div class="page-header">
<a href="{% url "network.vxlan-delete" pk=network.id %}" class="btn btn-danger pull-right"><i class="fa fa-times-circle"></i> {% trans "Delete this network" %}</a>
<h2>{{ form.name.value }} <small>{% trans "details of network" %}</small></h2>
<h2>{{ form.name.value }}</h2>
</div>
<div class="row">
<div class="col-sm-6">
{% crispy form %}
<h3><small>{% trans "Details of network" %}</small></h3>
{{ form.name|as_crispy_field }}
{{ form.networkAddress|as_crispy_field }}
{{ form.isDhcpEnabled|as_crispy_field }}
</div>
<div class="col-sm-6">
<div class="page-header">
<h3>{% trans "Connected virtual machines" %}</h3>
</div>
<h3 class="pull-right"><small>{% trans "connected virtual machines" %}</small></h3>
</div>
</div>
{% endblock %}
......@@ -974,12 +974,23 @@ class VxlanDetail(LoginRequiredMixin, SuccessMessageMixin, DetailView): #TODO: c
context_object_name = 'network'
def get_object(self, queryset=None):
return openstack_api.neutron.network_get(self.request, self.kwargs['pk'])
return openstack_api.neutron.network_get(self.request, self.kwargs['pk'], expand_subnet=True)
def get_context_data(self, **kwargs):
context = super(VxlanDetail, self).get_context_data(**kwargs)
subnet = self.object.subnets[0] if len(self.object.subnets) > 0 else None
form = VxlanForm(initial={
'name': self.object.name,
'networkAddress': subnet.cidr if subnet else None,
'isDhcpEnabled': subnet.enable_dhcp if subnet else False,
})
context['isMultipleSubnetsAvailable'] = len(self.object.subnets) > 1
context['isSubnetMissing'] = len(self.object.subnets) < 1
context['vm_list'] = () #SmallVmTable(self.object.vm_interface.all())
context['form'] = VxlanForm
context['form'] = form
return context
class VxlanCreate(LoginRequiredMixin, FormView):
......@@ -988,6 +999,11 @@ class VxlanCreate(LoginRequiredMixin, FormView):
def form_valid(self, form):
network_created = openstack_api.neutron.network_create(self.request, name=form.cleaned_data['name'])
if form.cleaned_data['isAdvancedConfig']:
pass
else:
openstack_api.neutron.subnet_create(self.request, network_created.id, ip_version=4)
# TODO: default ip version should read from SETTINGS
return redirect(reverse_lazy('network.vxlan', kwargs={'pk': network_created.id}))
class VxlanDelete(LoginRequiredMixin, DeleteView): #TODO: check user
......
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