Class: Serverspec::Type::AWS::EC2::Instance

Inherits:
Base
  • Object
show all
Defined in:
lib/resources/ec2/instance.rb

Overview

The Instance class exposes the EC2::Instance resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_id_name, instance = nil) ⇒ Instance

AWS SDK for Ruby v2 Aws::EC2::Client wrapper for initializing an Instance resource

Parameters:

  • instance_id_name (String)

    The ID or Name tag of the Instance

  • instance (Class) (defaults to: nil)

    Aws::EC2::Client instance

Raises:

  • (RuntimeError)

    if instance_id_name.nil?

  • (RuntimeError)

    if instance_id_name.length == 0

  • (RuntimeError)

    if instance_id_name.length > 1



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/resources/ec2/instance.rb', line 20

def initialize(instance_id_name, instance = nil)
  check_init_arg 'instance_id_name', 'EC2::instance', instance_id_name
  @aws = instance.nil? ? Aws::EC2::Client.new : instance
  if instance_id_name.match(/^i-[A-Fa-f0-9]{8}$/).nil?
    @instance_name = instance_id_name
    get_instance_by_name instance_id_name
  else
    @instance_id = instance_id_name
    get_instance_by_id instance_id_name
  end
end

Instance Attribute Details

#instance_idObject (readonly)

The ID of the Instance



9
10
11
# File 'lib/resources/ec2/instance.rb', line 9

def instance_id
  @instance_id
end

#instance_nameObject (readonly)

The Name tag of the Instance (if available)



11
12
13
# File 'lib/resources/ec2/instance.rb', line 11

def instance_name
  @instance_name
end

Instance Method Details

#architectureString

The architecture of the image

Returns:

  • (String)


145
146
147
# File 'lib/resources/ec2/instance.rb', line 145

def architecture
  @instance.architecture
end

#block_device_mappingsArray(Hash)

Any block device mappings for the Instance

Returns:

  • (Array(Hash))


164
165
166
# File 'lib/resources/ec2/instance.rb', line 164

def block_device_mappings
  @instance.block_device_mappings
end

#ebs_optimized?Boolean

Specifies whether the Instance is optimized for EBS I/O

Returns:

  • (Boolean)


61
62
63
# File 'lib/resources/ec2/instance.rb', line 61

def ebs_optimized?
  @instance.ebs_optimized
end

#enhanced_networked?Boolean

Specifies whether enhanced networking is enabled

Returns:

  • (Boolean)


66
67
68
# File 'lib/resources/ec2/instance.rb', line 66

def enhanced_networked?
  @instance.sriov_net_support == 'simple'
end

#hypervisorString

The hypervisor type of the Instance

Returns:

  • (String)


194
195
196
# File 'lib/resources/ec2/instance.rb', line 194

def hypervisor
  @instance.hypervisor
end

#iam_instance_profileHash

The IAM Instance profile associtated with the Instance

Returns:

  • (Hash)


206
207
208
# File 'lib/resources/ec2/instance.rb', line 206

def iam_instance_profile
  @instance.iam_instance_profile
end

#image_idString

The ID of the AMI used to launch the Instance

Returns:

  • (String)


72
73
74
# File 'lib/resources/ec2/instance.rb', line 72

def image_id
  @instance.image_id
end

#instance_lifecycleString

Indicates whether this is a spot Instance

Returns:

  • (String)


176
177
178
# File 'lib/resources/ec2/instance.rb', line 176

def instance_lifecycle
  @instance.instance_lifecycle
end

#instance_typeString

The Instance type

Returns:

  • (String)


96
97
98
# File 'lib/resources/ec2/instance.rb', line 96

def instance_type
  @instance.instance_type
end

#kernel_idString

The kernel associtated to this Instance

Returns:

  • (String)


109
110
111
# File 'lib/resources/ec2/instance.rb', line 109

def kernel_id
  @instance.kernel_id
end

#key_nameString

The name of the key pair

Returns:

  • (String)


90
91
92
# File 'lib/resources/ec2/instance.rb', line 90

def key_name
  @instance.key_name
end

#monitoring_enabled?Boolean

Indicates whether the monitoring is enabled for the Instance

Returns:

  • (Boolean)


45
46
47
# File 'lib/resources/ec2/instance.rb', line 45

def monitoring_enabled?
  @instance.monitoring.state == 'enabled'
end

#network_interfacesArray(Hash)

One or more NetworkInterfaces for the Instance

Returns:

  • (Array(Hash))


200
201
202
# File 'lib/resources/ec2/instance.rb', line 200

def network_interfaces
  @instance.network_interfaces
end

#on_windows?Boolean

Returns true if the platform is Windows

Returns:

  • (Boolean)


50
51
52
# File 'lib/resources/ec2/instance.rb', line 50

def on_windows?
  @instance.platform.casecmp('windows').zero?
end

#placementHash

The location where the Instance launched. Indicates the availability zone, the placement group, and the Instance tenancy

Returns:

  • (Hash)


103
104
105
# File 'lib/resources/ec2/instance.rb', line 103

def placement
  @instance.placement
end

#private_dns_nameString

The private DNS name assigned to the Instance

Returns:

  • (String)


78
79
80
# File 'lib/resources/ec2/instance.rb', line 78

def private_dns_name
  @instance.private_dns_name
end

#private_ip_addressString

The private IP address assigned to the Instance

Returns:

  • (String)


133
134
135
# File 'lib/resources/ec2/instance.rb', line 133

def private_ip_address
  @instance.private_ip_address
end

#public_dns_nameString

The public DNS name assigned to the Instance

Returns:

  • (String)


84
85
86
# File 'lib/resources/ec2/instance.rb', line 84

def public_dns_name
  @instance.public_dns_name
end

#public_ip_addressString

The public IP address assigned to the Instance

Returns:

  • (String)


139
140
141
# File 'lib/resources/ec2/instance.rb', line 139

def public_ip_address
  @instance.public_ip_address
end

#ramdisk_idString

The RAM disk associtated to this Instance

Returns:

  • (String)


115
116
117
# File 'lib/resources/ec2/instance.rb', line 115

def ramdisk_id
  @instance.ramdisk_id
end

#root_device_nameString

The root device name (eg: /dev/sda1, /dev/xvda1)

Returns:

  • (String)


158
159
160
# File 'lib/resources/ec2/instance.rb', line 158

def root_device_name
  @instance.root_device_name
end

#root_device_typeString

The root device type used by the AMI. It can be an EBS volume or Instance store

Returns:

  • (String)


152
153
154
# File 'lib/resources/ec2/instance.rb', line 152

def root_device_type
  @instance.root_device_type
end

#running?Boolean

Returns true if the Instance state is 'running'

Returns:

  • (Boolean)


40
41
42
# File 'lib/resources/ec2/instance.rb', line 40

def running?
  @instance.state.name == 'running'
end

#security_groupsArray(Hash)

One or more SecurityGroups for the Instance

Returns:

  • (Array(Hash))


188
189
190
# File 'lib/resources/ec2/instance.rb', line 188

def security_groups
  @instance.security_groups
end

#source_dest_checked?Boolean

Specifies whether the Instance launched in a VPC is able to perform NAT. The value must be false for the Instance to perform NAT

Returns:

  • (Boolean)


56
57
58
# File 'lib/resources/ec2/instance.rb', line 56

def source_dest_checked?
  @instance.source_dest_check
end

#subnet_idString

The ID of the subnet in which the Instance is running

Returns:

  • (String)


121
122
123
# File 'lib/resources/ec2/instance.rb', line 121

def subnet_id
  @instance.subnet_id
end

#tagsArray(Hash)

Any tags assigned to the Instance

Returns:

  • (Array(Hash))


182
183
184
# File 'lib/resources/ec2/instance.rb', line 182

def tags
  @instance.tags
end

#to_sString

Returns the string representation of EC2::Instance

Returns:

  • (String)


34
35
36
37
# File 'lib/resources/ec2/instance.rb', line 34

def to_s
  return "EC2 Instance ID: #{@instance_id}" if @instance_name.nil?
  "EC2 Instance ID: #{@instance_id}; Name: #{@instance_name}"
end

#virtualization_typeString

The virtualization type of the Instance, whether is HVM or PV

Returns:

  • (String)


170
171
172
# File 'lib/resources/ec2/instance.rb', line 170

def virtualization_type
  @instance.virtualization_type
end

#vpc_idString

The ID of the VPC in which the Instance is running

Returns:

  • (String)


127
128
129
# File 'lib/resources/ec2/instance.rb', line 127

def vpc_id
  @instance.vpc_id
end