{% include 'modal/instance_create.html' %}
{% include 'modal/instance_show.html' %}
{% include 'modal/instance_new_action.html' %}
+ {% include 'modal/instance_new_alarm.html' %}
+ {% include 'modal/instance_export_metric.html' %}
{% endblock %}
{% block resource_block %}
<ul class="dropdown-menu">
<li><a href="#"
onclick="javascript:performAction('{% url 'projects:instances:action' instance_id=i|get:'_id' project_id=project_id type=type %}')">
- <i class="fa fa-magic"></i>Exec NS Primitive</a></li>
+ <i class="fa fa-magic"></i> Exec NS Primitive</a></li>
<li>
<a href="{% url 'projects:instances:ns_operations' project_id=project_id type=type instance_id=i|get:'_id' %}">
- <i class="fa fa-list"></i>Active operations</a></li>
+ <i class="fa fa-list"></i> Active operations</a></li>
+ <li class="divider"></li>
+ <li><a href="#"
+ onclick="javascript:newAlarmNs('{% url 'projects:instances:ns_create_alarm' instance_id=i|get:'_id' project_id=project_id type=type %}')">
+ <i class="far fa-bell"></i> New Alarm</a></li>
+ <li><a href="#"
+ onclick="javascript:exportMetricNs('{% url 'projects:instances:ns_export_metric' instance_id=i|get:'_id' project_id=project_id type=type %}')">
+ <i class="far fa-chart-bar"></i> Export metric</a></li>
<li class="divider"></li>
<li>
<a href="javascript:deleteNs('{% url 'projects:instances:delete' instance_id=i|get:'_id' project_id=project_id type=type %}', true)">
- <i class="far fa-trash-alt" style="color:red" ></i>Force delete</a></li>
+ <i class="far fa-trash-alt" style="color:red" ></i> Force delete</a></li>
</ul>
--- /dev/null
+<div class="modal" id="modal_instance_export_metric" xmlns="http://www.w3.org/1999/html">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <span aria-hidden="true">×</span></button>
+ <h4 class="modal-title">Export metric</h4>
+ </div>
+
+ <form id="formExportMetricNS" action="" class="form-horizontal" method="post" enctype="multipart/form-data">
+ {% csrf_token %}
+ <div class="modal-body" id="modal_instance_export_metric">
+
+
+ <div class="form-group">
+ <label for="metric_name" class="col-sm-3">Name *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="metric_name" name="metric_name" required>
+ </div>
+ <label for="metric_name" class="col-sm-3">Metric Name *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="metric_name" name="metric_name" required>
+ </div>
+ </div>
+
+
+ <div class="form-group">
+ <label for="vnf_member_index" class="col-sm-3">VNF Member index *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="vnf_member_index" name="vnf_member_index" required>
+ </div>
+ <label for="vdu_name" class="col-sm-3">VDU Name *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="vdu_name" name="vdu_name" required>
+ </div>
+ </div>
+
+ <div class="form-group">
+
+
+ <label for="correlation_id" class="col-sm-3">Correlation</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="correlation_id" name="correlation_id" >
+ </div>
+
+ </div>
+ <div class="form-group">
+ <label for="collection_unit" class="col-sm-3">Collection Unit</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="collection_unit" name="collection_unit" >
+ </div>
+ <label for="collection_period" class="col-sm-3">Collection period </label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="collection_period" name="collection_period" >
+ </div>
+
+ </div>
+ <div class="form-group">
+
+
+ </div>
+
+
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+ <button class="btn btn-primary pull-right">Create</button>
+ </div>
+ </form>
+
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
--- /dev/null
+<div class="modal" id="modal_instance_new_alarm" xmlns="http://www.w3.org/1999/html">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <span aria-hidden="true">×</span></button>
+ <h4 class="modal-title">Create Alarm</h4>
+ </div>
+
+ <form id="formAlarmNS" action="" class="form-horizontal" method="post" enctype="multipart/form-data">
+ {% csrf_token %}
+ <div class="modal-body" id="modal_instance_new_alarm_body">
+
+
+ <div class="form-group">
+ <label for="alarm_name" class="col-sm-3">Name *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="alarm_name" name="alarm_name" required>
+ </div>
+ <label for="metric_name" class="col-sm-3">Metric Name *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="metric_name" name="metric_name" required>
+ </div>
+ </div>
+
+
+ <div class="form-group">
+ <label for="vnf_member_index" class="col-sm-3">VNF Member index *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="vnf_member_index" name="vnf_member_index" required>
+ </div>
+ <label for="vdu_name" class="col-sm-3">VDU Name *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="vdu_name" name="vdu_name" required>
+ </div>
+ </div>
+
+ <div class="form-group">
+
+ <label for="statistic" class="col-sm-3">Statistic *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="statistic" name="statistic" required>
+ </div>
+ <label for="correlation_id" class="col-sm-3">Correlation</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="correlation_id" name="correlation_id" >
+ </div>
+
+ </div>
+ <div class="form-group">
+ <label for="threshold_value" class="col-sm-3">Threshold Value *</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="threshold_value" name="threshold_value" required>
+ </div>
+ <label for="statistic" class="col-sm-3">Severity</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="severity" name="severity" >
+ </div>
+
+ </div>
+ <div class="form-group">
+ <label for="operation" class="col-sm-3">Operation</label>
+ <div class="col-sm-3">
+ <input class="form-control input-sm" id="operation" name="operation" >
+ </div>
+
+
+
+ </div>
+
+
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+ <button class="btn btn-primary pull-right">Create</button>
+ </div>
+ </form>
+
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/action$', views.action, name='action'),
url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/operation$', views.ns_operations, name='ns_operations'),
url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/operation/(?P<op_id>[0-9a-z-]+)', views.ns_operation, name='ns_operation'),
+ url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/monitoring/alarm$', views.create_alarm, name='ns_create_alarm'),
+ url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)/monitoring/metric$', views.export_metric, name='ns_export_metric'),
url(r'^(?P<type>[ns|vnf]+)/(?P<instance_id>[0-9a-z-]+)', views.show, name='show'),
]
print result
return __response_handler(request, result)
+@login_required
+def export_metric(request, project_id=None, instance_id=None, type=None):
+
+ metric_data = request.POST.dict()
+
+ client = Client()
+ keys = ["collection_period",
+ "vnf_member_index",
+ "metric_name",
+ "correlation_id",
+ "vdu_name",
+ "collection_unit"]
+ metric_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, metric_data.items()))
+
+ response = client.ns_metric_export(instance_id, metric_data)
+
+ return __response_handler(request, {}, None, to_redirect=False,
+ status=response.status_code)
+
+@login_required
+def create_alarm(request, project_id=None, instance_id=None, type=None):
+ metric_data = request.POST.dict()
+ print metric_data
+ client = Client()
+
+
+ keys = ["threshold_value",
+ "vnf_member_index",
+ "metric_name",
+ "vdu_name",
+ "alarm_name",
+ "correlation_id",
+ "statistic",
+ "operation",
+ "severity"]
+ metric_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, metric_data.items()))
+
+ result = client.ns_alarm_create(instance_id, metric_data)
+ return __response_handler(request, {}, None, to_redirect=False,
+ status=result['status'] if 'status' in result else None)
+
def __response_handler(request, data_res, url=None, to_redirect=None, *args, **kwargs):
raw_content_types = request.META.get('HTTP_ACCEPT', '*/*').split(',')
return redirect(url, *args, **kwargs)
else:
return render(request, url, data_res)
+
+
json=vim_data)
return None
-
def sdn_list(self):
token = self.get_token()
if token:
return self._send_get(_url, headers=headers)
return None
+ def ns_alarm_create(self, id, alarm_payload):
+ token = self.get_token()
+ headers = {}
+ if token:
+ headers['Authorization'] = 'Bearer {}'.format(token)
+ headers['Content-Type'] = 'application/json'
+# headers['accept'] = 'application/json'
+
+ _url = "{0}/test/message/alarm_request".format(self._base_path)
+ return self._send_post(_url, headers=headers, json=alarm_payload)
+ return None
+
+ def ns_metric_export(self, id, metric_payload):
+
+ token = self.get_token()
+ headers = {}
+ if token:
+ headers['Authorization'] = 'Bearer {}'.format(token)
+ headers['Content-Type'] = 'application/json'
+ #headers['accept'] = 'application/json'
+ print "DIO"
+ _url = "{0}/test/message/metric_request".format(self._base_path)
+ print _url
+ return self._send_post(_url, headers=headers, json=metric_payload)
+ return None
+
+
def vnfd_list(self):
token = self.get_token()
if token:
log.exception(e)
#print "Exception during send POST"
return {'error': 'error during connection to agent'}
- return Util.json_loads_byteified(r.text)
+ if 'accept' in kwargs['headers']:
+ accept = kwargs['headers']['accept']
+ if accept == 'application/json':
+ #print "json"
+ return Util.json_loads_byteified(r.text)
+ return r
def _send_put(self, url, data=None, json=None, **kwargs):
try:
$('#modal_instance_new_action').modal('show');
}
+function exportMetricNs(url) {
+ console.log(url)
+ $("#formExportMetricNS").attr("action", url);
+ $('#modal_instance_export_metric').modal('show');
+}
+
+function newAlarmNs(url) {
+ $("#formAlarmNS").attr("action", url);
+ $('#modal_instance_new_alarm').modal('show');
+}
+
function deleteNs(url, force) {
bootbox.confirm("Are you sure want to delete?", function (result) {
if (result) {
});
});
+ $("#formAlarmNS").submit(function (event) {
+ event.preventDefault(); //prevent default action
+ var post_url = $(this).attr("action"); //get form action url
+ var request_method = $(this).attr("method"); //get form GET/POST method
+ var form_data = new FormData(this); //Encode form elements for submission
+ console.log(post_url);
+ $.ajax({
+ url: post_url,
+ type: request_method,
+ data: form_data,
+ headers: {
+ "Accept": 'application/json'
+ },
+ contentType: false,
+ processData: false
+ }).done(function (response,textStatus, jqXHR) {
+ $('#modal_instance_new_action').modal('hide');
+ bootbox.alert({
+ title: "Metric",
+ message: "Alarm created."
+ });
+ }).fail(function(result){
+ var data = result.responseJSON;
+ var title = "Error " + (data.code ? data.code: 'unknown');
+ var message = data.detail ? data.detail: 'No detail available.';
+ bootbox.alert({
+ title: title,
+ message: message
+ });
+ });
+ });
+
+ $("#formExportMetricNS").submit(function (event) {
+ event.preventDefault(); //prevent default action
+ var post_url = $(this).attr("action"); //get form action url
+ var request_method = $(this).attr("method"); //get form GET/POST method
+ var form_data = new FormData(this); //Encode form elements for submission
+ console.log(post_url);
+ $.ajax({
+ url: post_url,
+ type: request_method,
+ data: form_data,
+ headers: {
+ "Accept": 'application/json'
+ },
+ contentType: false,
+ processData: false
+ }).done(function (response,textStatus, jqXHR) {
+ $('#modal_instance_new_action').modal('hide');
+ bootbox.alert({
+ title: "Metric",
+ message: "Metric exported."
+ });
+ }).fail(function(result){
+ var data = result.responseJSON;
+ var title = "Error " + (data.code ? data.code: 'unknown');
+ var message = data.detail ? data.detail: 'No detail available.';
+ bootbox.alert({
+ title: title,
+ message: message
+ });
+ });
+ });
+
});
\ No newline at end of file