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

Inherits:
Server show all
Defined in:
lib/rackspace-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.



39
40
41
42
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 39

def initialize(attributes={})
  self.image_id   ||= 'img-wwgbb' # Ubuntu Lucid 10.04 server (i686)
  super
end

Instance Method Details

#activate_consoleObject



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

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

#destroyObject



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

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

#flavorObject



101
102
103
104
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 101

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

#flavor_idObject



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

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



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

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

#imageObject



106
107
108
109
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 106

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

#private_ip_addressObject



111
112
113
114
115
116
117
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 111

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

#public_ip_addressObject



119
120
121
122
123
124
125
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 119

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

#ready?Boolean

Returns:

  • (Boolean)


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

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

#rebootObject



73
74
75
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 73

def reboot
  false
end

#saveObject

Raises:



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 137

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



89
90
91
92
93
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 89

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

#snapshotObject



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

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

#startObject



77
78
79
80
81
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 77

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

#stopObject



83
84
85
86
87
# File 'lib/rackspace-fog/brightbox/models/compute/server.rb', line 83

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

#zone_idObject



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

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



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

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