oraclecloud 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +202 -0
- data/README.md +208 -0
- data/Rakefile +6 -0
- data/lib/oraclecloud.rb +36 -0
- data/lib/oraclecloud/asset.rb +65 -0
- data/lib/oraclecloud/assets.rb +99 -0
- data/lib/oraclecloud/client.rb +250 -0
- data/lib/oraclecloud/exceptions.rb +36 -0
- data/lib/oraclecloud/imagelist.rb +34 -0
- data/lib/oraclecloud/imagelists.rb +45 -0
- data/lib/oraclecloud/instance.rb +79 -0
- data/lib/oraclecloud/instance_request.rb +78 -0
- data/lib/oraclecloud/instances.rb +39 -0
- data/lib/oraclecloud/ip_association.rb +36 -0
- data/lib/oraclecloud/ip_associations.rb +29 -0
- data/lib/oraclecloud/orchestration.rb +85 -0
- data/lib/oraclecloud/orchestrations.rb +61 -0
- data/lib/oraclecloud/shape.rb +42 -0
- data/lib/oraclecloud/shapes.rb +36 -0
- data/lib/oraclecloud/sshkey.rb +32 -0
- data/lib/oraclecloud/sshkeys.rb +25 -0
- data/lib/oraclecloud/version.rb +20 -0
- data/oraclecloud.gemspec +26 -0
- metadata +156 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'ffi_yajl'
|
20
|
+
|
21
|
+
module OracleCloud
|
22
|
+
module Exception
|
23
|
+
class HTTPError < RuntimeError
|
24
|
+
attr_accessor :klass, :code, :body, :error, :path
|
25
|
+
def initialize(opts = {})
|
26
|
+
@code = opts[:code]
|
27
|
+
@body = opts[:body]
|
28
|
+
@path = opts[:path]
|
29
|
+
@klass = opts[:klass]
|
30
|
+
@error = opts[:error]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class HTTPNotFound < HTTPError; end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class ImageList
|
20
|
+
attr_reader :imagelist_data
|
21
|
+
|
22
|
+
def initialize(imagelist_data)
|
23
|
+
@imagelist_data = imagelist_data
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
imagelist_data['name']
|
28
|
+
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
imagelist_data['description'].gsub(/\"/, '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class ImageLists
|
20
|
+
attr_reader :client
|
21
|
+
|
22
|
+
def initialize(client)
|
23
|
+
@client = client
|
24
|
+
end
|
25
|
+
|
26
|
+
def all
|
27
|
+
public_imagelists + private_imagelists
|
28
|
+
end
|
29
|
+
|
30
|
+
def public_imagelists
|
31
|
+
client.http_get(:single, '/imagelist/oracle/public/')['result'].each_with_object([]) do |imagelist, memo|
|
32
|
+
memo << OracleCloud::ImageList.new(imagelist)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def private_imagelists
|
37
|
+
# TODO: tracked in PE-47
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
|
41
|
+
def exist?(imagelist_name)
|
42
|
+
all.any? { |x| x.name == imagelist_name }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class Instance < Asset
|
20
|
+
def local_init
|
21
|
+
@asset_type = 'instance'
|
22
|
+
end
|
23
|
+
|
24
|
+
def id
|
25
|
+
strip_identity_domain(asset_data['name'])
|
26
|
+
end
|
27
|
+
|
28
|
+
def full_name
|
29
|
+
asset_data['name']
|
30
|
+
end
|
31
|
+
|
32
|
+
def ip_address
|
33
|
+
asset_data['ip']
|
34
|
+
end
|
35
|
+
|
36
|
+
def image
|
37
|
+
asset_data['imagelist']
|
38
|
+
end
|
39
|
+
|
40
|
+
def shape
|
41
|
+
asset_data['shape']
|
42
|
+
end
|
43
|
+
|
44
|
+
def hostname
|
45
|
+
asset_data['hostname']
|
46
|
+
end
|
47
|
+
|
48
|
+
def label
|
49
|
+
asset_data['label']
|
50
|
+
end
|
51
|
+
|
52
|
+
def state
|
53
|
+
asset_data['state']
|
54
|
+
end
|
55
|
+
alias_method :status, :state
|
56
|
+
|
57
|
+
def vcable_id
|
58
|
+
asset_data['vcable_id']
|
59
|
+
end
|
60
|
+
|
61
|
+
def public_ip_addresses
|
62
|
+
client.ip_associations.find_by_vcable(vcable_id).map(&:ip_address)
|
63
|
+
end
|
64
|
+
|
65
|
+
def orchestration
|
66
|
+
orchestration = asset_data['attributes']['nimbula_orchestration']
|
67
|
+
return if orchestration.nil?
|
68
|
+
|
69
|
+
strip_identity_domain(orchestration)
|
70
|
+
end
|
71
|
+
|
72
|
+
def delete
|
73
|
+
raise 'Unable to delete instance, instance is part of orchestration ' \
|
74
|
+
"#{orchestration} - delete the orchestration instead" unless orchestration.nil?
|
75
|
+
|
76
|
+
client.asset_delete(asset_type, id)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class InstanceRequest
|
20
|
+
attr_reader :client, :opts, :name, :shape, :imagelist, :public_ip, :label, :sshkeys
|
21
|
+
def initialize(client, opts)
|
22
|
+
@client = client
|
23
|
+
@opts = opts
|
24
|
+
|
25
|
+
@name = opts[:name]
|
26
|
+
@shape = opts[:shape]
|
27
|
+
@imagelist = opts[:imagelist]
|
28
|
+
@public_ip = opts[:public_ip]
|
29
|
+
@label = opts.fetch(:label, @name)
|
30
|
+
@sshkeys = opts.fetch(:sshkeys, [])
|
31
|
+
|
32
|
+
validate_options!
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate_options!
|
36
|
+
raise ArgumentError, "The following required options are missing: #{missing_required_options.join(', ')}" unless
|
37
|
+
missing_required_options.empty?
|
38
|
+
|
39
|
+
raise ArgumentError, "#{shape} is not a valid shape" unless client.shapes.exist?(shape)
|
40
|
+
raise ArgumentError, "#{imagelist} is not a valid imagelist" unless client.imagelists.exist?(imagelist)
|
41
|
+
raise ArgumentError, 'sshkeys must be an array of key names' unless sshkeys.respond_to?(:each)
|
42
|
+
end
|
43
|
+
|
44
|
+
def missing_required_options
|
45
|
+
[ :name, :shape, :imagelist ].each_with_object([]) do |opt, memo|
|
46
|
+
memo << opt unless opts[opt]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def full_name
|
51
|
+
"#{client.compute_identity_domain}/#{client.username}/#{name}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def nat
|
55
|
+
return unless public_ip
|
56
|
+
(public_ip == :pool) ? 'ippool:/oracle/public/ippool' : "ipreservation:#{public_ip}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def networking
|
60
|
+
networking = {}
|
61
|
+
networking['eth0'] = {}
|
62
|
+
networking['eth0']['nat'] = nat unless nat.nil?
|
63
|
+
|
64
|
+
networking
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_h
|
68
|
+
{
|
69
|
+
'shape' => shape,
|
70
|
+
'label' => label,
|
71
|
+
'imagelist' => imagelist,
|
72
|
+
'name' => full_name,
|
73
|
+
'sshkeys' => sshkeys,
|
74
|
+
'networking' => networking
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class Instances < Assets
|
20
|
+
def local_init
|
21
|
+
@asset_type = 'instance'
|
22
|
+
@asset_klass = OracleCloud::Instance
|
23
|
+
end
|
24
|
+
|
25
|
+
def instance_id_by_name(container, name)
|
26
|
+
directory("#{container}/#{name}").first
|
27
|
+
end
|
28
|
+
|
29
|
+
def all
|
30
|
+
all_asset_ids_by_container.each_with_object([]) do |(container, instance_names), memo|
|
31
|
+
instance_names.each do |instance_name|
|
32
|
+
id = instance_id_by_name(container, instance_name)
|
33
|
+
path = "#{container}/#{instance_name}/#{id}"
|
34
|
+
memo << OracleCloud::Instance.new(client, path)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class IPAssociation < Asset
|
20
|
+
def local_init
|
21
|
+
@asset_type = 'ip/association'
|
22
|
+
end
|
23
|
+
|
24
|
+
def vcable_id
|
25
|
+
asset_data['vcable']
|
26
|
+
end
|
27
|
+
|
28
|
+
def ip_address
|
29
|
+
asset_data['ip']
|
30
|
+
end
|
31
|
+
|
32
|
+
def reservation_id
|
33
|
+
asset_data['reservation'].split('/').last
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class IPAssociations < Assets
|
20
|
+
def local_init
|
21
|
+
@asset_type = 'ip/association'
|
22
|
+
@asset_klass = OracleCloud::IPAssociation
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_vcable(vcable_id)
|
26
|
+
all.select { |x| x.vcable_id == vcable_id }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chef Partner Engineering (<partnereng@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
module OracleCloud
|
19
|
+
class Orchestration < Asset
|
20
|
+
def local_init
|
21
|
+
@asset_type = 'orchestration'
|
22
|
+
end
|
23
|
+
|
24
|
+
def status
|
25
|
+
asset_data['status']
|
26
|
+
end
|
27
|
+
|
28
|
+
def description
|
29
|
+
asset_data['description']
|
30
|
+
end
|
31
|
+
|
32
|
+
def start
|
33
|
+
return if %w(starting ready).include?(status)
|
34
|
+
|
35
|
+
client.asset_put(asset_type, "#{name_with_container}?action=START")
|
36
|
+
refresh
|
37
|
+
end
|
38
|
+
|
39
|
+
def stop
|
40
|
+
return if status == 'stopped'
|
41
|
+
|
42
|
+
client.asset_put(asset_type, "#{name_with_container}?action=STOP")
|
43
|
+
refresh
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete
|
47
|
+
client.asset_delete(asset_type, name_with_container)
|
48
|
+
end
|
49
|
+
|
50
|
+
def launch_plan
|
51
|
+
return if asset_data['oplans'].nil?
|
52
|
+
|
53
|
+
asset_data['oplans'].find { |x| x['obj_type'] == 'launchplan' }
|
54
|
+
end
|
55
|
+
|
56
|
+
def instance_records
|
57
|
+
return [] if launch_plan.nil? || launch_plan['objects'].nil?
|
58
|
+
|
59
|
+
instance_object = launch_plan['objects'].find { |x| x.respond_to?(:key?) && x.key?('instances') }
|
60
|
+
return [] if instance_object.nil?
|
61
|
+
|
62
|
+
instance_object['instances'].select { |x| x.key?('state') }
|
63
|
+
end
|
64
|
+
|
65
|
+
def instances
|
66
|
+
return [] if instance_records.nil?
|
67
|
+
|
68
|
+
instance_records.map { |x| client.instances.by_name(x['name']) }
|
69
|
+
end
|
70
|
+
|
71
|
+
def instance_count
|
72
|
+
instance_records.count
|
73
|
+
end
|
74
|
+
|
75
|
+
def error?
|
76
|
+
status == 'error'
|
77
|
+
end
|
78
|
+
|
79
|
+
def errors
|
80
|
+
return [] unless launch_plan.key?('info') && launch_plan['info'].key?('errors')
|
81
|
+
|
82
|
+
launch_plan['info']['errors'].values
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|