module Hyperkit::Client::Profiles
Methods for the profiles API
@see Hyperkit::Client
@see github.com/lxc/lxd/blob/master/doc/rest-api.md
Public Instance Methods
Create a profile
@param name [String] Profile name @param options [Hash] Additional data to be passed @option options [Hash] :config Profile configuration @option options [String] :description Profile description @option options [Hash] :devices Profile devices @return [Sawyer::Resource]
@example Create profile with config
Hyperkit.create_profile("test-profile", config: { "limits.memory" => "2GB", "limits.cpu" => 2, "raw.lxc" => "lxc.aa_profile = unconfined" })
@example Create profile with devices
Hyperkit.create_profile("test-profile", devices: { eth0: { nictype: "bridged", parent: "br-ext", type: "nic" } })
# 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).metadata end
Delete a profile
@param name [String] Profile name @return [Sawyer::Resource]
@example Delete profile 'test-profile'
Hyperkit.delete_profile("test-profile")
# File lib/hyperkit/client/profiles.rb, line 136 def delete_profile(name) delete(profile_path(name)).metadata end
Patch an existing profile using patch api
@param name [String] Profile name @param options [Hash] Additional data to be passed @option options [Hash] :config Profile configuration. It will be merged with existing configuration @option options [String] :description Profile description @option options [Hash] :devices Profile devices. Existing devices will be merged @return [Sawyer::Resource]
@example Patch profile with config (config is merged)
Hyperkit.patch_profile("test-profile", config: { "limits.memory" => "4GB", "limits.cpu" => 4, "raw.lxc" => "lxc.aa_profile = unconfined" })
# File lib/hyperkit/client/profiles.rb, line 111 def patch_profile(name, options={}) opts = options.except(:name) opts[:config] = stringify_hash(opts[:config]) if opts[:config] patch(profile_path(name), opts).metadata end
Retrieve a profile
@param name [String] Profile name @return [Sawyer::Resource] Profile
@example Retrieve profile 'test-profile'
Hyperkit.profile("test-profile")
# File lib/hyperkit/client/profiles.rb, line 61 def profile(name) get(profile_path(name)).metadata end
List of profiles on the server
@return [Array<String>] An array of profile names
@example Get list of profiles
Hyperkit.profiles #=> ["default", "docker"]
# File lib/hyperkit/client/profiles.rb, line 19 def profiles response = get(profiles_path) response.metadata.map { |path| path.split('/').last } end
Rename a profile
@param old_name [String] Existing profile name @param new_name [String] New profile name @return [Sawyer::Resource]
@example Rename profile 'test' to 'test2'
Hyperkit.rename_profile("test", "test2")
# File lib/hyperkit/client/profiles.rb, line 125 def rename_profile(old_name, new_name) post(profile_path(old_name), { name: new_name }).metadata end
Update an existing profile
@param name [String] Profile name @param options [Hash] Additional data to be passed @option options [Hash] :config Profile configuration. Existing configuration will be overwritten. @option options [String] :description Profile description @option options [Hash] :devices Profile devices. Existing devices will be overwritten. @return [Sawyer::Resource]
@example 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" })
@example Create profile with devices (devices are overwritten – not merged)
Hyperkit.create_profile("test-profile", devices: { eth0: { nictype: "bridged", parent: "br-int", type: "nic" } })
# 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).metadata end
Private Instance Methods
# File lib/hyperkit/client/profiles.rb, line 146 def profile_path(name) File.join(profiles_path, name) end
# File lib/hyperkit/client/profiles.rb, line 142 def profiles_path "/1.0/profiles" end