Module: Hyperkit::Client::Profiles

Included in:
Hyperkit::Client
Defined in:
lib/hyperkit/client/profiles.rb

Overview

Methods for the profiles API

Instance Method Summary collapse

Instance Method Details

#create_profile(name, options = {}) ⇒ Sawyer::Resource

Create a profile

Examples:

Create profile with config

Hyperkit.create_profile("test-profile", config: {
  "limits.memory" => "2GB",
  "limits.cpu" => 2,
  "raw.lxc" => "lxc.aa_profile = unconfined"
})

Create profile with devices

Hyperkit.create_profile("test-profile", devices: {
  eth0: {
    nictype: "bridged",
    parent: "br-ext",
    type: "nic"
  }
})

Parameters:

  • name (String)

    Profile name

  • options (Hash) (defaults to: {})

    Additional data to be passed

Options Hash (options):

  • :config (Hash)

    Profile configuration

  • :description (String)

    Profile description

  • :devices (Hash)

    Profile devices

Returns:

  • (Sawyer::Resource)


48
49
50
51
52
# File 'lib/hyperkit/client/profiles.rb', line 48

def create_profile(name, options={})
  opts = options.merge(name: name)
  opts[:config] = stringify_hash(opts[:config]) if opts[:config]
  post(profiles_path, opts).
end

#delete_profile(name) ⇒ Sawyer::Resource

Delete a profile

Examples:

Delete profile 'test-profile'

Hyperkit.delete_profile("test-profile")

Parameters:

  • name (String)

    Profile name

Returns:

  • (Sawyer::Resource)


114
115
116
# File 'lib/hyperkit/client/profiles.rb', line 114

def delete_profile(name)
  delete(profile_path(name)).
end

#profile(name) ⇒ Sawyer::Resource

Retrieve a profile

Examples:

Retrieve profile 'test-profile'

Hyperkit.profile("test-profile")

Parameters:

  • name (String)

    Profile name

Returns:

  • (Sawyer::Resource)

    Profile



61
62
63
# File 'lib/hyperkit/client/profiles.rb', line 61

def profile(name)
  get(profile_path(name)).
end

#profilesArray<String>

List of profiles on the server

Examples:

Get list of profiles

Hyperkit.profiles #=> ["default", "docker"]

Returns:

  • (Array<String>)

    An array of profile names



19
20
21
22
# File 'lib/hyperkit/client/profiles.rb', line 19

def profiles
  response = get(profiles_path)
  response..map { |path| path.split('/').last }
end

#rename_profile(old_name, new_name) ⇒ Sawyer::Resource

Rename a profile

Examples:

Rename profile 'test' to 'test2'

Hyperkit.rename_profile("test", "test2")

Parameters:

  • old_name (String)

    Existing profile name

  • new_name (String)

    New profile name

Returns:

  • (Sawyer::Resource)


103
104
105
# File 'lib/hyperkit/client/profiles.rb', line 103

def rename_profile(old_name, new_name)
  post(profile_path(old_name), { name: new_name }).
end

#update_profile(name, options = {}) ⇒ Sawyer::Resource

Update an existing profile

Examples:

Update profile with config (config is overwritten – not merged)

Hyperkit.update_profile("test-profile", config: {
  "limits.memory" => "4GB",
  "limits.cpu" => 4,
  "raw.lxc" => "lxc.aa_profile = unconfined"
})

Create profile with devices (devices are overwritten – not merged)

Hyperkit.create_profile("test-profile", devices: {
  eth0: {
    nictype: "bridged",
    parent: "br-int",
    type: "nic"
  }
})

Parameters:

  • name (String)

    Profile name

  • options (Hash) (defaults to: {})

    Additional data to be passed

Options Hash (options):

  • :config (Hash)

    Profile configuration. Existing configuration will be overwritten.

  • :description (String)

    Profile description

  • :devices (Hash)

    Profile devices. Existing devices will be overwritten.

Returns:

  • (Sawyer::Resource)


89
90
91
92
93
# File 'lib/hyperkit/client/profiles.rb', line 89

def update_profile(name, options={})
  opts = options.except(:name)
  opts[:config] = stringify_hash(opts[:config]) if opts[:config]
  put(profile_path(name), opts).
end