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, #ssh_options, #ssh_port, #username

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #ssh_ip_address, #ssh_ip_address=, #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 Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

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

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



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

def initialize(attributes = {})
  # Call super first to initialize the service object for our default image
  super
  self.image_id ||= service.default_image
end

Instance Method Details

#activate_consoleObject



159
160
161
162
163
# File 'lib/fog/brightbox/models/compute/server.rb', line 159

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

#destroyObject



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

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

#dns_nameString

Returns the public DNS name of the server

Returns:



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

def dns_name
  ["public", fqdn].join(".")
end

#flavorObject



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

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

#flavor_idObject



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

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



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

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

#imageObject



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

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

#mapping_identityString

Replaces the server’s identifier with it’s interface’s identifier for Cloud IP mapping

Returns:

  • (String)

    the identifier to pass to a Cloud IP mapping request



186
187
188
# File 'lib/fog/brightbox/models/compute/server.rb', line 186

def mapping_identity
  interfaces.first["id"]
end

#private_ip_addressObject



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

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

#public_ip_addressObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  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)


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

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

#saveObject

Raises:



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

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  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 == "" }

  options.merge!(:server_type => flavor_id) unless flavor_id.nil? || flavor_id == ""

  data = service.create_server(options)
  merge_attributes(data)
  true
end

#shutdownObject



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

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

#snapshotObject



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

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

#startObject



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

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

#stopObject



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

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

#zone_idObject



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

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



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

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