Class: Fog::Compute::Bluebox::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/bluebox/models/compute/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



26
27
28
29
30
31
# File 'lib/fog/bluebox/models/compute/server.rb', line 26

def initialize(attributes={})
  self.flavor_id    ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' # Block 1GB Virtual Server
  self.image_id     ||= 'a8f05200-7638-47d1-8282-2474ef57c4c3' # Scientific Linux 6
  self.location_id  ||= '37c2bd9a-3e81-46c9-b6e2-db44a25cc675' # Seattle, WA
  super
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



24
25
26
# File 'lib/fog/bluebox/models/compute/server.rb', line 24

def hostname
  @hostname
end

#lb_applicationsObject

Returns the value of attribute lb_applications.



24
25
26
# File 'lib/fog/bluebox/models/compute/server.rb', line 24

def lb_applications
  @lb_applications
end

#lb_backendsObject

Returns the value of attribute lb_backends.



24
25
26
# File 'lib/fog/bluebox/models/compute/server.rb', line 24

def lb_backends
  @lb_backends
end

#lb_servicesObject

Returns the value of attribute lb_services.



24
25
26
# File 'lib/fog/bluebox/models/compute/server.rb', line 24

def lb_services
  @lb_services
end

#passwordObject

Returns the value of attribute password.



24
25
26
# File 'lib/fog/bluebox/models/compute/server.rb', line 24

def password
  @password
end

Instance Method Details

#destroyObject



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

def destroy
  requires :id
  service.destroy_block(id)
  true
end

#flavorObject



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

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

#imageObject



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

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

#locationObject



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

def location
  requires :location_id
  service.locations.get(location_id)
end

#private_ip_addressObject



54
55
56
# File 'lib/fog/bluebox/models/compute/server.rb', line 54

def private_ip_address
  nil
end

#public_ip_addressObject



58
59
60
61
62
# File 'lib/fog/bluebox/models/compute/server.rb', line 58

def public_ip_address
  if ip = ips.first
    ip['address']
  end
end

#ready?Boolean

Returns:

  • (Boolean)


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

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

#reboot(type = 'SOFT') ⇒ Object



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

def reboot(type = 'SOFT')
  requires :id
  service.reboot_block(id, type)
  true
end

#saveObject

Raises:

  • (Fog::Errors::Error)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fog/bluebox/models/compute/server.rb', line 74

def save
  raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
  requires :flavor_id, :image_id, :location_id
  options = {}

  unless persisted?  # new record
    raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key
    options['ssh_public_key'] = public_key if public_key
    options['password'] = password if @password
  end

  if @lb_backends
    options['lb_backends'] = lb_backends
  elsif @lb_services
    options['lb_services'] = lb_services
  elsif @lb_applications
    options['lb_applications'] = lb_applications
  end

  options['username'] = username
  options['hostname'] = hostname if @hostname
  options['ipv6_only'] = ipv6_only if ipv6_only
  data = service.create_block(flavor_id, image_id, location_id, options)
  merge_attributes(data.body)
  true
end

#setup(credentials = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fog/bluebox/models/compute/server.rb', line 101

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

#usernameObject



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

def username
  @username ||= 'deploy'
end