Add Container#rename

This commit is contained in:
Andre Nathan 2013-12-23 15:59:41 -02:00
parent 03eae61c02
commit f2a6812c80
2 changed files with 29 additions and 0 deletions

View file

@ -855,6 +855,26 @@ container_remove_device_node(int argc, VALUE *argv, VALUE self)
return self; return self;
} }
static VALUE
container_rename(VALUE self, VALUE rb_name)
{
int ret;
char *name;
struct container_data *data;
VALUE rb_args[2];
name = StringValuePtr(rb_name);
Data_Get_Struct(self, struct container_data, data);
ret = data->container->rename(data->container, name);
if (!ret)
rb_raise(Error, "unable to rename container");
rb_args[0] = rb_name;
rb_args[1] = Qnil;
return rb_class_new_instance(2, rb_args, Container);
}
static VALUE static VALUE
container_save_config(int argc, VALUE *argv, VALUE self) container_save_config(int argc, VALUE *argv, VALUE self)
{ {
@ -1323,6 +1343,7 @@ Init_lxc(void)
rb_define_method(Container, "reboot", container_reboot, 0); rb_define_method(Container, "reboot", container_reboot, 0);
rb_define_method(Container, "remove_device_node", rb_define_method(Container, "remove_device_node",
container_remove_device_node, 0); container_remove_device_node, 0);
rb_define_method(Container, "rename", container_rename, 1);
rb_define_method(Container, "save_config", container_save_config, -1); rb_define_method(Container, "save_config", container_save_config, -1);
rb_define_method(Container, "set_cgroup_item", rb_define_method(Container, "set_cgroup_item",
container_set_cgroup_item, 2); container_set_cgroup_item, 2);

View file

@ -35,4 +35,12 @@ class TestLXCCreated < Test::Unit::TestCase
assert(@container.keys('lxc.network.0').include?('name')) assert(@container.keys('lxc.network.0').include?('name'))
assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr')) assert_match(/^00:16:3e:/, @container.config_item('lxc.network.0.hwaddr'))
end end
def test_container_rename
new_name = "renamed_#{@name}"
renamed = @container.rename(new_name)
assert_equal(new_name, renamed.name)
rerenamed = renamed.rename(@name)
assert_equal(@name, rerenamed.name)
end
end end