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 Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#private_key=, #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



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

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

#change_admin_password(password) ⇒ Object



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

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

#confirm_resizeObject



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

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

#createObject



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

def create
  requires :name, :image_id, :flavor_id
  data = connection.create_server(name, image_id, flavor_id, 1, 1)
  merge_attributes(data.body['server'])
  true
end

#destroyObject



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

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

#flavorObject



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

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

#imageObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/fog/rackspace/models/compute_v2/server.rb', line 94

def ready?
  state == ACTIVE
end

#reboot(type = 'SOFT') ⇒ Object



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

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

#rebuild(image_id) ⇒ Object



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

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

#resize(flavor_id) ⇒ Object



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

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

#revert_resizeObject



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

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



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

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