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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#private_key=, #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
# File 'lib/fog/brightbox/models/compute/server.rb', line 40

def initialize(attributes={})
  self.image_id ||= Fog::Compute[:brightbox].default_image
  super
end

Instance Method Details

#activate_consoleObject



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

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

#destroyObject



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

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

#flavorObject



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

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

#flavor_idObject



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

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



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

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

#imageObject



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

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

#private_ip_addressObject



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

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

#public_ip_addressObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

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)


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

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:



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

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



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

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

#snapshotObject



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

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

#startObject



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

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

#stopObject



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

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

#zone_idObject



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

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



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

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