Class: Fog::Compute::HP::Server

Inherits:
Server show all
Defined in:
lib/fog/hp/models/compute/server.rb

Instance Attribute Summary collapse

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #username

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #ssh_port, #sshable?

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



36
37
38
39
40
41
42
# File 'lib/fog/hp/models/compute/server.rb', line 36

def initialize(attributes = {})
  # assign these attributes first to prevent race condition with new_record?
  self.security_groups = attributes.delete(:security_groups)
  self.min_count = attributes.delete(:min_count)
  self.max_count = attributes.delete(:max_count)
  super
end

Instance Attribute Details

#flavor_idObject



94
95
96
# File 'lib/fog/hp/models/compute/server.rb', line 94

def flavor_id
  @flavor_id ||= (flavor.nil? ? nil : flavor["id"])
end

#image_idObject



86
87
88
# File 'lib/fog/hp/models/compute/server.rb', line 86

def image_id
  @image_id ||= (image.nil? ? nil : image["id"])
end

#passwordObject (readonly)

Returns the value of attribute password.



33
34
35
# File 'lib/fog/hp/models/compute/server.rb', line 33

def password
  @password
end

Instance Method Details

#change_password(admin_password) ⇒ Object



122
123
124
125
126
# File 'lib/fog/hp/models/compute/server.rb', line 122

def change_password(admin_password)
  requires :id
  connection.change_password_server(id, admin_password)
  true
end

#confirm_resizeObject



152
153
154
155
156
# File 'lib/fog/hp/models/compute/server.rb', line 152

def confirm_resize
  requires :id
  connection.confirm_resized_server(id)
  true
end

#create_image(name, metadata = {}) ⇒ Object



158
159
160
161
# File 'lib/fog/hp/models/compute/server.rb', line 158

def create_image(name, ={})
  requires :id
  connection.create_image(id, name, )
end

#destroyObject



44
45
46
47
48
# File 'lib/fog/hp/models/compute/server.rb', line 44

def destroy
  requires :id
  connection.delete_server(id)
  true
end

#imagesObject



50
51
52
53
# File 'lib/fog/hp/models/compute/server.rb', line 50

def images
  requires :id
  connection.images(:server => self)
end

#key_pairObject



55
56
57
58
59
# File 'lib/fog/hp/models/compute/server.rb', line 55

def key_pair
  requires :key_name

  connection.key_pairs.get(key_name)
end

#key_pair=(new_keypair) ⇒ Object



61
62
63
# File 'lib/fog/hp/models/compute/server.rb', line 61

def key_pair=(new_keypair)
  self.key_name = new_keypair && new_keypair.name
end

#max_count=(new_max_count) ⇒ Object



106
107
108
# File 'lib/fog/hp/models/compute/server.rb', line 106

def max_count=(new_max_count)
  @max_count = new_max_count
end

#min_count=(new_min_count) ⇒ Object



102
103
104
# File 'lib/fog/hp/models/compute/server.rb', line 102

def min_count=(new_min_count)
  @min_count = new_min_count
end

#private_ip_addressObject



65
66
67
68
# File 'lib/fog/hp/models/compute/server.rb', line 65

def private_ip_address
  addr = addresses.nil? ? nil : addresses.fetch('private', []).first
  addr["addr"] if addr
end

#public_ip_addressObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fog/hp/models/compute/server.rb', line 70

def public_ip_address
  # FIX: Both the private and public ips are bundled under "private" network name
  # So hack to get to the public ip address
  if !addresses.nil?
    addr = addresses.fetch('private', [])
    # if we have more than 1 address, then the return the second address which is public
    if addr.count > 1
      addr[1]["addr"]
    else
      nil
    end
  else
    nil
  end
end

#ready?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/fog/hp/models/compute/server.rb', line 118

def ready?
  self.state == 'ACTIVE'
end

#reboot(type = 'SOFT') ⇒ Object



128
129
130
131
132
# File 'lib/fog/hp/models/compute/server.rb', line 128

def reboot(type = 'SOFT')
  requires :id
  connection.reboot_server(id, type)
  true
end

#rebuild(image_id, name, admin_pass = nil, metadata = nil, personality = nil) ⇒ Object



134
135
136
137
138
# File 'lib/fog/hp/models/compute/server.rb', line 134

def rebuild(image_id, name, admin_pass=nil, =nil, personality=nil)
  requires :id
  connection.rebuild_server(id, image_id, name, admin_pass, , personality)
  true
end

#resize(flavor_id) ⇒ Object



140
141
142
143
144
# File 'lib/fog/hp/models/compute/server.rb', line 140

def resize(flavor_id)
  requires :id
  connection.resize_server(id, flavor_id)
  true
end

#revert_resizeObject



146
147
148
149
150
# File 'lib/fog/hp/models/compute/server.rb', line 146

def revert_resize
  requires :id
  connection.revert_resized_server(id)
  true
end

#saveObject

Raises:



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/fog/hp/models/compute/server.rb', line 163

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
  requires :flavor_id, :image_id, :name
  options = {
    'metadata'    => ,
    'personality' => personality,
    'accessIPv4'  => accessIPv4,
    'accessIPv6'  => accessIPv6,
    'min_count'   => @min_count,
    'max_count'   => @max_count,
    'key_name'    => key_name,
    'security_groups' => @security_groups
  }
  options = options.reject {|key, value| value.nil?}
  data = connection.create_server(name, flavor_id, image_id, options)
  merge_attributes(data.body['server'])
  true
end

#security_groupsObject



114
115
116
# File 'lib/fog/hp/models/compute/server.rb', line 114

def security_groups   
  @security_groups
end

#security_groups=(new_security_groups) ⇒ Object



110
111
112
# File 'lib/fog/hp/models/compute/server.rb', line 110

def security_groups=(new_security_groups)
  @security_groups = new_security_groups
end

#setup(credentials = {}) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/fog/hp/models/compute/server.rb', line 182

def setup(credentials = {})
  requires :public_ip_address, :identity, :public_key, :username
  Fog::SSH.new(public_ip_address, username, credentials).run([
    %{mkdir .ssh},
    %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
    %{passwd -l #{username}},
    %{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
    %{echo "#{Fog::JSON.encode()}" >> ~/metadata.json}
  ])
rescue Errno::ECONNREFUSED
  sleep(1)
  retry
end