Module: Ropenstack::Image::Version2

Defined in:
lib/ropenstack/image/v2.rb

Overview

  • Name: ImageVersion2

  • Description: Implementation of the Glance V2.0 API Client in Ruby

  • Author: Sam ‘Tehsmash’ Betts, John Davidge

  • Date: 30/06/2014

Instance Method Summary collapse

Instance Method Details

#image_add_tag(id, tag) ⇒ Object



46
47
48
# File 'lib/ropenstack/image/v2.rb', line 46

def image_add_tag(id, tag)
  put_request(address("images/"+id+"/tags/"+tag), @token)
end

#image_create(name, id, visibilty, tags) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ropenstack/image/v2.rb', line 21

def image_create(name, id, visibilty, tags)
  data = { 
    :name => name
  }
  unless id.nil?
    data[:id] = id
  end
  unless visibility.nil?
    data[:visibility] = visibility
  end
  unless tags.nil?
    data[:tags] = tags
  end

  post_request(address("images"), data, @token)
end

#image_delete(id) ⇒ Object



38
39
40
# File 'lib/ropenstack/image/v2.rb', line 38

def image_delete(id)
  delete_request(address("images/" + id), @token)
end

#image_delete_tag(id) ⇒ Object



50
51
52
# File 'lib/ropenstack/image/v2.rb', line 50

def image_delete_tag(id)
  delete_request(address("images/"+id+"/tags/"+tag), @token)
end

#image_download(id) ⇒ Object

TODO Ruby HTTP Binary Download to FILE



43
44
# File 'lib/ropenstack/image/v2.rb', line 43

def image_download(id)
end

#images(id) ⇒ Object

Returns a list of images with all associated meta-data in hash format.



13
14
15
16
17
18
19
# File 'lib/ropenstack/image/v2.rb', line 13

def images(id)
  if id.nil?
    return get_request(address("images"), @token)["images"]
  else
    return get_request(address("images/" + id), @token)
  end
end

#member_addObject



58
59
# File 'lib/ropenstack/image/v2.rb', line 58

def member_add()
end

#member_deleteObject



61
62
# File 'lib/ropenstack/image/v2.rb', line 61

def member_delete()
end

#member_updateObject



64
65
# File 'lib/ropenstack/image/v2.rb', line 64

def member_update()
end

#members(id) ⇒ Object

Members



55
56
# File 'lib/ropenstack/image/v2.rb', line 55

def members(id)
end

#put_octect(uri, data, manage_errors) ⇒ Object

Special rest call for sending a file stream using an octet-stream main change is just custom headers. Still implemented using do_request function.



113
114
115
116
117
118
119
# File 'lib/ropenstack/image/v2.rb', line 113

def put_octect(uri, data, manage_errors)
  headers = build_headers(@token)
  headers["Content-Type"] = 'application/octet-stream'	
  req = Net::HTTP::Put.new(uri.request_uri, initheader = headers)
  req.body = data
  return do_request(uri, req, manage_errors, 0)
end

#schemas(type) ⇒ Object

Schemas



68
69
70
# File 'lib/ropenstack/image/v2.rb', line 68

def schemas(type)
  return get_request(address("schemas/" + type), @token)
end

#upload_image_from_file(name, disk_format, container_format, minDisk, minRam, is_public, file) ⇒ Object

Upload an image to the Image Service from a file, takes in a ruby file object. More convoluted than it should be because for a bug in Quantum which just returns an error no matter the outcome.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ropenstack/image/v2.rb', line 80

def upload_image_from_file(name, disk_format, container_format, minDisk, minRam, is_public, file)
  data = {
    "name" => name,
    "disk_format" => disk_format,
    "container_format" => container_format,
    "minDisk" => minDisk,
    "minRam" => minRam,
    "public" => is_public
  }
  imagesBefore = images()
  post_request(address("images"), data, @token, false)
  imagesAfter = images()
  foundNewImage = true
  image = nil
  imagesAfter.each do |imageA|
    imagesBefore.each do |imageB|
      if(imageA == imageB)
        foundNewImage = false				
      end
    end
    if(foundNewImage)
      image = imageA
      break
    end
  end
  return put_octect(address(image["file"]), file.read, false)
end