class Kitchen::Driver::VmpoolStores::GitlabCommitStore
Attributes
branch[R]
pool_file[R]
project_id[RW]
Public Class Methods
new(options = nil)
click to toggle source
@option project_id
[Integer] - the project id in gitlab @option commit_id [Integer] - the snipppet id in the gitlab project @option pool_file
[String] - the snipppet file name
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 14 def initialize(options = nil) # there is currently some sort of weird bug in gitlab that prevents us from creating files with a yaml extension # thus we have ranmed the default pool file to vmpool options ||= { "project_id" => nil, "pool_file" => 'vmpool'} raise ArgumentError.new("You must pass the project_id option") unless options['project_id'].to_i > 0 @project_id = options['project_id'] #ie. 89 @pool_file = options['pool_file'] || 'vmpool' @branch = 'master' end
Public Instance Methods
create()
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 30 def create #info("Creating new vmpool data commit") create_file unless file_exists? read end
save()
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 36 def save # info("Saving vmpool data") update_file read end
update(content = nil)
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 24 def update(content = nil) #info("Updating vmpool data") update_file read end
Private Instance Methods
create_file(project = project_id)
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 49 def create_file(project = project_id) actions = [{ "action" => "create", "file_path" => pool_file, "content" => {}.to_yaml }] client.create_commit(project, branch, "update vmpool data", actions) end
file_exists?(project = project_id, file = pool_file)
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 45 def file_exists?(project = project_id, file = pool_file) read_content(project, file) end
read_content(project = project_id, file = pool_file)
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 68 def read_content(project = project_id, file = pool_file) begin client.file_contents(project, file, branch) rescue Gitlab::Error::NotFound false end end
update_file(project = project_id)
click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_commit_store.rb, line 59 def update_file(project = project_id) actions = [{ "action" => "update", "file_path" => pool_file, "content" => pool_data.to_yaml }] client.create_commit(project, branch, "update vmpool data", actions) end