Class: NCC::Connection::AWS
Overview
/* Copyright 2013 Proofpoint, Inc. All rights reserved.
Copyright 2014 Evernote Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */
Instance Attribute Summary
#fog
Instance Method Summary
collapse
#collection, #communication_error, connect, #console, #create_instance, #current?, #debug, #delete, #do_connect, #do_fog, #error, #fatal, #fields, #generic_provider_request, #generic_translate, #get_provider_object, #get_provider_objects, #host_fqdn, #id_field, #id_map, #id_map_hash, #id_of, #ids, #images, #info, #initialize, #instance_for, #instance_host, #instance_not_found, #instances, #inventory_request, #keyintern, #keyname_for, #map_from_raw_provider_id, #map_to_id, #map_to_provider_id, #maybe_invalidate, #me, #merge_configured, #modify_instance_request, #notice, #object_of, #provider_id_map, #provider_request, #reboot, #sizes, #to_s, #translate, #translated_id_of, #warn
Instance Method Details
#connection_params ⇒ Object
52
53
54
|
# File 'lib/ncc/connection/aws.rb', line 52
def connection_params
['aws_access_key_id', 'aws_secret_access_key']
end
|
#console_log(instance_id) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/ncc/connection/aws.rb', line 80
def console_log(instance_id)
begin
do_fog do |fog|
fog.get_console_output(instance_id).body
end
rescue Fog::Compute::AWS::NotFound
instance_not_found instance_id
rescue Exception => e
communication_error e.message
end
end
|
#instance_image(server) ⇒ Object
68
69
70
|
# File 'lib/ncc/connection/aws.rb', line 68
def instance_image(server)
map_from_raw_provider_id(:image, server.image_id)
end
|
#instance_ip_address(server) ⇒ Object
76
77
78
|
# File 'lib/ncc/connection/aws.rb', line 76
def instance_ip_address(server)
server.private_ip_address
end
|
#instance_name(server) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/ncc/connection/aws.rb', line 56
def instance_name(server)
if ! server.tags.nil? and server.tags.has_key? 'Name'
server.tags['Name']
else
nil
end
end
|
#instance_size(server) ⇒ Object
64
65
66
|
# File 'lib/ncc/connection/aws.rb', line 64
def instance_size(server)
map_from_raw_provider_id(:size, server.flavor_id)
end
|
#instance_status(server) ⇒ Object
72
73
74
|
# File 'lib/ncc/connection/aws.rb', line 72
def instance_status(server)
map_to_status(server.state)
end
|
#map_to_provider_status(abstract_status) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/ncc/connection/aws.rb', line 120
def map_to_provider_status(abstract_status)
case abstract_status
when 'active', 'error', 'hard-reboot', 'reboot', 'provider-operation',
'unknown', 'needs-verify'
'running'
when 'build'
'pending'
when 'terminated'
'terminated'
when 'shutting-down'
'shutting-down'
when 'suspending'
'stopping'
when 'suspend'
'stopped'
else
'running'
end
end
|
#map_to_status(aws_status) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/ncc/connection/aws.rb', line 101
def map_to_status(aws_status)
case aws_status
when 'running'
'active'
when 'pending'
'build'
when 'terminated'
'terminated'
when 'shutting-down'
'shutting-down'
when 'stopping'
'suspending'
when 'stopped'
'suspend'
else
'unknown'
end
end
|
#provider ⇒ Object
39
40
41
|
# File 'lib/ncc/connection/aws.rb', line 39
def provider
'aws'
end
|
#provider_request_of(instance) ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/ncc/connection/aws.rb', line 92
def provider_request_of(instance)
{
:name => instance.name,
:flavor_id => sizes(instance.size)['provider_id'],
:image_id => images(instance.image)['provider_id'],
:tags => { 'Name' => instance.name }
}.merge(instance. provider)
end
|
#translate_image(provider_image) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/ncc/connection/aws.rb', line 30
def translate_image(provider_image)
generic_translate(:image, provider_image).
merge({
'description' => provider_image.description,
'ramdisk_id' => provider_image.ramdisk_id,
'kernel_id' => provider_image.kernel_id
})
end
|
#translate_size(flavor) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/ncc/connection/aws.rb', line 20
def translate_size(flavor)
generic_translate(:size, flavor).
merge({
'ram' => flavor.ram,
'disk' => flavor.disk,
'cores' => flavor.cores,
'description' => flavor.name
})
end
|
#use_only_mapped(type) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/ncc/connection/aws.rb', line 43
def use_only_mapped(type)
case type
when :image
true
when :size
false
end
end
|