{% 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>
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)
+
+
class Client(object):
- def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', **kwargs):
+ def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', ro_host=None, ro_port=9090, **kwargs):
self._user = 'admin'
self._password = 'admin'
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
<input type="password" name="password" class="form-control" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
- <div class="form-group has-feedback">
- <input name="project_id" class="form-control" placeholder="Project">
- <span class="glyphicon glyphicon-lock form-control-feedback"></span>
- </div>
<div class="row">
<div class="col-xs-8">