Class: Fog::Compute::Brightbox::Server

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

Instance Attribute Summary

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.



40
41
42
43
44
45
# File 'lib/fog/brightbox/models/compute/server.rb', line 40

def initialize(attributes={})
  # Call super first to initialize the 'connection' object for our default image
  super
  # FIXME connection is actually <Fog::Compute::Brightbox::Real> not <Fog::Connection>
  self.image_id ||= connection.default_image
end

Instance Method Details

#activate_consoleObject



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

def activate_console
  requires :identity
  response = connection.activate_console_server(identity)
  [response["console_url"], response["console_token"], response["console_token_expires"]]
end

#destroyObject



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

def destroy
  requires :identity
  connection.destroy_server(identity)
  true
end

#flavorObject



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

def flavor
  requires :flavor_id
  connection.flavors.get(flavor_id)
end

#flavor_idObject



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

def flavor_id
  if t_flavour_id = attributes[:flavor_id]
    t_flavour_id
  elsif server_type
    server_type[:id] || server_type['id']
  end
end

#flavor_id=(incoming_flavour_id) ⇒ Object



67
68
69
# File 'lib/fog/brightbox/models/compute/server.rb', line 67

def flavor_id=(incoming_flavour_id)
  attributes[:flavor_id] = incoming_flavour_id
end

#imageObject



127
128
129
130
# File 'lib/fog/brightbox/models/compute/server.rb', line 127

def image
  requires :image_id
  connection.images.get(image_id)
end

#private_ip_addressObject



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

def private_ip_address
  unless interfaces.empty?
    interfaces.first["ipv4_address"]
  else
    nil
  end
end

#public_ip_addressObject



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

def public_ip_address
  unless cloud_ips.empty?
    cloud_ips.first["public_ip"]
  else
    nil
  end
end

#ready?Boolean

Returns:

  • (Boolean)


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

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

#reboot(use_hard_reboot = true) ⇒ Boolean

Directly requesting a server reboot is not supported in the API so needs to attempt a shutdown/stop, wait and start again.

Default behaviour is a hard reboot because it is more reliable because the state of the server’s OS is irrelevant.

Parameters:

  • use_hard_reboot (Boolean) (defaults to: true)

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/fog/brightbox/models/compute/server.rb', line 84

def reboot(use_hard_reboot = true)
  requires :identity
  if ready?
    unless use_hard_reboot
      soft_reboot
    else
      hard_reboot
    end
  else
    # Not able to reboot if not ready in the first place
    false
  end
end

#saveObject

Raises:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/fog/brightbox/models/compute/server.rb', line 158

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
  requires :image_id
  options = {
    :image => image_id,
    :name => name,
    :zone => zone_id,
    :user_data => user_data,
    :server_groups => server_groups
  }.delete_if {|k,v| v.nil? || v == "" }
  unless flavor_id.nil? || flavor_id == ""
    options.merge!(:server_type => flavor_id)
  end
  data = connection.create_server(options)
  merge_attributes(data)
  true
end

#shutdownObject



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

def shutdown
  requires :identity
  connection.shutdown_server(identity)
  true
end

#snapshotObject



71
72
73
74
# File 'lib/fog/brightbox/models/compute/server.rb', line 71

def snapshot
  requires :identity
  connection.snapshot_server(identity)
end

#startObject



98
99
100
101
102
# File 'lib/fog/brightbox/models/compute/server.rb', line 98

def start
  requires :identity
  connection.start_server(identity)
  true
end

#stopObject



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

def stop
  requires :identity
  connection.stop_server(identity)
  true
end

#zone_idObject



47
48
49
50
51
52
53
# File 'lib/fog/brightbox/models/compute/server.rb', line 47

def zone_id
  if t_zone_id = attributes[:zone_id]
    t_zone_id
  elsif zone
    zone[:id] || zone['id']
  end
end

#zone_id=(incoming_zone_id) ⇒ Object



63
64
65
# File 'lib/fog/brightbox/models/compute/server.rb', line 63

def zone_id=(incoming_zone_id)
  attributes[:zone_id] = incoming_zone_id
end