Class: LxcSsh::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/lxc_ssh/manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(session, lxc_version, lxc_path) ⇒ Manager

Initializes the lxc manager by creating an instance of the version-specific lxc manager for the detected version

Parameters:

  • session (SSH::Connection::Session)

    ssh session

  • lxc_version (String)

    lxc version string

  • lxc_path (String)

    lxc installation path



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lxc_ssh/manager.rb', line 10

def initialize(session, lxc_version, lxc_path)
  @lxc_path = lxc_path
  @specific_manager = nil

  # LXC APIs mac change in the future, therefore a version specific adapter
  # must be used
  if    Gem::Version.new(lxc_version) >= Gem::Version.new('1.0')
    @specific_manager = LxcSsh::SpecificManager10.new(session, lxc_path)
  # other version checks go here
  else
    raise 'lxc versions < 1.0 are not supported'
  end
end

Instance Method Details

#container(name) ⇒ LxcSsh::Container

Returns an LxcSsh::Container object for the given container name

Returns:



48
49
50
# File 'lib/lxc_ssh/manager.rb', line 48

def container(name)
  @specific_manager.get_container_obj name
end

#container_config(name) ⇒ LxcSsh::ContainerConfig

Returns a LxcSsh::ContainerConfig object for the container name



41
42
43
# File 'lib/lxc_ssh/manager.rb', line 41

def container_config(name)
  @specific_manager.container_config name
end

#container_namesArray

Returns an array of lxc containers

Returns:

  • (Array)


27
28
29
# File 'lib/lxc_ssh/manager.rb', line 27

def container_names
  @specific_manager.container_names
end

#containersArray

Returns an array containing objects with container metadata

Returns:

  • (Array)


34
35
36
# File 'lib/lxc_ssh/manager.rb', line 34

def containers
  @specific_manager.containers
end

#create_container(name, template, template_options = nil) ⇒ String

Creates a container with the default configuration and additional template options and returns the output as a string

Parameters:

  • name (String)

    container name

  • template (String)

    template name (without ‘lxc-’-prefix)

  • template_options (String) (defaults to: nil)

    additional template options

Returns:

  • (String)


85
86
87
# File 'lib/lxc_ssh/manager.rb', line 85

def create_container(name, template, template_options = nil)
  @specific_manager.create_container name, template, template_options
end

#destroy_container(name) ⇒ Boolean

Destroys a container with the given name

Parameters:

  • name (String)

    container name

Returns:

  • (Boolean)


109
110
111
# File 'lib/lxc_ssh/manager.rb', line 109

def destroy_container(name)
  @specific_manager.destroy_container name
end

#start_container(name) ⇒ Boolean

Starts a container with the given name

Parameters:

  • name (String)

    container name

Returns:

  • (Boolean)


93
94
95
# File 'lib/lxc_ssh/manager.rb', line 93

def start_container(name)
  @specific_manager.start_container name
end

#stop_container(name) ⇒ Boolean

Stops a container

Parameters:

  • name (String)

    container name

Returns:

  • (Boolean)


101
102
103
# File 'lib/lxc_ssh/manager.rb', line 101

def stop_container(name)
  @specific_manager.stop_container name
end

#template_help(name) ⇒ String

Returns the template help text for a given template name

Parameters:

  • template_name (String)

    template to use (without ‘lxc-’-prefix)

Returns:

  • (String)


73
74
75
# File 'lib/lxc_ssh/manager.rb', line 73

def template_help(name)
  @specific_manager.template_help name
end

#template_namesArray

TODO:

check path

Returns an array containing all templates

Returns:

  • (Array)


65
66
67
# File 'lib/lxc_ssh/manager.rb', line 65

def template_names
  @specific_manager.template_names
end

#write_config(name, config) ⇒ Object

Writes the config file contents back to the container config

Parameters:

  • container_name (String)

    the container to use

  • config (String)

    configuration string to save



56
57
58
# File 'lib/lxc_ssh/manager.rb', line 56

def write_config(name, config)
  @specific_manager.write_config name, config
end