Class: HP::Cloud::ImageHelper

Inherits:
BaseHelper show all
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

Attributes inherited from BaseHelper

#connection, #cstatus, #fog

Class Method Summary collapse

Instance Method Summary collapse

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_atObject

Returns the value of attribute created_at.



34
35
36
# File 'lib/hpcloud/image_helper.rb', line 34

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



34
35
36
# File 'lib/hpcloud/image_helper.rb', line 34

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



33
34
35
# File 'lib/hpcloud/image_helper.rb', line 33

def meta
  @meta
end

#nameObject

Returns the value of attribute name.



34
35
36
# File 'lib/hpcloud/image_helper.rb', line 34

def name
  @name
end

#statusObject

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_keysObject



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

Returns:

  • (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

Returns:

  • (Boolean)


79
80
81
# File 'lib/hpcloud/image_helper.rb', line 79

def is_windows?
  return (@meta.hsh['hp_image_license'].nil? == false)
end

#loginObject



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/hpcloud/image_helper.rb', line 98

def 
  case os
  when :ubuntu 
    return 'ubuntu'
  when :centos, :fedora, :debian
    return 'root'
  when :windows
    return 'Administrator'
  end
  return 'ubuntu'
end

#osObject



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

#saveObject



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