Class: Cangallo
- Inherits:
-
Object
- Object
- Cangallo
- Defined in:
- lib/cangallo/keybase.rb,
lib/cangallo.rb,
lib/cangallo/repo.rb,
lib/cangallo/check.rb,
lib/cangallo/qcow2.rb,
lib/cangallo/config.rb,
lib/cangallo/version.rb,
lib/cangallo/cangafile.rb,
lib/cangallo/libguestfs.rb
Overview
Copyright 2016, Javier Fontán Muiños <[email protected]>
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: Keybase Classes: Cangafile, Check, Config, LibGuestfs, Qcow2, Repo
Constant Summary collapse
- VERSION =
'0.0.8'
Instance Method Summary collapse
- #find(string) ⇒ Object
- #get(string) ⇒ Object
- #get_images(repo_name = nil) ⇒ Object
-
#initialize ⇒ Cangallo
constructor
A new instance of Cangallo.
- #parse_name(name) ⇒ Object
- #repo(name = nil) ⇒ Object
- #short_name(string, repo = nil) ⇒ Object
Constructor Details
Instance Method Details
#find(string) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cangallo.rb', line 94 def find(string) repo, name = parse_name(string) return "#{repo}:#{self.repo(repo).find(name)}" if repo image = self.repo.find(name) return "#{self.repo.name}:#{image}" if image @config.repos.each do |r| image = self.repo(r).find(name) return "#{r}:#{image}" if image end nil end |
#get(string) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/cangallo.rb', line 109 def get(string) image = find(string) return nil if !image repo, name = parse_name(image) img = self.repo(repo).get(name) img["repo"] = repo if img img end |
#get_images(repo_name = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cangallo.rb', line 36 def get_images(repo_name = nil) info = [] repos = [] if repo_name repos = [repo_name] else repos = @config.repos end repos.each do |r| repo = self.repo(r) repo.images.each do |sha256, image| name = repo.short_name(sha256) info << { "repo" => r, "sha256" => sha256, "name" => "#{r}:#{name}", "size" => image["actual-size"], "parent" => short_name(image["parent"], r), "description" => image["description"], "available" => File.exist?(repo.image_path(sha256)), "creation-time" => image["creation-time"] } end end info end |
#parse_name(name) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cangallo.rb', line 68 def parse_name(name) slices = name.split(':') repo = nil name = name if slices.length > 1 repo = slices[0] name = slices[1] end return repo, name end |
#repo(name = nil) ⇒ Object
32 33 34 |
# File 'lib/cangallo.rb', line 32 def repo(name = nil) @config.repo(name) end |
#short_name(string, repo = nil) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cangallo.rb', line 82 def short_name(string, repo = nil) return nil if !string img_repo, img_name = parse_name(string) img_repo ||= repo image = self.repo(img_repo).find(img_name) name = self.repo(img_repo).short_name(image) "#{img_repo}:#{name}" end |