lorj_cloud 0.1.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/.gitreview +4 -0
- data/.rspec +2 -0
- data/.rubocop.yml +46 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +43 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/data.yaml +0 -0
- data/lib/defaults.yaml +0 -0
- data/lib/lorj_cloud/version.rb +4 -0
- data/lib/lorj_cloud.rb +6 -0
- data/lib/process/cloud/process/common.rb +60 -0
- data/lib/process/cloud/process/connection.rb +92 -0
- data/lib/process/cloud/process/external_network.rb +90 -0
- data/lib/process/cloud/process/flavor.rb +97 -0
- data/lib/process/cloud/process/images.rb +99 -0
- data/lib/process/cloud/process/internet_network.rb +33 -0
- data/lib/process/cloud/process/internet_server.rb +29 -0
- data/lib/process/cloud/process/keypairs.rb +332 -0
- data/lib/process/cloud/process/network.rb +107 -0
- data/lib/process/cloud/process/public_ip.rb +106 -0
- data/lib/process/cloud/process/router.rb +267 -0
- data/lib/process/cloud/process/rules.rb +120 -0
- data/lib/process/cloud/process/security_groups.rb +120 -0
- data/lib/process/cloud/process/server.rb +127 -0
- data/lib/process/cloud/process/server_log.rb +34 -0
- data/lib/process/cloud/process/subnetwork.rb +96 -0
- data/lib/process/cloud_process.rb +30 -0
- data/lib/providers/hpcloud/compute.rb +105 -0
- data/lib/providers/hpcloud/hpcloud.rb +463 -0
- data/lib/providers/hpcloud/network.rb +115 -0
- data/lib/providers/hpcloud/security_groups.rb +68 -0
- data/lib/providers/mock/mock.rb +144 -0
- data/lib/providers/openstack/openstack.rb +410 -0
- data/lib/providers/openstack/openstack_create.rb +206 -0
- data/lib/providers/openstack/openstack_delete.rb +28 -0
- data/lib/providers/openstack/openstack_get.rb +39 -0
- data/lib/providers/openstack/openstack_process.rb +26 -0
- data/lib/providers/openstack/openstack_query.rb +96 -0
- data/lib/providers/openstack/openstack_update.rb +35 -0
- data/lib/providers/templates/compute.rb +40 -0
- data/lib/providers/templates/mycloud.rb +72 -0
- data/lib/providers/templates/network.rb +32 -0
- data/lorj_cloud.gemspec +32 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4233f4744a02510e08773415b97e9e2c1d22a573
|
4
|
+
data.tar.gz: 65f7e65ab5b524739d081bfd6fac667a0b92e815
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6942511c15d7ca200f7994f3e78db471cc1d051aef996d68118694e2512e6decae0310f14b1b470aa725cc3079cdeaf5b037d5986f0db54d6e5afcd8a2c748f2
|
7
|
+
data.tar.gz: b6e027ec8f848aec4be5ad2bd8a241c2f1e65699bcf5234b0c815b85f2979230336b0960503deb2dd442e8a114d21e4d7267a164ab50d84571ab99475c5400f5
|
data/.gitignore
ADDED
data/.gitreview
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# use: rubocop --show-cops
|
16
|
+
# to validate configuration.
|
17
|
+
# rubocop config
|
18
|
+
AllCops:
|
19
|
+
Include:
|
20
|
+
- '**/Rakefile'
|
21
|
+
- '**/config.ru'
|
22
|
+
Exclude:
|
23
|
+
- 'docker/**/*'
|
24
|
+
- 'bin/scripts/**/*'
|
25
|
+
- 'git/**/*'
|
26
|
+
- 'tmp/**/*'
|
27
|
+
#Documentation:
|
28
|
+
# Enabled: false
|
29
|
+
#Metrics/LineLength:
|
30
|
+
# Max: 99
|
31
|
+
Style/HashSyntax:
|
32
|
+
EnforcedStyle: hash_rockets
|
33
|
+
|
34
|
+
# lets start with 40, but 10 is way to small..
|
35
|
+
Metrics/MethodLength:
|
36
|
+
Max: 40
|
37
|
+
# If Method length is increased, class length need to be extended as well.
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Max: 150
|
40
|
+
|
41
|
+
# allow arguments to be longer than 15
|
42
|
+
Metrics/AbcSize:
|
43
|
+
Max: 40
|
44
|
+
# forj-docker binary name gets an exception
|
45
|
+
Style/FileName:
|
46
|
+
Exclude: ['bin/forj-docker', 'lib/**/forj-docker.rb']
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# LorjCloud
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/lorj_cloud`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'lorj_cloud'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install lorj_cloud
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/lorj_cloud/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
require 'rspec/core/rake_task'
|
19
|
+
require 'rubocop/rake_task'
|
20
|
+
require 'rdoc/task'
|
21
|
+
|
22
|
+
task :default => [:lint, :spec]
|
23
|
+
|
24
|
+
desc 'Generate lorj documentation'
|
25
|
+
RDoc::Task.new do |rdoc|
|
26
|
+
rdoc.main = 'README.md'
|
27
|
+
rdoc.rdoc_files.include('README.md', 'lib', 'example', 'bin')
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Run the specs.'
|
31
|
+
RSpec::Core::RakeTask.new do |t|
|
32
|
+
t.pattern = 'spec/*_spec.rb'
|
33
|
+
t.rspec_opts = '-f doc'
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Run RuboCop on the project'
|
37
|
+
RuboCop::RakeTask.new(:lint) do |task|
|
38
|
+
task.formatters = ['progress']
|
39
|
+
task.verbose = true
|
40
|
+
task.fail_on_error = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :build => [:lint, :spec]
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'lorj_cloud'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/data.yaml
ADDED
File without changes
|
data/lib/defaults.yaml
ADDED
File without changes
|
data/lib/lorj_cloud.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
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
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
19
|
+
|
20
|
+
# Common definition
|
21
|
+
class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
|
22
|
+
# All objects used by this process are built from a Controller
|
23
|
+
process_default :use_controller => true
|
24
|
+
end
|
25
|
+
|
26
|
+
# Class to manage retry on errors before failing
|
27
|
+
class SSLErrorMgt
|
28
|
+
def initialize(iMaxRetry = 5)
|
29
|
+
@retry = 0
|
30
|
+
@max_retry = iMaxRetry
|
31
|
+
end
|
32
|
+
|
33
|
+
def wait(message, issue = nil)
|
34
|
+
if @retry < @max_retry
|
35
|
+
sleep(2)
|
36
|
+
@retry += 1
|
37
|
+
if PrcLib.level == 0
|
38
|
+
msg = format('%s/%s try... ', @retry, @max_retry)
|
39
|
+
msg += issue unless issue.nil?
|
40
|
+
print msg
|
41
|
+
end
|
42
|
+
return false
|
43
|
+
else
|
44
|
+
PrcLib.error('Too many retry. %s', message)
|
45
|
+
return true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def error_detected(message, backtrace, e)
|
50
|
+
if message.match('SSLv2/v3 read server hello A: unknown protocol')
|
51
|
+
return wait(message, "'unknown protocol' SSL Error")
|
52
|
+
elsif e.is_a?(Excon::Errors::InternalServerError)
|
53
|
+
return wait(message, ANSI.red(e.class))
|
54
|
+
else
|
55
|
+
PrcLib.error("Exception %s: %s\n%s", e.class, message,
|
56
|
+
backtrace.join("\n"))
|
57
|
+
return true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
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
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
19
|
+
|
20
|
+
# rubocop: disable Style/ClassAndModuleChildren
|
21
|
+
|
22
|
+
# Connection process code
|
23
|
+
class CloudProcess
|
24
|
+
def connect(sCloudObj, hParams)
|
25
|
+
ssl_error_obj = SSLErrorMgt.new # Retry object
|
26
|
+
PrcLib.debug("%s:%s Connecting to '%s' "\
|
27
|
+
"- Project '%s'",
|
28
|
+
self.class, sCloudObj, config[:provider], hParams[:tenant])
|
29
|
+
begin
|
30
|
+
controller_connect(sCloudObj)
|
31
|
+
rescue => e
|
32
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
33
|
+
|
34
|
+
PrcLib.error('%s:%s: Unable to connect.\n%s',
|
35
|
+
self.class, sCloudObj, e.message)
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Define services model
|
42
|
+
class Lorj::BaseDefinition
|
43
|
+
# predefined list of objects.
|
44
|
+
# Links between objects is not predefined. To do it, use needs declaration
|
45
|
+
# in your provider class.
|
46
|
+
|
47
|
+
# object to get list of services
|
48
|
+
# Defines Process handler to call
|
49
|
+
define_obj(:services,
|
50
|
+
|
51
|
+
:create_e => :connect
|
52
|
+
)
|
53
|
+
obj_needs :data, :auth_uri
|
54
|
+
obj_needs :data, :account_id
|
55
|
+
obj_needs :data, :account_key
|
56
|
+
obj_needs :data, :tenant
|
57
|
+
|
58
|
+
undefine_attribute :id # Do not return any predefined ID
|
59
|
+
undefine_attribute :name # Do not return any predefined NAME
|
60
|
+
end
|
61
|
+
|
62
|
+
# compute_connection
|
63
|
+
class Lorj::BaseDefinition
|
64
|
+
define_obj(:compute_connection,
|
65
|
+
|
66
|
+
:create_e => :connect # Will call ForjProcess connect
|
67
|
+
)
|
68
|
+
obj_needs :data, :account_id
|
69
|
+
obj_needs :data, :account_key
|
70
|
+
obj_needs :data, :auth_uri
|
71
|
+
obj_needs :data, :tenant
|
72
|
+
obj_needs :data, :compute
|
73
|
+
|
74
|
+
undefine_attribute :id # Do not return any predefined ID
|
75
|
+
undefine_attribute :name # Do not return any predefined NAME
|
76
|
+
end
|
77
|
+
|
78
|
+
# network_connection
|
79
|
+
class Lorj::BaseDefinition
|
80
|
+
define_obj(:network_connection,
|
81
|
+
|
82
|
+
:create_e => :connect
|
83
|
+
)
|
84
|
+
obj_needs :data, :account_id
|
85
|
+
obj_needs :data, :account_key
|
86
|
+
obj_needs :data, :auth_uri
|
87
|
+
obj_needs :data, :tenant
|
88
|
+
obj_needs :data, :network
|
89
|
+
|
90
|
+
undefine_attribute :id # Do not return any predefined ID
|
91
|
+
undefine_attribute :name # Do not return any predefined NAME
|
92
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
+
|
19
|
+
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
+
|
21
|
+
# External network process attached to a network
|
22
|
+
class CloudProcess
|
23
|
+
def forj_get_or_create_ext_net(sCloudObj, hParams)
|
24
|
+
PrcLib.state("Checking router '%s' gateway", hParams[:router, :name])
|
25
|
+
|
26
|
+
router_obj = hParams[:router]
|
27
|
+
router_name = hParams[:router, :name]
|
28
|
+
network_id = hParams[:router, :gateway_network_id]
|
29
|
+
if network_id
|
30
|
+
external_network = forj_query_external_network(sCloudObj,
|
31
|
+
{ :id => network_id },
|
32
|
+
hParams)
|
33
|
+
PrcLib.info("Router '%s' is attached to the "\
|
34
|
+
"external gateway '%s'.", router_name,
|
35
|
+
external_network[:name])
|
36
|
+
else
|
37
|
+
PrcLib.info("Router '%s' needs to be attached to an "\
|
38
|
+
'external gateway.', router_name)
|
39
|
+
PrcLib.state('Attaching')
|
40
|
+
external_network = forj_query_external_network(:network, {}, hParams)
|
41
|
+
if !external_network.empty?
|
42
|
+
router_obj[:gateway_network_id] = external_network[:id]
|
43
|
+
controller_update(:router, router_obj)
|
44
|
+
PrcLib.info("Router '%s' attached to the "\
|
45
|
+
"external network '%s'.",
|
46
|
+
router_name, external_network[:name])
|
47
|
+
else
|
48
|
+
PrcLib.fatal(1, "Unable to attach router '%s' to an external gateway. "\
|
49
|
+
'Required for boxes to get internet access. ',
|
50
|
+
get_data(:router, :name))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Need to keep the :network object as :external_network object type.
|
55
|
+
external_network.type = sCloudObj
|
56
|
+
external_network
|
57
|
+
end
|
58
|
+
|
59
|
+
def forj_query_external_network(_sCloudObj, sQuery, _hParams)
|
60
|
+
PrcLib.state('Identifying External gateway')
|
61
|
+
begin
|
62
|
+
# Searching for external network
|
63
|
+
query = sQuery.merge(:external => true)
|
64
|
+
info = {
|
65
|
+
:notfound => 'No external network found',
|
66
|
+
:checkmatch => 'Found 1 %s. Checking if it is an %s.',
|
67
|
+
:nomatch => 'No %s identified as %s match',
|
68
|
+
:found => "Found external %s '%s'.",
|
69
|
+
:more => 'Found several %s. Searching for the first one to be an %s.'
|
70
|
+
}
|
71
|
+
networks = query_single(:network, query, 'external network', info)
|
72
|
+
return Lorj::Data.new if networks.length == 0
|
73
|
+
networks[0]
|
74
|
+
rescue => e
|
75
|
+
PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Identify an external network thanks to the network router.
|
81
|
+
class Lorj::BaseDefinition
|
82
|
+
define_obj(:external_network,
|
83
|
+
|
84
|
+
:create_e => :forj_get_or_create_ext_net,
|
85
|
+
:query_e => :forj_query_external_network
|
86
|
+
)
|
87
|
+
|
88
|
+
obj_needs :CloudObject, :network_connection
|
89
|
+
obj_needs :CloudObject, :router
|
90
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
+
|
19
|
+
# ---------------------------------------------------------------------------
|
20
|
+
# flavor management
|
21
|
+
# ---------------------------------------------------------------------------
|
22
|
+
class CloudProcess
|
23
|
+
# Depending on clouds/rights, we can create flavor or not.
|
24
|
+
# Usually, flavor records already exists, and the controller may map them
|
25
|
+
# CloudProcess predefines some values. Consult CloudProcess.rb for details
|
26
|
+
def forj_get_or_create_flavor(sCloudObj, hParams)
|
27
|
+
flavor_name = hParams[:flavor_name]
|
28
|
+
PrcLib.state("Searching for flavor '%s'", flavor_name)
|
29
|
+
|
30
|
+
flavors = query_flavor(sCloudObj, { :name => flavor_name }, hParams)
|
31
|
+
if flavors.length == 0
|
32
|
+
if !hParams[:create]
|
33
|
+
PrcLib.error("Unable to create %s '%s'. Creation is not "\
|
34
|
+
'supported.', sCloudObj, flavor_name)
|
35
|
+
ForjLib::Data.new.set(nil, sCloudObj)
|
36
|
+
else
|
37
|
+
create_flavor(sCloudObj, hParams)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
flavors[0]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Should return 1 or 0 flavor.
|
45
|
+
def query_flavor(sCloudObj, sQuery, hParams)
|
46
|
+
flavor_name = hParams[:flavor_name]
|
47
|
+
# list = forj_query_flavor(sCloudObj, sQuery, hParams)
|
48
|
+
# query_single(sCloudObj, list, sQuery, flavor_name)
|
49
|
+
query_single(sCloudObj, sQuery, flavor_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Should return 1 or 0 flavor.
|
53
|
+
def forj_query_flavor(sCloudObj, sQuery, _hParams)
|
54
|
+
ssl_error_obj = SSLErrorMgt.new
|
55
|
+
begin
|
56
|
+
list = controller_query(sCloudObj, sQuery)
|
57
|
+
rescue => e
|
58
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
59
|
+
end
|
60
|
+
list
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Flavor Object
|
65
|
+
# Identify flavor
|
66
|
+
class Lorj::BaseDefinition # rubocop: disable ClassAndModuleChildren
|
67
|
+
define_obj(:flavor,
|
68
|
+
|
69
|
+
:create_e => :forj_get_or_create_flavor,
|
70
|
+
:query_e => :forj_query_flavor
|
71
|
+
# :get_e => :forj_get_flavor,
|
72
|
+
# :update_e => :forj_update_flavor,
|
73
|
+
# :delete_e => :forj_delete_flavor
|
74
|
+
)
|
75
|
+
|
76
|
+
obj_needs :CloudObject, :compute_connection
|
77
|
+
obj_needs :data, :flavor_name, :for => [:create_e]
|
78
|
+
# Cloud provider will need to map to one of those predefined flavors.
|
79
|
+
# limitation values may match exactly or at least ensure those limitation
|
80
|
+
# are under provider limitation
|
81
|
+
# ie, at least the CloudProcess limitation can less than the
|
82
|
+
# Cloud provider defines.
|
83
|
+
# CloudProcess EHD = 160, then Provider EHD = 200 is ok
|
84
|
+
# but Provider EHD = 150 is not ok.
|
85
|
+
predefine_data_value('tiny', :desc => 'VCU: 1, RAM:512M, HD:1G, '\
|
86
|
+
'EHD: 0G, Swap: 0G')
|
87
|
+
predefine_data_value('xsmall', :desc => 'VCU: 1, RAM:1G, HD:10G, '\
|
88
|
+
'EHD: 10G, Swap: 0G')
|
89
|
+
predefine_data_value('small', :desc => 'VCU: 2, RAM:2G, HD:30G, '\
|
90
|
+
'EHD: 10G, Swap: 0G')
|
91
|
+
predefine_data_value('medium', :desc => 'VCU: 2, RAM:4G, HD:30G, '\
|
92
|
+
'EHD: 50G, Swap: 0G')
|
93
|
+
predefine_data_value('large', :desc => 'VCU: 4, RAM:8G, HD:30G, '\
|
94
|
+
'EHD: 100G, Swap: 0G')
|
95
|
+
predefine_data_value('xlarge', :desc => 'VCU: 8, RAM:16G, HD:30G, '\
|
96
|
+
'EHD: 200G, Swap: 0G')
|
97
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
+
|
19
|
+
# ---------------------------------------------------------------------------
|
20
|
+
# Image management
|
21
|
+
# ---------------------------------------------------------------------------
|
22
|
+
class CloudProcess
|
23
|
+
def forj_get_or_create_image(sCloudObj, hParams)
|
24
|
+
image_name = hParams[:image_name]
|
25
|
+
PrcLib.state("Searching for image '%s'", image_name)
|
26
|
+
|
27
|
+
search_the_image(sCloudObj, { :name => image_name }, hParams)
|
28
|
+
# No creation possible.
|
29
|
+
end
|
30
|
+
|
31
|
+
def search_the_image(sCloudObj, sQuery, hParams)
|
32
|
+
image_name = hParams[:image_name]
|
33
|
+
images = forj_query_image(sCloudObj, sQuery, hParams)
|
34
|
+
case images.length
|
35
|
+
when 0
|
36
|
+
PrcLib.info("No image '%s' found", image_name)
|
37
|
+
nil
|
38
|
+
when 1
|
39
|
+
PrcLib.info("Found image '%s'.", image_name)
|
40
|
+
images[0, :ssh_user] = ssh_user(images[0, :name])
|
41
|
+
images[0]
|
42
|
+
else
|
43
|
+
PrcLib.info("Found several images '%s'. Selecting the first "\
|
44
|
+
"one '%s'", image_name, images[0, :name])
|
45
|
+
images[0, :ssh_user] = ssh_user(images[0, :name])
|
46
|
+
images[0]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def forj_query_image(sCloudObj, sQuery, _hParams)
|
51
|
+
ssl_error_obj = SSLErrorMgt.new
|
52
|
+
begin
|
53
|
+
images = controller_query(sCloudObj, sQuery)
|
54
|
+
rescue => e
|
55
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
56
|
+
end
|
57
|
+
add_ssh_user(images)
|
58
|
+
images
|
59
|
+
end
|
60
|
+
|
61
|
+
def add_ssh_user(images)
|
62
|
+
images.each do |image|
|
63
|
+
image[:ssh_user] = ssh_user(image[:name])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def ssh_user(image_name)
|
68
|
+
return 'fedora' if image_name =~ /fedora/i
|
69
|
+
return 'centos' if image_name =~ /centos/i
|
70
|
+
'ubuntu'
|
71
|
+
end
|
72
|
+
|
73
|
+
def forj_get_image(sCloudObj, sId, _hParams)
|
74
|
+
ssl_error_obj = SSLErrorMgt.new
|
75
|
+
begin
|
76
|
+
image = controller_get(sCloudObj, sId)
|
77
|
+
rescue => e
|
78
|
+
retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
|
79
|
+
end
|
80
|
+
add_ssh_user([image])
|
81
|
+
image
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# ************************************ Image Object
|
86
|
+
# Identify image
|
87
|
+
class Lorj::BaseDefinition # rubocop: disable Style/ClassAndModuleChildren
|
88
|
+
define_obj(:image,
|
89
|
+
|
90
|
+
:create_e => :forj_get_or_create_image,
|
91
|
+
:query_e => :forj_query_image,
|
92
|
+
:get_e => :forj_get_image
|
93
|
+
# :update_e => :forj_update_image
|
94
|
+
# :delete_e => :forj_delete_image
|
95
|
+
)
|
96
|
+
|
97
|
+
obj_needs :CloudObject, :compute_connection
|
98
|
+
obj_needs :data, :image_name, :for => [:create_e]
|
99
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# It requires Core objects to be defined + default ForjProcess functions.
|
18
|
+
|
19
|
+
# rubocop: disable Style/ClassAndModuleChildren
|
20
|
+
|
21
|
+
# Internet network Object
|
22
|
+
# Define Internet network
|
23
|
+
#
|
24
|
+
# This object contains the logic to ensure the router's network has a gateway
|
25
|
+
# to the external network (internet)
|
26
|
+
# is capable to connect to internet
|
27
|
+
# And to create this connection if possible.
|
28
|
+
class Lorj::BaseDefinition # rubocop: disable ClassAndModuleChildren
|
29
|
+
define_obj(:internet_network, :nohandler => true)
|
30
|
+
|
31
|
+
obj_needs :CloudObject, :external_network # External network to connect if
|
32
|
+
# needed.
|
33
|
+
end
|