Added commands into metadata.

The json_metadata command has been modified to accept some new
options and return the commands metadata. The API.txt has been
updated as well. The UI has been modified to use commands metadata
instead of methods metadata.

Ticket #388
This commit is contained in:
Endi S. Dewata
2011-11-16 15:13:32 -06:00
parent 005b74d869
commit 8f642bbe08
12 changed files with 10902 additions and 63 deletions

View File

@@ -1684,11 +1684,15 @@ command: i18n_messages
args: 0,0,1
output: Output('messages', <type 'dict'>, None)
command: json_metadata
args: 2,0,2
args: 2,3,3
arg: Str('objname?')
arg: Str('methodname?')
option: Str('object?')
option: Str('method?')
option: Str('command?')
output: Output('objects', <type 'dict'>, None)
output: Output('methods', <type 'dict'>, None)
output: Output('commands', <type 'dict'>, None)
command: krbtpolicy_mod
args: 1,9,3
arg: Str('uid', attribute=True, cli_name='user', multivalue=False, primary_key=True, query=True, required=False)

View File

@@ -132,12 +132,12 @@ IPA.automount.map_entity = function(spec) {
fields: [
{
name: 'key',
label: IPA.get_method_option(
label: IPA.get_command_option(
'automountmap_add_indirect', 'key').label
},
{
name: 'parentmap',
label: IPA.get_method_option(
label: IPA.get_command_option(
'automountmap_add_indirect', 'parentmap').label
}
]

View File

@@ -145,7 +145,7 @@ IPA.dns.zone_entity = function(spec) {
{
type: 'force_dnszone_add_checkbox',
name: 'force',
metadata: IPA.get_method_option('dnszone_add', 'force')
metadata: IPA.get_command_option('dnszone_add', 'force')
}
]
}
@@ -745,7 +745,7 @@ IPA.dnsrecord_type_widget = function(spec) {
};
IPA.force_dnszone_add_checkbox_widget = function(spec) {
var metadata = IPA.get_method_option('dnszone_add', spec.name);
var metadata = IPA.get_command_option('dnszone_add', spec.name);
spec.label = metadata.label;
spec.tooltip = metadata.doc;
return IPA.checkbox_widget(spec);

View File

@@ -51,7 +51,7 @@ IPA.entitle.entity = function(spec) {
fields: [
{
name: 'uuid',
label: IPA.get_method_option('entitle_register', 'ipaentitlementid').label,
label: IPA.get_command_option('entitle_register', 'ipaentitlementid').label,
read_only: true
},
{
@@ -72,7 +72,7 @@ IPA.entitle.entity = function(spec) {
},
{
name: 'quantity',
label: IPA.get_method_arg('entitle_consume', 'quantity').label,
label: IPA.get_command_arg('entitle_consume', 'quantity').label,
read_only: true
},
{
@@ -96,7 +96,7 @@ IPA.entitle.entity = function(spec) {
},
{
name: 'quantity',
label: IPA.get_method_arg('entitle_consume', 'quantity').label
label: IPA.get_command_arg('entitle_consume', 'quantity').label
},
{
name: 'start',
@@ -121,17 +121,17 @@ IPA.entitle.entity = function(spec) {
fields: [
{
name: 'username',
label: IPA.get_method_arg('entitle_register', 'username').label
label: IPA.get_command_arg('entitle_register', 'username').label
},
{
name: 'password',
label: IPA.get_method_option('entitle_register', 'password').label,
label: IPA.get_command_option('entitle_register', 'password').label,
type: 'password'
}
/* currently not supported
, {
name: 'ipaentitlementid',
label: IPA.get_method_option('entitle_register', 'ipaentitlementid').label
label: IPA.get_command_option('entitle_register', 'ipaentitlementid').label
}
*/
]
@@ -155,8 +155,8 @@ IPA.entitle.entity = function(spec) {
fields: [
{
name: 'quantity',
label: IPA.get_method_arg('entitle_consume', 'quantity').label,
metadata: IPA.get_method_arg('entitle_consume', 'quantity')
label: IPA.get_command_arg('entitle_consume', 'quantity').label,
metadata: IPA.get_command_arg('entitle_consume', 'quantity')
}
]
}).

View File

@@ -144,12 +144,12 @@ IPA.host.entity = function(spec) {
fields: [
{
name: 'ip_address',
metadata: IPA.get_method_option('host_add', 'ip_address')
metadata: IPA.get_command_option('host_add', 'ip_address')
},
{
type: 'force_host_add_checkbox',
name: 'force',
metadata: IPA.get_method_option('host_add', 'force')
metadata: IPA.get_command_option('host_add', 'force')
}
]
}
@@ -392,7 +392,7 @@ IPA.host_deleter_dialog = function(spec) {
that.deleter_dialog_create();
var metadata = IPA.get_method_option('host_del', 'updatedns');
var metadata = IPA.get_command_option('host_del', 'updatedns');
that.updatedns = $('<input/>', {
type: 'checkbox',
@@ -492,7 +492,7 @@ IPA.utc_date_column_format = function(value){
IPA.force_host_add_checkbox_widget = function(spec) {
var metadata = IPA.get_method_option('host_add', spec.name);
var metadata = IPA.get_command_option('host_add', spec.name);
spec.label = metadata.label;
spec.tooltip = metadata.doc;
return IPA.checkbox_widget(spec);

View File

@@ -66,41 +66,14 @@ var IPA = function() {
$.ajaxSetup(that.ajax_options);
var methods = IPA.command({
name: 'ipa_init_methods',
method: 'json_metadata',
options: {
methodname: 'all'
},
on_success: function(data, text_status, xhr) {
that.metadata.methods = data.result.methods;
}
});
var objects = IPA.command({
name: 'ipa_init_objects',
method: 'json_metadata',
options: {
objname: 'all'
},
on_success: function(data, text_status, xhr) {
that.metadata.objects = data.result.objects;
}
});
var metadata_command = IPA.concurrent_command({
commands: [
methods,
objects
],
on_success: params.on_success
});
var batch = IPA.batch_command({
name: 'ipa_init',
retry: false,
on_success: function() {
metadata_command.execute();
that.init_metadata({
on_success: params.on_success,
on_error: params.on_error
});
},
on_error: function(xhr, text_status, error_thrown) {
@@ -168,6 +141,42 @@ var IPA = function() {
batch.execute();
};
that.init_metadata = function(params) {
var objects = IPA.command({
name: 'ipa_init_objects',
method: 'json_metadata',
options: {
object: 'all'
},
on_success: function(data, text_status, xhr) {
that.metadata.objects = data.result.objects;
}
});
var commands = IPA.command({
name: 'ipa_init_commands',
method: 'json_metadata',
options: {
command: 'all'
},
on_success: function(data, text_status, xhr) {
that.metadata.commands = data.result.commands;
}
});
var metadata_command = IPA.concurrent_command({
commands: [
objects,
commands
],
on_success: params.on_success,
on_error: params.on_error
});
metadata_command.execute();
};
that.register = function(name, factory) {
that.remove_entity(name);
that.entity_factories[name] = factory;
@@ -798,9 +807,9 @@ IPA.get_entity_param = function(entity_name, name) {
return null;
};
IPA.get_method_arg = function(method_name, name) {
IPA.get_command_arg = function(command_name, arg_name) {
var metadata = IPA.metadata.methods[method_name];
var metadata = IPA.metadata.commands[command_name];
if (!metadata) {
return null;
}
@@ -811,7 +820,7 @@ IPA.get_method_arg = function(method_name, name) {
}
for (var i=0; i<args.length; i++) {
if (args[i].name === name) {
if (args[i].name === arg_name) {
return args[i];
}
}
@@ -819,9 +828,9 @@ IPA.get_method_arg = function(method_name, name) {
return null;
};
IPA.get_method_option = function(method_name, name) {
IPA.get_command_option = function(command_name, option_name) {
var metadata = IPA.metadata.methods[method_name];
var metadata = IPA.metadata.commands[command_name];
if (!metadata) {
return null;
}
@@ -832,7 +841,7 @@ IPA.get_method_option = function(method_name, name) {
}
for (var i=0; i<options.length; i++) {
if (options[i].name === name) {
if (options[i].name === option_name) {
return options[i];
}
}

View File

@@ -119,7 +119,7 @@ IPA.service.entity = function(spec) {
{
type: 'checkbox',
name: 'force',
metadata: IPA.get_method_option('service_add', 'force')
metadata: IPA.get_command_option('service_add', 'force')
}
]
}

View File

@@ -666,7 +666,7 @@ IPA.sudo.options_section = function(spec) {
that.table.create_column({
name: 'ipasudoopt',
label: IPA.get_method_option('sudorule_add_option', 'ipasudoopt').label,
label: IPA.get_command_option('sudorule_add_option', 'ipasudoopt').label,
entity_name:that.entity.name,
primary_key: true
});
@@ -766,7 +766,7 @@ IPA.sudo.options_section = function(spec) {
that.show_add_dialog = function() {
var label = IPA.get_method_option('sudorule_add_option', 'ipasudoopt').label;
var label = IPA.get_command_option('sudorule_add_option', 'ipasudoopt').label;
var title = IPA.messages.dialogs.add_title;
title = title.replace('${entity}', label);
@@ -828,7 +828,7 @@ IPA.sudo.options_section = function(spec) {
that.show_remove_dialog = function() {
var label = IPA.get_method_option('sudorule_add_option', 'ipasudoopt').label;
var label = IPA.get_command_option('sudorule_add_option', 'ipasudoopt').label;
var values = that.table.get_selected_values();
if (!values.length) {

View File

@@ -220,6 +220,9 @@
"hbacsvcgroup": {
"services": "Services"
},
"hbactest": {
"label": "HBAC Test"
},
"host": {
"certificate": "Host Certificate",
"cn": "Host Name",

File diff suppressed because it is too large Load Diff

View File

@@ -941,6 +941,17 @@ class Command(HasParam):
return rv
# list of attributes we want exported to JSON
json_friendly_attributes = (
'name', 'takes_args', 'takes_options',
)
def __json__(self):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
return json_dict
class LocalOrRemote(Command):
"""
A command that is explicitly executed locally or remotely.

View File

@@ -48,16 +48,34 @@ class json_metadata(Command):
),
)
takes_options = (
Str('object?',
doc=_('Name of object to export'),
),
Str('method?',
doc=_('Name of method to export'),
),
Str('command?',
doc=_('Name of command to export'),
),
)
has_output = (
Output('objects', dict, doc=_('Dict of JSON encoded IPA Objects')),
Output('methods', dict, doc=_('Dict of JSON encoded IPA Methods')),
Output('commands', dict, doc=_('Dict of JSON encoded IPA Commands')),
)
def execute(self, objname, methodname):
def execute(self, objname, methodname, **options):
objects = dict()
methods = dict()
commands = dict()
if objname :
empty = True
try:
if not objname:
objname = options['object']
if objname in self.api.Object:
o = self.api.Object[objname]
objects = dict([(o.name, json_serialize(o))])
@@ -65,25 +83,52 @@ class json_metadata(Command):
objects = dict(
(o.name, json_serialize(o)) for o in self.api.Object()
)
elif methodname:
if methodname in self.api.Method:
empty = False
except KeyError:
pass
try:
if not methodname:
methodname = options['method']
if methodname in self.api.Method:
m = self.api.Method[methodname]
methods = dict([(m.name, json_serialize(m))])
elif methodname == "all":
methods = dict(
(m.name, json_serialize(m)) for m in self.api.Method()
)
else:
empty = False
except KeyError:
pass
try:
cmdname = options['command']
if cmdname in self.api.Command:
c = self.api.Command[cmdname]
commands = dict([(c.name, json_serialize(c))])
elif cmdname == "all":
commands = dict(
(c.name, json_serialize(c)) for c in self.api.Command()
)
empty = False
except KeyError:
pass
if empty:
objects = dict(
(o.name, json_serialize(o)) for o in self.api.Object()
)
methods = dict(
(m.name, json_serialize(m)) for m in self.api.Method()
)
commands = dict(
(c.name, json_serialize(c)) for c in self.api.Command()
)
retval = dict([
("objects", objects),
("methods", methods),
("commands", commands),
])
return retval
@@ -313,6 +358,9 @@ class i18n_messages(Command):
"hbacsvcgroup": {
"services": _("Services"),
},
"hbactest": {
"label": _("HBAC Test"),
},
"host": {
"certificate": _("Host Certificate"),
"cn": _("Host Name"),