class Kitchen::Driver::VmpoolStores::GitlabSnippetStore

Attributes

pool_file[R]
project_id[RW]
snippet_id[RW]

Public Class Methods

new(options = nil) click to toggle source

@option project_id [Integer] - the project id in gitlab @option snippet_id [Integer] - the snipppet id in the gitlab project @option pool_file [String] - the snipppet file name

# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 13
def initialize(options = nil)
  options ||= { project_id: nil, snippet_id: nil, pool_file: 'vmpool'}
  raise ArgumentError.new("You must pass the project_id option") unless options['project_id'].to_i > 0
  @snippet_id = options['snippet_id']  #ie. 34422
  @project_id = options['project_id']  #ie. 89
  @pool_file = options['pool_file']
end

Public Instance Methods

create() click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 27
def create
  #info("Creating new vmpool data snippet")
  snippet = create_snippet
  @snippet_id = snippet.id
  read
end
save() click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 34
def save
  #info("Saving vmpool data")
  update_snippet
  read
end
update(content = nil) click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 21
def update(content = nil)
  #info("Updating vmpool data")
  update_snippet
  read
end

Private Instance Methods

create_snippet(project = project_id) click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 51
def create_snippet(project = project_id)
  client.create_commit(project, {
    title: 'Virtual Machine Pools',
    visibility: 'public',
    file_name: pool_file,
    code: {}.to_yaml
    })
end
project_snippets(project = project_id) click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 69
def project_snippets(project = project_id)
  client.snippets(project).map {|s| s.id }
end
read_content(project = project_id, id = snippet_id) click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 73
def read_content(project = project_id, id = snippet_id)
  client.snippet_content(project, id)
end
snippet_exists?(project = project_id) click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 42
def snippet_exists?(project = project_id)
  return false unless snippet_id
  client.snippets(project, {
    title: 'Virtual Machine Pools',
    visibility: 'public',
    file_name: pool_file,
    code: {}.to_yaml})
end
update_snippet(project = project_id) click to toggle source
# File lib/kitchen/driver/vmpool_stores/gitlab_snippet_store.rb, line 60
def update_snippet(project = project_id)
  client.edit_snippet(project, snippet_id, {
    title: 'Virtual Machine Pools',
    visibility: 'public',
    file_name: pool_file,
    code: pool_data.to_yaml
   })
end