Added "publish" method to publications, client && server part

Added "custom_methods" to detail handlers
This commit is contained in:
Adolfo Gómez 2014-01-20 09:38:24 +00:00
parent cfc2dbb49e
commit 8ed7bd1cc0
11 changed files with 75 additions and 12 deletions

View File

@ -41,11 +41,11 @@ function minify_admin() {
'gui-element',
// Gui definition
'gui-definition',
'gui-d-service-providers',
'gui-d-services',
'gui-d-authenticators',
'gui-d-osmanagers',
'gui-d-connectivity',
'gui-d-deployedservices',
'gui-d-servicespools',
];
var cssFiles = [

View File

@ -174,6 +174,13 @@ class Transports(DetailHandler):
]
class Publications(DetailHandler):
custom_methods=['publish']
def publish(self, parent):
logger.debug('Custom "publish" invoked')
parent.publish()
return self.success()
def getItems(self, parent, item):
return [{
'id': i.id,

View File

@ -159,10 +159,15 @@ class BaseModelHandler(Handler):
def invalidItemException(self):
raise NotFound(_('Item not found'))
# Success methods
def success(self):
return 'done'
# Details do not have types at all
# so, right now, we only process details petitions for Handling & tables info
class DetailHandler(BaseModelHandler):
custom_methods = []
'''
Detail handler (for relations such as provider-->services, authenticators-->users,groups, deployed services-->cache,assigned, groups, transports
Urls recognized for GET are:
@ -178,8 +183,11 @@ class DetailHandler(BaseModelHandler):
[path] --> create NEW item
[path]/ID --> Modify existing item
For DELETE:
[path]/ID
[path]/ID
Also accepts GET methods for "custom" methods
'''
def __init__(self, parentHandler, path, params, *args, **kwargs):
self._parent = parentHandler
self._path = path
@ -195,6 +203,16 @@ class DetailHandler(BaseModelHandler):
if nArgs == 0:
return self.getItems(parent, None)
# if has custom methods, look for if this request matches any of them
for cm in self.custom_methods:
if self._args[0] == cm:
try:
operation = getattr(self, self._args[0])
except:
self.invalidMethodException()
return operation(parent)
if nArgs == 1:
if self._args[0] == OVERVIEW:
return self.getItems(parent, None)

View File

@ -62,9 +62,10 @@ class Client(object):
pass
try:
cached_api_key = aKey
cached_api = API(url='https://'+self._host, username=self._username, password=self._password, timeout=self._timeout, insecure=True, debug=True)
cached_api = API(url='https://'+self._host+'/api', username=self._username, password=self._password, timeout=self._timeout, insecure=True, debug=True)
return cached_api
except:
logger.exception('Exception connection ovirt at {0}'.format(self._host))
cached_api_key = None
raise Exception("Can't connet to server at {0}".format(self._host))
return None

View File

@ -405,6 +405,7 @@ DetailModelRestApi.prototype = {
"use strict";
return this.base.getLogs(itemId, success_fnc, fail_fnc);
},
// Put methods
put: function(data, options) {
"use strict";
return this.base.put(data, options);
@ -439,6 +440,7 @@ DetailModelRestApi.prototype = {
"use strict";
return this.base.del(id, success_fnc, fail_fnc);
},
tableInfo: function(success_fnc, fail_fnc) {
"use strict";
return this.base.tableInfo(success_fnc, fail_fnc);
@ -456,6 +458,16 @@ DetailModelRestApi.prototype = {
return this.base.gui(typeName, success_fnc, fail_fnc);
},
// Generic "Invoke" method (with no args, if needed, put them on "method" after "?" as normal url would be
invoke: function(method, success_fnc, fail_fnc) {
"use strict";
return this.base.get({
id: method,
success: success_fnc,
fail: fail_fnc
});
},
};
// Populate api

View File

@ -47,7 +47,7 @@ gui.servicesPool.link = function(event) {
logs : 'logs-placeholder',
}));
gui.setLinksEvents();
var testClick = function(val, value, btn, tbl, refreshFnc) {
gui.doLog(value);
};
@ -142,10 +142,34 @@ gui.servicesPool.link = function(event) {
var publications = null;
if( service.info.needs_publication ) {
$('#publications-placeholder_tab').removeClass('hidden');
publications = new GuiElement(api.servicesPool.detail(servPool.id, 'publications'), 'publications');
var pubApi = api.servicesPool.detail(servPool.id, 'publications');
publications = new GuiElement(pubApi, 'publications');
var publicationsTable = publications.table({
container : 'publications-placeholder',
rowSelect : 'single',
buttons : [ 'new', {
text: gettext('Cancel'),
css: 'disabled',
click: function(val, value, btn, tbl, refreshFnc) {
gui.doLog(val);
},
select: function(val, value, btn, tbl, refreshFnc) {
if( !val ) {
$(btn).removeClass('btn3d-info').addClass('disabled');
return;
}
if( ['P','W','L'].indexOf(val.state) > 0 ) { // Waiting for publication, Preparing or running
$(btn).removeClass('disabled').addClass('btn3d-info');
}
},
},
'xls' ],
onNew: function(action, tbl, refreshFnc) {
gui.doLog('New publication');
pubApi.invoke('publish', function(){
gui.doLog('Success');
}, gui.failRequestModalFnc(gettext('Publication failed')) );
},
});
prevTables.push(publicationsTable);

View File

@ -103,11 +103,11 @@
<!-- user interface management -->
<script src="{% get_static_prefix %}adm/js/gui-definition.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-service-providers.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-services.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-authenticators.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-osmanagers.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-connectivity.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-deployedservices.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-servicespools.js"></script>
{% else %}
<!-- minified js from: 'jquery.cookie', 'bootstrap.min', 'bootstrap-switch.min', 'bootstrap-select.min', 'jquery.validate.min', 'jquery.blockUI',

View File

@ -15,7 +15,7 @@
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li><a class="lnk-dashboard" href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li><a class="lnk-service_providers" href="#"><i class="fa fa-bar-chart-o"></i> {% trans 'Service providers' %}</a></li>
<li><a class="lnk-service_providers" href="#"><i class="fa fa-bar-chart-o"></i> {% trans 'Services' %}</a></li>
<li><a class="lnk-authenticators" href="#"><i class="fa fa-user"></i> {% trans 'Authenticators' %}</a></li>
<li><a class="lnk-osmanagers" href="#"><i class="fa fa-edit"></i> Os Managers</a></li>
<li><a class="lnk-connectivity" href="#"><i class="fa fa-font"></i> {% trans 'Connectivity' %}</a></li>
@ -30,6 +30,7 @@
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right navbar-user">
</ul>
<form id="form_language" action="{% url "django.views.i18n.set_language" %}" method="post">

View File

@ -1,10 +1,10 @@
{% load i18n %}
<div class="row">
<div class="col-xs-12">
<h1>{% trans 'Providers' %}</h1>
<h1>{% trans 'Services' %}</h1>
<ol class="breadcrumb">
<li><a class="lnk-dashboard" href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li>{% trans 'Providers' %}</li>
<li>{% trans 'Services' %}</li>
</ol>
</div>
</div><!-- /.row -->

View File

@ -1,7 +1,7 @@
{% load i18n %}
<div class="row">
<div class="col-xs-12">
<h1>{% trans 'Deployed Services' %}</h1>
<h1>{% trans 'Services Pools' %}</h1>
<ol class="breadcrumb">
<li><a class="lnk-dashboard" href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li>{% trans 'Deployed Services' %}</li>