lorj 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +46 -0
  4. data/Gemfile +15 -15
  5. data/README.md +22 -17
  6. data/Rakefile +12 -2
  7. data/bin/cloud_test.rb +13 -65
  8. data/example/students_1/process/students.rb +39 -0
  9. data/example/students_1/students.rb +22 -5
  10. data/example/students_2/process/students.rb +48 -0
  11. data/example/students_2/students.rb +39 -16
  12. data/example/students_3/controller/yaml_students.rb +50 -43
  13. data/example/students_3/controller/yaml_students_controller.rb +100 -87
  14. data/example/students_3/process/students.rb +161 -97
  15. data/example/students_3/students.rb +85 -56
  16. data/example/yaml_students/students.rb +40 -40
  17. data/example/yaml_students/yaml_students.rb +103 -90
  18. data/lib/core/core.rb +356 -696
  19. data/lib/core/core_controller.rb +227 -0
  20. data/lib/core/core_internal.rb +339 -0
  21. data/lib/core/core_model.rb +328 -0
  22. data/lib/core/core_object_data.rb +330 -0
  23. data/lib/core/core_object_params.rb +230 -0
  24. data/lib/core/core_process.rb +391 -0
  25. data/lib/core/core_process_setup.rb +353 -0
  26. data/lib/core/core_setup_ask.rb +241 -0
  27. data/lib/core/core_setup_encrypt.rb +146 -0
  28. data/lib/core/core_setup_init.rb +229 -0
  29. data/lib/core/core_setup_list.rb +160 -0
  30. data/lib/core/definition.rb +647 -469
  31. data/lib/core/definition_internal.rb +264 -308
  32. data/lib/core/lorj_basecontroller.rb +95 -0
  33. data/lib/core/lorj_basedefinition.rb +307 -0
  34. data/lib/core/lorj_baseprocess.rb +265 -0
  35. data/lib/core/lorj_data.rb +583 -0
  36. data/lib/core/lorj_keypath.rb +119 -0
  37. data/lib/core_process/cloud/process/common.rb +63 -0
  38. data/lib/core_process/cloud/process/connection.rb +93 -0
  39. data/lib/core_process/cloud/process/external_network.rb +94 -0
  40. data/lib/core_process/cloud/process/flavor.rb +99 -0
  41. data/lib/core_process/cloud/process/images.rb +87 -0
  42. data/lib/core_process/cloud/process/internet_network.rb +34 -0
  43. data/lib/core_process/cloud/process/internet_server.rb +30 -0
  44. data/lib/core_process/cloud/process/keypairs.rb +276 -0
  45. data/lib/core_process/cloud/process/network.rb +108 -0
  46. data/lib/core_process/cloud/process/public_ip.rb +100 -0
  47. data/lib/core_process/cloud/process/router.rb +260 -0
  48. data/lib/core_process/cloud/process/rules.rb +120 -0
  49. data/lib/core_process/cloud/process/security_groups.rb +121 -0
  50. data/lib/core_process/cloud/process/server.rb +127 -0
  51. data/lib/core_process/cloud/process/server_log.rb +35 -0
  52. data/lib/core_process/cloud/process/subnetwork.rb +108 -0
  53. data/lib/core_process/cloud_process.rb +30 -0
  54. data/lib/logging.rb +298 -0
  55. data/lib/lorj/version.rb +18 -1
  56. data/lib/lorj.rb +58 -18
  57. data/lib/lorj_account.rb +556 -0
  58. data/lib/lorj_config.rb +468 -0
  59. data/lib/lorj_defaults.rb +278 -0
  60. data/lib/prc.rb +136 -104
  61. data/lib/prc_base_config.rb +285 -0
  62. data/lib/prc_core_config.rb +878 -0
  63. data/lib/prc_section_config.rb +57 -0
  64. data/lib/providers/hpcloud/compute.rb +81 -93
  65. data/lib/providers/hpcloud/hpcloud.rb +462 -0
  66. data/lib/providers/hpcloud/network.rb +96 -98
  67. data/lib/providers/hpcloud/security_groups.rb +41 -40
  68. data/lib/providers/mock/mock.rb +144 -0
  69. data/lib/providers/openstack/openstack.rb +45 -0
  70. data/lib/providers/templates/compute.rb +21 -23
  71. data/lib/providers/templates/mycloud.rb +72 -0
  72. data/lib/providers/templates/network.rb +11 -12
  73. data/lib/rh.rb +339 -0
  74. data/lorj-spec/defaults.yaml +4 -0
  75. data/lorj.gemspec +6 -0
  76. data/spec/00_lorj_log_spec.rb +53 -0
  77. data/spec/01_hash_rh_spec.rb +243 -0
  78. data/spec/02_prc_base_config_spec.rb +216 -0
  79. data/spec/04_prc_core_config_spec.rb +83 -0
  80. data/spec/11_lorj_config_spec.rb +263 -0
  81. data/spec/12_lorj_account_spec.rb +181 -0
  82. metadata +76 -28
  83. data/Gemfile.lock +0 -37
  84. data/example/students_1/process/Students.rb +0 -20
  85. data/example/students_2/process/Students.rb +0 -27
  86. data/example/students_4/controller/yaml_students.rb +0 -82
  87. data/example/students_4/controller/yaml_students_controller.rb +0 -141
  88. data/example/students_4/process/students.rb +0 -112
  89. data/example/students_4/students.rb +0 -103
  90. data/lib/core/lorj-basecontroller.rb +0 -90
  91. data/lib/core/lorj-basedefinition.rb +0 -1139
  92. data/lib/core/lorj-baseprocess.rb +0 -236
  93. data/lib/core/lorj-data.rb +0 -567
  94. data/lib/core/lorj-keypath.rb +0 -115
  95. data/lib/core_process/CloudProcess.rb +0 -337
  96. data/lib/core_process/global_process.rb +0 -502
  97. data/lib/core_process/network_process.rb +0 -605
  98. data/lib/prc-account.rb +0 -339
  99. data/lib/prc-config.rb +0 -1030
  100. data/lib/prc-logging.rb +0 -261
  101. data/lib/providers/hpcloud/Hpcloud.rb +0 -426
  102. data/lib/providers/mock/Mock.rb +0 -141
  103. data/lib/providers/openstack/Openstack.rb +0 -47
  104. data/lib/providers/templates/core.rb +0 -61
  105. data/spec/forj-account_spec.rb +0 -75
  106. data/spec/forj-config_spec.rb +0 -196
@@ -14,54 +14,55 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ # HPCloud security groups
17
18
  module HPSecurityGroups
18
- def HPSecurityGroups.query_sg(oNetworkConnect, sQuery)
19
- oNetworkConnect.security_groups.all(sQuery)
20
- end
19
+ def self.query_sg(oNetworkConnect, sQuery)
20
+ oNetworkConnect.security_groups.all(sQuery)
21
+ end
21
22
 
22
- def HPSecurityGroups.create_sg(oNetwork, name, description)
23
- params = {:name => name}
24
- params[:description] = description if description
25
- oNetwork.security_groups.create( params )
26
- end
23
+ def self.create_sg(oNetwork, name, description)
24
+ params = { :name => name }
25
+ params[:description] = description if description
26
+ oNetwork.security_groups.create(params)
27
+ end
27
28
 
28
- def HPSecurityGroups.create_rule(oNetwork, hData)
29
- oNetwork.security_group_rules.create( hData )
30
- end
29
+ def self.create_rule(oNetwork, hData)
30
+ oNetwork.security_group_rules.create(hData)
31
+ end
31
32
 
32
- def HPSecurityGroups.query_rule(oNetwork, sQuery)
33
- oNetwork.security_group_rules.all(sQuery)
34
- end
33
+ def self.query_rule(oNetwork, sQuery)
34
+ oNetwork.security_group_rules.all(sQuery)
35
+ end
35
36
 
36
- def HPSecurityGroups.delete_rule(oNetwork, rule_id)
37
- oNetwork.security_group_rules.get(rule_id).destroy
38
- end
37
+ def self.delete_rule(oNetwork, rule_id)
38
+ oNetwork.security_group_rules.get(rule_id).destroy
39
+ end
39
40
  end
40
41
 
42
+ # HPCloud keypairs
41
43
  module HPKeyPairs
42
- def HPKeyPairs.query_keypair(oComputeConnect, sQuery)
43
- cKeyPairs = oComputeConnect.key_pairs.all()
44
- aResults = []
45
- cKeyPairs.each { |sElem|
46
- bSelect = true
47
- attributes = sElem.instance_variable_get(:@attributes)
48
- sQuery.each { | key, value |
49
- if attributes[key] != value
50
- bSelect = false
51
- break
52
- end
53
- }
54
- aResults.push sElem if bSelect
55
- }
56
- aResults
57
- end
44
+ def self.query_keypair(oComputeConnect, sQuery)
45
+ keypairs = oComputeConnect.key_pairs.all
46
+ results = []
47
+ keypairs.each do |sElem|
48
+ is_selected = true
49
+ attributes = sElem.instance_variable_get(:@attributes)
50
+ sQuery.each do | key, value |
51
+ if attributes[key] != value
52
+ is_selected = false
53
+ break
54
+ end
55
+ end
56
+ results.push sElem if is_selected
57
+ end
58
+ results
59
+ end
58
60
 
59
- def HPKeyPairs.get_keypair(oComputeConnect, sId)
60
- #byebug
61
- oComputeConnect.key_pairs.get(sId)
62
- end
61
+ def self.get_keypair(oComputeConnect, sId)
62
+ oComputeConnect.key_pairs.get(sId)
63
+ end
63
64
 
64
- def HPKeyPairs.create_keypair(oComputeConnect, name, pubkey)
65
- oComputeConnect.key_pairs.create( :name => name, :public_key => pubkey)
66
- end
65
+ def self.create_keypair(oComputeConnect, name, pubkey)
66
+ oComputeConnect.key_pairs.create(:name => name, :public_key => pubkey)
67
+ end
67
68
  end
@@ -0,0 +1,144 @@
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
+ # This class describes how to process some actions, and will do everything prior
18
+ # this task to make it to work.
19
+
20
+ # This Mock controller keep the data in memory in hash/Array data.
21
+ class Mock
22
+ # mock do not need to use any mapping. It adapts itself to what the process
23
+ # has defined.
24
+ end
25
+
26
+ # This Mock controller keep the data in memory in hash/Array data.
27
+ class MockController
28
+ @@data = {} # rubocop: disable ClassVars
29
+
30
+ def create(sObjectType, hParams)
31
+ PrcLib.debug("Mock: create object '%s' with parameters (hdata) '%s'",
32
+ sObjectType, hParams[:hdata])
33
+
34
+ result = {}
35
+ hParams[].keys.each do |key|
36
+ next if key == :hdata
37
+ result[key] = hParams[key]
38
+ end
39
+ result.merge!(hParams[:hdata])
40
+
41
+ @@data[sObjectType] = [] unless @@data.key?(sObjectType)
42
+
43
+ array = @@data[sObjectType]
44
+
45
+ array.each do | value |
46
+ fail if value.key?(result[:name])
47
+ end
48
+ array << result
49
+
50
+ result[:id] = array.length - 1
51
+
52
+ # Typical code:
53
+ # ~ case sObjectType
54
+ # ~ when :public_ip
55
+ # Following function can be executed to ensure the object :connection exists
56
+ # ~ required?(hParams, :connection)
57
+ # ~ required?(hParams, :server)
58
+ # ~ ... CODE to create
59
+ # ~ else
60
+ # ~ controller_error "'%s' is not a valid object for 'create'", sObjectType
61
+ # ~ end
62
+ # The code should return some data
63
+ # This data will be encapsulated in Lorj::Data object.
64
+ # data will be extracted by the framework with the controller get_attr
65
+ # function and mapped.
66
+ PrcLib.debug("Mock: object '%s' = '%s' is created.", sObjectType, result)
67
+ result
68
+ end
69
+
70
+ # This function return a collection which have to provide:
71
+ # functions: [], length, each
72
+ # Used by network process.
73
+ def query(sObjectType, sQuery, hParams)
74
+ PrcLib.debug("Mock: query object '%s' with hdata '%s' using query '%s'",
75
+ sObjectType, hParams[:hdata], sQuery)
76
+
77
+ return [] unless @@data.key?(sObjectType)
78
+
79
+ result = []
80
+
81
+ @@data[sObjectType].each do | value |
82
+ elem = value
83
+ sQuery.each do | query_key, query_value |
84
+ elem = nil if !value.key?(query_key) || value[query_key] != query_value
85
+ end
86
+ result << elem if elem
87
+ end
88
+ result
89
+ end
90
+
91
+ def delete(sObjectType, hParams)
92
+ PrcLib.debug("Mock: delete object '%s' with hdata '%s'",
93
+ sObjectType, hParams[:hdata])
94
+ return nil unless @@data.key?(sObjectType)
95
+
96
+ return false if !hParams.exist?(sObjectType) || hParams[sObjectType].nil?
97
+ @@data[sObjectType].delete(hParams[sObjectType])
98
+ PrcLib.debug("Mock: object '%s' = '%s' is deleted.",
99
+ sObjectType, hParams[sObjectType])
100
+ true
101
+ end
102
+
103
+ def get(sObjectType, sUniqId, hParams)
104
+ PrcLib.debug("Mock: Get object '%s' = '%s' with hdata '%s'",
105
+ sObjectType, sUniqId, hParams[:hdata])
106
+ return nil unless @@data.key?(sObjectType)
107
+ @@data[sObjectType][sUniqId]
108
+ end
109
+
110
+ def get_attr(oControlerObject, key)
111
+ # This controller function read the data and
112
+ # extract the information requested by the framework.
113
+ # Those data will be mapped to the process data model.
114
+ # The key is an array, to get data from a level tree.
115
+ # [data_l1, data_l2, data_l3] => should retrieve data from structure like
116
+ # data[ data_l2[ data_l3 ] ]
117
+ attributes = oControlerObject
118
+
119
+ attributes.rh_get(key)
120
+ rescue => e
121
+ controller_error "Unable to map '%s'.\n%s", key, e.message
122
+ end
123
+
124
+ def set_attr(oControlerObject, key, value)
125
+ attributes = oControlerObject
126
+
127
+ attributes.rh_set(value, key)
128
+ rescue => e
129
+ controller_error "Unable to map '%s' on '%s'.\n%s",
130
+ key, sObjectType, e.message
131
+ end
132
+
133
+ def update(sObjectType, oObject, hParams)
134
+ PrcLib.debug("Mock: Update object '%s' = '%s' with hdata '%s'",
135
+ sObjectType, sUniqId, hParams[:hdata])
136
+ return false unless @@data.key?(sObjectType)
137
+
138
+ return false unless @@data[sObjectType][oObject[:id]].nil?
139
+ # Considered hash object is already updated.
140
+ # This action emule the object save which doesn't make sense in this empty
141
+ # Mock controller.
142
+ true
143
+ end
144
+ end
@@ -0,0 +1,45 @@
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
+ # This class describes how to process some actions, and will do everything prior
18
+ # this task to make it to work.
19
+ class Openstack < BaseDefinition
20
+ def initialize
21
+ superclass.provides([:compute, :network])
22
+ end
23
+
24
+ def compute
25
+ Fog::Compute.new(
26
+ :provider => :openstack,
27
+ :openstack_api_key => superclass.oForjAccount.get(:account_id),
28
+ :openstack_username => superclass.oForjAccount.get(:account_key),
29
+ :openstack_auth_url => superclass.oForjAccount.get(:auth_uri),
30
+ :openstack_tenant => superclass.oForjAccount.get(:tenant_id),
31
+ :openstack_region => superclass.oForjAccount.get(:compute)
32
+ )
33
+ end
34
+
35
+ def network
36
+ Fog::Network.new(
37
+ :provider => :openstack,
38
+ :openstack_api_key => superclass.oForjAccount.get(:account_id),
39
+ :openstack_username => superclass.oForjAccount.get(:account_key),
40
+ :openstack_auth_url => superclass.oForjAccount.get(:auth_uri),
41
+ :openstack_tenant => superclass.oForjAccount.get(:tenant_id),
42
+ :openstack_region => superclass.oForjAccount.get(:network)
43
+ )
44
+ end
45
+ end
@@ -15,28 +15,26 @@
15
15
  # limitations under the License.
16
16
 
17
17
  # This file is given as an example.
18
+ # This class is automatically derived from ForjCloudBase and ForjProcess
19
+ class Mycloud
20
+ def provider_compute_new
21
+ # My fog connection
22
+ # hget_cloudObjMapping() is a ForjCloudBase function which will build a
23
+ # hash from data required with needed mapped keys(see core.rb)
24
+ Fog::Compute.new({ :provider => :mycloud }.merge(hget_cloudObjMapping))
18
25
 
19
- class Mycloud # This class is automatically derived from ForjCloudBase and ForjProcess
20
-
21
- def provider_compute_new
22
- # My fog connection
23
- # hget_cloudObjMapping() is a ForjCloudBase function which will build a
24
- # hash from data required with needed mapped keys(see core.rb)
25
- Fog::Compute.new({:provider => :mycloud}.merge(hget_cloudObjMapping()))
26
-
27
- # If you do not want to get data mapped automatically, you can use
28
- # @oForjAccount.get()
29
- # This means in following declaration in your core.rb:
30
- # obj_needs(:data, :<CloudDataKey},{:mapping => :<MyCloudKeyMapped>})
31
- # can be updated by removing the mapping => <Value>
32
- Fog::Compute.new({
33
- :provider => :mycloud,
34
- :user => @oForjAccount.get(:account_id),
35
- :pwd => @oForjAccount.get(:account_key),
36
- :auth_uri => @oForjAccount.get(:auth_uri),
37
- :project => @oForjAccount.get(:tenant),
38
- :compute_service => @oForjAccount.get(:compute),
39
- })
40
-
41
- end
26
+ # If you do not want to get data mapped automatically, you can use
27
+ # @oForjAccount.get()
28
+ # This means in following declaration in your core.rb:
29
+ # obj_needs(:data, :<CloudDataKey},{:mapping => :<MyCloudKeyMapped>})
30
+ # can be updated by removing the mapping => <Value>
31
+ Fog::Compute.new(
32
+ :provider => :mycloud,
33
+ :user => @oForjAccount.get(:account_id),
34
+ :pwd => @oForjAccount.get(:account_key),
35
+ :auth_uri => @oForjAccount.get(:auth_uri),
36
+ :project => @oForjAccount.get(:tenant),
37
+ :compute_service => @oForjAccount.get(:compute)
38
+ )
39
+ end
42
40
  end
@@ -0,0 +1,72 @@
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
+ # This file is given as an example.
18
+
19
+ # require 'fog' # We can use fog to access a cloud
20
+
21
+ cloud_path = File.expand_path(File.dirname(__FILE__))
22
+
23
+ require File.join(cloud_path, 'compute.rb')
24
+ require File.join(cloud_path, 'network.rb')
25
+
26
+ # Defines Meta MyCloud object
27
+ class Mycloud
28
+ # Defines Object structure and function stored on the Hpcloud class object.
29
+
30
+ # ForjCloud has a list of predefined object, like compute_connection, network
31
+ # , ...
32
+ # See lib/providers/core/cloud_data_pref.rb
33
+
34
+ # Compute Object
35
+ define_obj :compute_connection
36
+ # Defines Data used by compute.
37
+ obj_needs(:data, :account_id, :mapping => :user)
38
+ obj_needs(:data, :account_key, :mapping => :pwd)
39
+ obj_needs(:data, :auth_uri, :mapping => :auth_uri)
40
+ obj_needs(:data, :tenant, :mapping => :project)
41
+ obj_needs(:data, :compute, :mapping => :compute_service)
42
+
43
+ define_obj :network_connection
44
+ obj_needs(:data, :account_id, :mapping => :user)
45
+ obj_needs(:data, :account_key, :mapping => :pwd)
46
+ obj_needs(:data, :auth_uri, :mapping => :auth_uri)
47
+ obj_needs(:data, :tenant, :mapping => :project)
48
+ obj_needs(:data, :network, :mapping => :network_service)
49
+
50
+ define_obj :network
51
+ obj_needs(:CloudObject, :network_connection)
52
+ obj_needs(:data, :network_name)
53
+
54
+ # defines setup Cloud data
55
+ # This definition is required only if you need to change the predefined data.
56
+ # To get details on what kind of parameters can be applied to a CloudData, see
57
+ # lib/defaults.yaml
58
+ define_data(:account_id, :provisioned_by => :setup,
59
+ :desc => 'MyCloud username')
60
+ define_data(:account_key, :provisioned_by => :setup,
61
+ :desc => 'HPCloud secret Key')
62
+ define_data(:auth_uri, :provisioned_by => :setup,
63
+ :desc => 'HPCloud Authentication service URL')
64
+ define_data(:tenant, :provisioned_by => :setup,
65
+ :desc => 'HPCloud Tenant ID')
66
+ define_data(:compute, :provisioned_by => :setup,
67
+ :desc => 'HPCloud Compute service zone (Ex: '\
68
+ 'region-a.geo-1)')
69
+ define_data(:network, :provisioned_by => :setup,
70
+ :desc => 'HPCloud Network service zone (Ex: '\
71
+ 'region-a.geo-1)')
72
+ end
@@ -16,18 +16,17 @@
16
16
 
17
17
  # This file is given as an example.
18
18
 
19
- class Mycloud # This class is automatically derived from ForjCloudBase and ForjProcess
19
+ # This class is automatically derived from ForjCloudBase and ForjProcess
20
+ class Mycloud
21
+ def provider_network_new
22
+ Fog::Network.new({ :provider => :mycloud }.merge(hget_cloudObjMapping))
23
+ end
20
24
 
21
- def provider_network_new
22
- Fog::Network.new({:provider => :mycloud}.merge(hget_cloudObjMapping()))
23
- end
24
-
25
- def provider_query_network(oNetwork, name)
26
- oNetwork.networks.all(:name => name)
27
- end
28
-
29
- def provider_create_network(oNetwork, name)
30
- oNetwork.networks.create(:name => name)
31
- end
25
+ def provider_query_network(oNetwork, name)
26
+ oNetwork.networks.all(:name => name)
27
+ end
32
28
 
29
+ def provider_create_network(oNetwork, name)
30
+ oNetwork.networks.create(:name => name)
31
+ end
33
32
  end