Class: Fog::AWS::EC2::Server
- Inherits:
-
Model
- Object
- Model
- Fog::AWS::EC2::Server
show all
- Defined in:
- lib/fog/aws/models/ec2/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#connection
Instance Method Summary
collapse
Methods inherited from Model
#collection, #inspect, #reload, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
35
36
37
38
39
|
# File 'lib/fog/aws/models/ec2/server.rb', line 35
def initialize(attributes={})
@groups ||= ["default"] if attributes[:subnet_id].blank?
@flavor_id ||= 'm1.small'
super
end
|
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture.
11
12
13
|
# File 'lib/fog/aws/models/ec2/server.rb', line 11
def architecture
@architecture
end
|
Instance Method Details
#addresses ⇒ Object
41
42
43
44
45
|
# File 'lib/fog/aws/models/ec2/server.rb', line 41
def addresses
requires :id
connection.addresses(:server => self)
end
|
#console_output ⇒ Object
47
48
49
50
51
|
# File 'lib/fog/aws/models/ec2/server.rb', line 47
def console_output
requires :id
connection.get_console_output(@id)
end
|
#destroy ⇒ Object
53
54
55
56
57
58
|
# File 'lib/fog/aws/models/ec2/server.rb', line 53
def destroy
requires :id
connection.terminate_instances(@id)
true
end
|
#flavor ⇒ Object
76
77
78
|
# File 'lib/fog/aws/models/ec2/server.rb', line 76
def flavor
@flavor ||= connection.flavors.all.detect {|flavor| flavor.id == @flavor_id}
end
|
#flavor=(new_flavor) ⇒ Object
72
73
74
|
# File 'lib/fog/aws/models/ec2/server.rb', line 72
def flavor=(new_flavor)
@flavor = new_flavor
end
|
#flavor_id ⇒ Object
def security_group
connection.security_groups.all(@group_id)
end
def security_group=(new_security_group)
@group_id = new_security_group.name
end
68
69
70
|
# File 'lib/fog/aws/models/ec2/server.rb', line 68
def flavor_id
@flavor && @flavor.id || @flavor_id
end
|
#key_pair ⇒ Object
80
81
82
83
84
|
# File 'lib/fog/aws/models/ec2/server.rb', line 80
def key_pair
requires :key_name
connection.keypairs.all(@key_name).first
end
|
#key_pair=(new_keypair) ⇒ Object
86
87
88
|
# File 'lib/fog/aws/models/ec2/server.rb', line 86
def key_pair=(new_keypair)
@key_name = new_keypair.name
end
|
#monitoring=(new_monitoring) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/fog/aws/models/ec2/server.rb', line 90
def monitoring=(new_monitoring)
if new_monitoring.is_a?(Hash)
@monitoring = new_monitoring['state']
else
@monitoring = new_monitoring
end
end
|
#placement=(new_placement) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/fog/aws/models/ec2/server.rb', line 98
def placement=(new_placement)
if new_placement.is_a?(Hash)
@availability_zone = new_placement['availabilityZone']
else
@availability_zone = new_placement
end
end
|
#ready? ⇒ Boolean
106
107
108
|
# File 'lib/fog/aws/models/ec2/server.rb', line 106
def ready?
@state == 'running'
end
|
#reboot ⇒ Object
110
111
112
113
114
|
# File 'lib/fog/aws/models/ec2/server.rb', line 110
def reboot
requires :id
connection.reboot_instances(@id)
true
end
|
#save ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/fog/aws/models/ec2/server.rb', line 116
def save
requires :image_id
options = {
'BlockDeviceMapping' => @block_device_mapping,
'InstanceType' => flavor_id,
'KernelId' => @kernel_id,
'KeyName' => @key_name,
'Monitoring.Enabled' => @monitoring,
'Placement.AvailabilityZone' => @availability_zone,
'RamdiskId' => @ramdisk_id,
'SecurityGroup' => @groups,
'SubnetId' => subnet_id,
'UserData' => @user_data
}
if subnet_id.blank?
options.delete('SubnetId')
else
options.delete('SecurityGroup')
end
data = connection.run_instances(@image_id, 1, 1, options)
merge_attributes(data.body['instancesSet'].first)
true
end
|
#start ⇒ Object
146
147
148
149
150
|
# File 'lib/fog/aws/models/ec2/server.rb', line 146
def start
requires :id
connection.start_instances(@id)
true
end
|
#stop ⇒ Object
152
153
154
155
156
|
# File 'lib/fog/aws/models/ec2/server.rb', line 152
def stop
requires :id
connection.stop_instances(@id)
true
end
|
#volumes ⇒ Object
158
159
160
161
162
|
# File 'lib/fog/aws/models/ec2/server.rb', line 158
def volumes
requires :id
connection.volumes(:server => self)
end
|