Class: Fog::AWS::EC2::Server

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/ec2/server.rb

Instance Attribute Summary

Attributes inherited from Model

#connection

Instance Method Summary collapse

Methods inherited from Model

#_dump, _load, aliases, attribute, #attributes, attributes, #collection, identity, #identity, #inspect, #merge_attributes, #new_record?, #reload, #requires, #to_json, #wait_for

Constructor Details

#initialize(attributes) ⇒ Server

Returns a new instance of Server.


34
35
36
37
38
# File 'lib/fog/aws/models/ec2/server.rb', line 34

def initialize(attributes)
  @groups ||= ["default"]
  @flavor_id ||= 'm1.small'
  super
end

Instance Method Details

#addressesObject


40
41
42
43
44
# File 'lib/fog/aws/models/ec2/server.rb', line 40

def addresses
  requires :id

  connection.addresses(:server => self)
end

#destroyObject


46
47
48
49
50
51
# File 'lib/fog/aws/models/ec2/server.rb', line 46

def destroy
  requires :id

  connection.terminate_instances(@id)
  true
end

#flavorObject


69
70
71
# File 'lib/fog/aws/models/ec2/server.rb', line 69

def flavor
  @flavor ||= connection.flavors.all.detect {|flavor| flavor.id == @flavor_id}
end

#flavor=(new_flavor) ⇒ Object


65
66
67
# File 'lib/fog/aws/models/ec2/server.rb', line 65

def flavor=(new_flavor)
  @flavor = new_flavor
end

#flavor_idObject

def security_group

connection.security_groups.all(@group_id)

end

def security_group=(new_security_group)

@group_id = new_security_group.name

end


61
62
63
# File 'lib/fog/aws/models/ec2/server.rb', line 61

def flavor_id
  @flavor && @flavor.id || @flavor_id
end

#key_pairObject


73
74
75
76
77
# File 'lib/fog/aws/models/ec2/server.rb', line 73

def key_pair
  requires :key_name

  connection.keypairs.all(@key_name).first
end

#key_pair=(new_keypair) ⇒ Object


79
80
81
# File 'lib/fog/aws/models/ec2/server.rb', line 79

def key_pair=(new_keypair)
  @key_name = new_keypair.name
end

#monitoring=(new_monitoring) ⇒ Object


83
84
85
86
87
88
89
# File 'lib/fog/aws/models/ec2/server.rb', line 83

def monitoring=(new_monitoring)
  if new_monitoring.is_a?(Hash)
    @monitoring = new_monitoring['state']
  else
    @monitoring = new_monitoring
  end
end

#placement=(new_placement) ⇒ Object


91
92
93
94
95
96
97
# File 'lib/fog/aws/models/ec2/server.rb', line 91

def placement=(new_placement)
  if new_placement.is_a?(Hash)
    @availability_zone = new_placement['availabilityZone']
  else
    @availability_zone = new_placement
  end
end

#ready?Boolean

Returns:

  • (Boolean)

99
100
101
# File 'lib/fog/aws/models/ec2/server.rb', line 99

def ready?
  @state == 'running'
end

#rebootObject


103
104
105
106
107
# File 'lib/fog/aws/models/ec2/server.rb', line 103

def reboot
  requires :id
  connection.reboot_instances(@id)
  true
end

#saveObject


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fog/aws/models/ec2/server.rb', line 109

def save
  requires :image_id

  options = {'InstanceType' => flavor.id}
  if @availability_zone
    options['Placement.AvailabilityZone'] = @availability_zone
  end
  unless @groups.empty?
    options.merge!(AWS.indexed_param("SecurityGroup", @groups))
  end
  if @kernel_id
    options['KernelId'] = @kernel_id
  end
  if @key_name
    options['KeyName'] = @key_name
  end
  if @monitoring
    options['Monitoring.Enabled'] = @monitoring
  end
  if @ramdisk_id
    options['RamdiskId'] = @ramdisk_id
  end
  if @user_data
    options['UserData'] = @user_data
  end
  data = connection.run_instances(@image_id, 1, 1, options)
  merge_attributes(data.body['instancesSet'].first)
  true
end

#volumesObject


139
140
141
142
143
# File 'lib/fog/aws/models/ec2/server.rb', line 139

def volumes
  requires :id

  connection.volumes(:server => self)
end