Class: Fog::Compute::RackspaceV2::Server

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

Constant Summary collapse

ACTIVE =

States

'ACTIVE'
BUILD =
'BUILD'
DELETED =
'DELETED'
ERROR =
'ERROR'
HARD_REBOOT =
'HARD_REBOOT'
MIGRATING =
'MIGRATING'
PASSWORD =
'PASSWORD'
REBOOT =
'REBOOT'
REBUILD =
'REBUILD'
RESCUE =
'RESCUE'
RESIZE =
'RESIZE'
REVERT_RESIZE =
'REVERT_RESIZE'
SUSPENDED =
'SUSPENDED'
UNKNOWN =
'UNKNOWN'
VERIFY_RESIZE =
'VERIFY_RESIZE'

Instance Attribute Summary collapse

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

#initialize, #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

This class inherits a constructor from Fog::Model

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



44
45
46
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 44

def password
  @password
end

Instance Method Details

#attachmentsObject



87
88
89
90
91
92
93
94
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 87

def attachments
  @attachments ||= begin
    Fog::Compute::RackspaceV2::Attachments.new({
      :connection => connection,
      :server => self
    })
  end
end

#change_admin_password(password) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 133

def change_admin_password(password)
  requires :identity
  connection.change_server_password(identity, password)
  self.state = PASSWORD
  @password = password
  true
end

#confirm_resizeObject



121
122
123
124
125
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 121

def confirm_resize
  requires :identity
  connection.confirm_resize_server(identity)
  true
end

#createObject



55
56
57
58
59
60
61
62
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 55

def create
  requires :name, :image_id, :flavor_id
  options = {}
  options[:disk_config] = disk_config unless disk_config.nil?
  data = connection.create_server(name, image_id, flavor_id, 1, 1, options)
  merge_attributes(data.body['server'])
  true
end

#destroyObject



71
72
73
74
75
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 71

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

#flavorObject



77
78
79
80
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 77

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

#imageObject



82
83
84
85
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 82

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

#ready?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 96

def ready?
  state == ACTIVE
end

#reboot(type = 'SOFT') ⇒ Object



100
101
102
103
104
105
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 100

def reboot(type = 'SOFT')
  requires :identity
  connection.reboot_server(identity, type)
  self.state = type == 'SOFT' ? REBOOT : HARD_REBOOT
  true
end

#rebuild(image_id) ⇒ Object



114
115
116
117
118
119
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 114

def rebuild(image_id)
  requires :identity
  connection.rebuild_server(identity, image_id)
  self.state = REBUILD
  true
end

#resize(flavor_id) ⇒ Object



107
108
109
110
111
112
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 107

def resize(flavor_id)
  requires :identity
  connection.resize_server(identity, flavor_id)
  self.state = RESIZE
  true
end

#revert_resizeObject



127
128
129
130
131
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 127

def revert_resize
  requires :identity
  connection.revert_resize_server(identity)
  true
end

#saveObject



46
47
48
49
50
51
52
53
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 46

def save
  if identity
    update
  else
    create
  end
  true
end

#updateObject



64
65
66
67
68
69
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 64

def update
  requires :identity, :name
  data = connection.update_server(identity, name)
  merge_attributes(data.body['server'])
  true
end