Class: Fog::AWS::EC2::Instance

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

Instance Method Summary collapse

Methods inherited from Model

aliases, attribute, #attributes, attributes, #collection, identity, #identity, #initialize, #inspect, #merge_attributes

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#addressesObject



25
26
27
# File 'lib/fog/aws/models/ec2/instance.rb', line 25

def addresses
  connection.addresses(:instance => self)
end

#destroyObject



29
30
31
32
# File 'lib/fog/aws/models/ec2/instance.rb', line 29

def destroy
  connection.terminate_instances(@instance_id)
  true
end

#instancesObject



50
51
52
# File 'lib/fog/aws/models/ec2/instance.rb', line 50

def instances
  @instances
end

#key_pairObject

def security_group

connection.security_groups.all(@group_id)

end

def security_group=(new_security_group)

@group_id = new_security_group.name

end



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

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

#key_pair=(new_keypair) ⇒ Object



46
47
48
# File 'lib/fog/aws/models/ec2/instance.rb', line 46

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

#monitoring=(new_monitoring) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/fog/aws/models/ec2/instance.rb', line 54

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

#placement=(new_placement) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/fog/aws/models/ec2/instance.rb', line 62

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

#reloadObject



70
71
72
73
74
# File 'lib/fog/aws/models/ec2/instance.rb', line 70

def reload
  if new_instance = instances.get(@instance_id)
    merge_attributes(new_instance.attributes)
  end
end

#saveObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/aws/models/ec2/instance.rb', line 76

def save
  options = {}
  if @availability_zone
    options['Placement.AvailabilityZone'] = @availability_zone
  end
  if @group_id
    options['groupId'] = @group_id
  end
  if @instance_type
    options['InstanceType'] = @instance_type
  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



107
108
109
# File 'lib/fog/aws/models/ec2/instance.rb', line 107

def volumes
  connection.volumes(:instance => self)
end