Class: HP::Cloud::ImageHelper
- Inherits:
-
BaseHelper
- Object
- BaseHelper
- HP::Cloud::ImageHelper
- Defined in:
- lib/hpcloud/image_helper.rb
Constant Summary collapse
- OS_TYPES =
{ :ubuntu => 0, :centos => 1, :fedora => 2, :debian => 3, :windows => 4 }
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
Attributes inherited from BaseHelper
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(foggy = nil) ⇒ ImageHelper
constructor
A new instance of ImageHelper.
- #is_private? ⇒ Boolean
- #is_windows? ⇒ Boolean
- #login ⇒ Object
- #os ⇒ Object
- #save ⇒ Object
- #set_server(value) ⇒ Object
Methods inherited from BaseHelper
#destroy, #is_valid?, #set_error, #to_hash
Constructor Details
#initialize(foggy = nil) ⇒ ImageHelper
Returns a new instance of ImageHelper.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hpcloud/image_helper.rb', line 40 def initialize(foggy = nil) super(nil, foggy) if foggy.nil? @meta = HP::Cloud::Metadata.new(nil) return end @id = foggy.id @name = foggy.name @created_at = foggy.created_at @status = foggy.status @meta = HP::Cloud::Metadata.new(foggy.) end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
34 35 36 |
# File 'lib/hpcloud/image_helper.rb', line 34 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
34 35 36 |
# File 'lib/hpcloud/image_helper.rb', line 34 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
33 34 35 |
# File 'lib/hpcloud/image_helper.rb', line 33 def @meta end |
#name ⇒ Object
Returns the value of attribute name.
34 35 36 |
# File 'lib/hpcloud/image_helper.rb', line 34 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
34 35 36 |
# File 'lib/hpcloud/image_helper.rb', line 34 def status @status end |
Class Method Details
.get_keys ⇒ Object
36 37 38 |
# File 'lib/hpcloud/image_helper.rb', line 36 def self.get_keys() return ["id", "name", "created_at", "status"] end |
Instance Method Details
#is_private? ⇒ Boolean
83 84 85 86 |
# File 'lib/hpcloud/image_helper.rb', line 83 def is_private? return false if @meta.hsh['owner'].nil? return @meta.hsh['owner'].empty? == false end |
#is_windows? ⇒ Boolean
79 80 81 |
# File 'lib/hpcloud/image_helper.rb', line 79 def is_windows? return (@meta.hsh['hp_image_license'].nil? == false) end |
#login ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/hpcloud/image_helper.rb', line 98 def login case os when :ubuntu return 'ubuntu' when :centos, :fedora, :debian return 'root' when :windows return 'Administrator' end return 'ubuntu' end |
#os ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/hpcloud/image_helper.rb', line 88 def os return :windows if is_windows? return :ubuntu if name.nil? return :windows unless name.match(/[wW][iI][nN][dD][oO][wW]/).nil? return :fedora unless name.match(/[fF][eE][dD][oO][rR][aA]/).nil? return :centos unless name.match(/[cC][eE][nN][tT][oO][sS]/).nil? return :debian unless name.match(/[dD][eE][bB][iI][aA][nN]/).nil? return :ubuntu end |
#save ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/hpcloud/image_helper.rb', line 57 def save if is_valid? set_error(@meta.cstatus) end return false if is_valid? == false if @fog.nil? server = Servers.new.get(@server_name_id) if server.is_valid? == false set_error(server.cstatus) return false end @id = server.create_image(@name , @meta.hsh).id if @id.nil? set_error(server.cstatus) return false end return true end raise "Update not implemented" end |
#set_server(value) ⇒ Object
53 54 55 |
# File 'lib/hpcloud/image_helper.rb', line 53 def set_server(value) @server_name_id = value end |