Remove LXC.default_config_path, add LXC.global_config_item

Follows lxc@593e84786e2b4709059989bee489deab5c923779
This commit is contained in:
Andre Nathan 2014-01-14 08:51:22 -02:00
parent 67dd08eeeb
commit 0c3abf0de2
2 changed files with 15 additions and 8 deletions

View file

@ -133,14 +133,20 @@ lxc_run_shell(VALUE self)
/*
* call-seq:
* LXC.default_config_path
* LXC.global_config_item(key)
*
* Returns the +liblxc+ configuration path, usually +/var/lib/lxc+.
* Returns value for the given global config key.
*/
static VALUE
lxc_default_config_path(VALUE self)
lxc_global_config_item(VALUE self, VALUE rb_key)
{
return rb_str_new2(lxc_get_default_config_path());
char *key;
const char *value;
key = StringValuePtr(rb_key);
value = lxc_get_global_config_item(key);
if (value == NULL)
rb_raise(Error, "invalid configuration key %s", key);
return rb_str_new2(value);
}
/*
@ -241,7 +247,7 @@ container_alloc(VALUE klass)
/*
* call-seq:
* LXC::Container.new(name, config_path = LXC.default_config_path)
* LXC::Container.new(name, config_path = LXC.global_config_item('lxc.lxcpath'))
*
* Creates a new container instance with the given name, under the given
* configuration path.
@ -1633,8 +1639,8 @@ Init_lxc(void)
lxc_arch_to_personality, 1);
rb_define_singleton_method(LXC, "run_command", lxc_run_command, 1);
rb_define_singleton_method(LXC, "run_shell", lxc_run_shell, 0);
rb_define_singleton_method(LXC, "default_config_path",
lxc_default_config_path, 0);
rb_define_singleton_method(LXC, "global_config_item",
lxc_global_config_item, 1);
rb_define_singleton_method(LXC, "version", lxc_version, 0);
rb_define_singleton_method(LXC, "list_containers", lxc_list_containers, -1);

View file

@ -10,7 +10,8 @@ class TestLXCUndefined < Test::Unit::TestCase
end
def test_container_config_file_name
config_path = File.join(LXC.default_config_path, @name, 'config')
lxc_path = LXC.global_config_item('lxc.lxcpath')
config_path = File.join(lxc_path, @name, 'config')
assert_equal(config_path, @container.config_file_name)
end