lorj 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/example/students_1/process/students.rb +1 -1
  4. data/example/students_1/student_v1.md +2 -0
  5. data/example/students_1/students.rb +2 -1
  6. data/example/students_2/process/students.rb +1 -1
  7. data/example/students_2/students.rb +4 -2
  8. data/example/students_3/controller/yaml_students_def.rb +1 -1
  9. data/example/students_3/process/students.rb +1 -1
  10. data/example/students_3/student_v3.md +5 -3
  11. data/example/students_3/students.rb +5 -3
  12. data/example/students_4/controller/yaml_students_def.rb +1 -1
  13. data/example/students_4/process/students/definition/students.rb +1 -1
  14. data/example/students_4/students.rb +5 -3
  15. data/example/students_5/controller/yaml_students.rb +1 -1
  16. data/example/students_5/process/students.rb +1 -1
  17. data/example/students_5/student_v5.md +4 -4
  18. data/example/students_5/students.rb +8 -7
  19. data/example/yaml_students/students.rb +4 -4
  20. data/lib/core/core.rb +110 -64
  21. data/lib/core/core_internal.rb +110 -15
  22. data/lib/core/core_object_data.rb +4 -4
  23. data/lib/core/core_process_setup.rb +3 -30
  24. data/lib/core/lorj_data.rb +1 -1
  25. data/lib/core/lorj_keypath.rb +3 -1
  26. data/lib/core/process.rb +67 -0
  27. data/lib/lorj/version.rb +2 -1
  28. data/lib/lorj.rb +3 -4
  29. data/lib/lorj_account.rb +6 -5
  30. data/lib/lorj_config.rb +3 -2
  31. data/lib/providers/templates/compute.rb +1 -1
  32. data/lorj-spec/controllers/mock/mock.rb +144 -0
  33. data/lorj-spec/data.yaml +0 -0
  34. data/lorj-spec/process/mock2_process.rb +48 -0
  35. data/lorj-spec/process/mock_process.rb +48 -0
  36. data/lorj-spec/providers/mock2/mock2.rb +0 -0
  37. data/lorj.gemspec +2 -4
  38. data/spec/05_lorj_keypath_spec.rb +78 -0
  39. data/spec/20_lorj_meta_spec.rb +1 -1
  40. data/spec/21_lorj_processes_spec.rb +115 -0
  41. metadata +27 -42
  42. data/lib/core_process/cloud/process/common.rb +0 -60
  43. data/lib/core_process/cloud/process/connection.rb +0 -92
  44. data/lib/core_process/cloud/process/external_network.rb +0 -90
  45. data/lib/core_process/cloud/process/flavor.rb +0 -97
  46. data/lib/core_process/cloud/process/images.rb +0 -99
  47. data/lib/core_process/cloud/process/internet_network.rb +0 -33
  48. data/lib/core_process/cloud/process/internet_server.rb +0 -29
  49. data/lib/core_process/cloud/process/keypairs.rb +0 -332
  50. data/lib/core_process/cloud/process/network.rb +0 -107
  51. data/lib/core_process/cloud/process/public_ip.rb +0 -102
  52. data/lib/core_process/cloud/process/router.rb +0 -267
  53. data/lib/core_process/cloud/process/rules.rb +0 -120
  54. data/lib/core_process/cloud/process/security_groups.rb +0 -120
  55. data/lib/core_process/cloud/process/server.rb +0 -126
  56. data/lib/core_process/cloud/process/server_log.rb +0 -34
  57. data/lib/core_process/cloud/process/subnetwork.rb +0 -96
  58. data/lib/core_process/cloud_process.rb +0 -30
  59. data/lib/prc_base_config.rb +0 -300
  60. data/lib/prc_core_config.rb +0 -1258
  61. data/lib/prc_section_config.rb +0 -90
  62. data/lib/providers/hpcloud/compute.rb +0 -105
  63. data/lib/providers/hpcloud/hpcloud.rb +0 -462
  64. data/lib/providers/hpcloud/network.rb +0 -115
  65. data/lib/providers/hpcloud/security_groups.rb +0 -68
  66. data/lib/providers/openstack/openstack.rb +0 -410
  67. data/lib/providers/openstack/openstack_create.rb +0 -205
  68. data/lib/providers/openstack/openstack_delete.rb +0 -28
  69. data/lib/providers/openstack/openstack_get.rb +0 -39
  70. data/lib/providers/openstack/openstack_process.rb +0 -26
  71. data/lib/providers/openstack/openstack_query.rb +0 -96
  72. data/lib/providers/openstack/openstack_update.rb +0 -35
  73. data/lib/rh.rb +0 -426
  74. data/spec/01_hash_rh_spec.rb +0 -282
  75. data/spec/02_prc_base_config_spec.rb +0 -227
  76. data/spec/03_prc_section_config_spec.rb +0 -196
  77. data/spec/04_prc_core_config_spec.rb +0 -325
@@ -1,97 +0,0 @@
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
@@ -1,99 +0,0 @@
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
@@ -1,33 +0,0 @@
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
@@ -1,29 +0,0 @@
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 SERVER Object
22
- # internet server is a server connected to the internet network.
23
- class Lorj::BaseDefinition
24
- define_obj(:internet_server, :nohandler => true)
25
-
26
- obj_needs :CloudObject, :internet_network
27
- obj_needs :CloudObject, :server
28
- obj_needs :CloudObject, :public_ip
29
- end
@@ -1,332 +0,0 @@
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
- # Keypair management
22
- class CloudProcess
23
- # KeyPair Create Process Handler
24
- # The process implemented is:
25
- # * Check local SSH keypairs with given ':keypair_name'
26
- # * Check remote keypair existence
27
- # * Compare and warn if needed.
28
- # * Import public key found if missing remotely and name it.
29
- #
30
- # Return:
31
- # - keypair : Lorj::Data keypair object. Following additional data should be
32
- # found in the keypair attributes
33
- # - :coherent : Boolean. True, if the local keypair (public AND
34
- # private) is coherent with remote keypair found in
35
- # the cloud
36
- # - :private_key_file: String. Path to local private key file
37
- # - :public_key_file : String. Path to local public key file
38
- # - :public_key : String. Public key content. (config[:public_key] is
39
- # also set - Used to import it)
40
- #
41
- def forj_get_or_create_keypair(sCloudObj, hParams)
42
- keypair_name = hParams[:keypair_name]
43
- PrcLib.state("Searching for keypair '%s'", keypair_name)
44
-
45
- keypair = forj_get_keypair(sCloudObj, keypair_name, hParams)
46
- if keypair.empty?
47
- loc_kpair = keypair_detect(keypair_name, hParams[:keypair_path],
48
- hParams[:keypair_base])
49
- keypair = keypair_import(hParams, loc_kpair)
50
- else
51
- keypair_display(keypair)
52
- end
53
- keypair
54
- end
55
-
56
- # Query cloud keypairs and check coherence with local files
57
- # of same name in forj files located by :keypair_path
58
- def forj_query_keypairs(sCloudObj, sQuery, hParams)
59
- keypair_path = File.expand_path(hParams[:keypair_path])
60
- keypair_base = File.expand_path(hParams[:keypair_base])
61
-
62
- ssl_error_obj = SSLErrorMgt.new
63
- begin
64
- keypairs = controller_query(sCloudObj, sQuery)
65
- rescue => e
66
- retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
67
- end
68
- # Looping on keypairs to identify if they have a valid local ssh key.
69
- keypairs.each do |keypair|
70
- loc_kpair = keypair_detect(keypair_name, keypair_path, keypair_base)
71
- keypair_files_detected(keypair, loc_kpair)
72
- end
73
- keypairs
74
- end
75
-
76
- # Get cloud keypair and check coherence with local files
77
- # of same name in forj files
78
- def forj_get_keypair(sCloudObj, keypair_name, hParams)
79
- ssl_error_obj = SSLErrorMgt.new
80
- begin
81
- keypair = controller_get(sCloudObj, keypair_name)
82
- rescue => e
83
- retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
84
- end
85
-
86
- keypair_path = File.expand_path(hParams[:keypair_path])
87
- loc_kpair = keypair_detect(keypair_name, keypair_path, keypair_name)
88
- keypair_files_detected(keypair, loc_kpair) unless keypair.empty?
89
- keypair
90
- end
91
- end
92
-
93
- # ************************************ keypairs Object
94
- # Identify keypairs
95
- class Lorj::BaseDefinition
96
- define_obj(:keypairs,
97
-
98
- :create_e => :forj_get_or_create_keypair,
99
- :query_e => :forj_query_keypairs,
100
- :get_e => :forj_get_keypair
101
- # :delete_e => :forj_delete_keypair
102
- )
103
-
104
- obj_needs :CloudObject, :compute_connection
105
- obj_needs :data, :keypair_name, :for => [:create_e]
106
- obj_needs :data, :keypair_path
107
- obj_needs :data, :keypair_base
108
-
109
- # By default optional. But required by the import case if needed.
110
- obj_needs_optional
111
- obj_needs :data, :public_key, :for => [:create_e]
112
-
113
- def_attribute :public_key
114
- end
115
-
116
- # Keypair management: Internal process functions
117
- class CloudProcess
118
- # Function to display information about keypair object found.
119
- #
120
- def keypair_display(keypair)
121
- PrcLib.info("Found keypair '%s'.", keypair[:name])
122
-
123
- private_key_file = File.join(keypair[:keypair_path],
124
- keypair[:private_key_name])
125
- public_key_file = File.join(keypair[:keypair_path],
126
- keypair[:public_key_name])
127
-
128
- PrcLib.info("Found openssh private key file '%s'.",
129
- private_key_file) if keypair[:private_key_exist?]
130
- PrcLib.info("Found openssh public key file '%s'.",
131
- public_key_file) if keypair[:public_key_exist?]
132
-
133
- unless keypair[:public_key_exist?]
134
- name = keypair[:name]
135
- PrcLib.warning("The local public key file '%s' is missing.\n"\
136
- "As the keypair name '%s' already exists in your cloud, "\
137
- 'you will need to get the original SSH keypair files '\
138
- "used to create the keypair name '%s'. Otherwise, you "\
139
- "won't be able to use it to connect to a box configured"\
140
- " with '%s'."\
141
- "\nPublic key found in the cloud:\n%s",
142
- public_key_file, name, name, name,
143
- keypair[:public_key])
144
- return
145
- end
146
-
147
- if keypair[:coherent]
148
- PrcLib.info("keypair '%s' local files are coherent with keypair in "\
149
- 'your cloud service. You will be able to use your local '\
150
- 'keys to connect to any box configured with this keypair '\
151
- 'name, over SSH.', keypair[:name])
152
- else
153
- PrcLib.warning("Your local public key file '%s' is incoherent with "\
154
- "public key attached to the keypair '%s' in your cloud."\
155
- " You won't be able to access your box with this keypair."\
156
- "\nPublic key found in the cloud:\n%s",
157
- public_key_file, keypair[:name], keypair[:public_key])
158
- end
159
- end
160
- end
161
-
162
- # Keypair management: Internal process functions
163
- class CloudProcess
164
- # Function to update a keypair object with ssh files found in :keypair_path
165
- #
166
- def keypair_files_detected(keypair, loc_kpair)
167
- keypair[:private_key_exist?] = loc_kpair[:private_key_exist?]
168
- keypair[:public_key_exist?] = loc_kpair[:public_key_exist?]
169
- keypair[:private_key_name] = loc_kpair[:private_key_name]
170
- keypair[:public_key_name] = loc_kpair[:public_key_name]
171
- keypair[:keypair_path] = loc_kpair[:keypair_path]
172
- keypair[:coherent] = coherent_keypair?(loc_kpair, keypair)
173
- end
174
-
175
- def keypair_import(hParams, loc_kpair)
176
- PrcLib.fatal(1, "Unable to import keypair '%s'. "\
177
- 'Public key file is not found. '\
178
- "Please run 'forj setup %s'",
179
- hParams[:keypair_name],
180
- config[:account_name]) unless loc_kpair[:public_key_exist?]
181
- public_key_file = File.join(loc_kpair[:keypair_path],
182
- loc_kpair[:public_key_name])
183
-
184
- begin
185
- public_key = File.read(public_key_file)
186
- rescue => e
187
- PrcLib.fatal(1, "Unable to import keypair '%s'. '%s' is "\
188
- "unreadable.\n%s", hParams[:keypair_name],
189
- loc_kpair[:public_key_file],
190
- e.message)
191
- end
192
- keypair = create_keypair(:keypairs, :public_key => public_key)
193
-
194
- return nil if keypair.nil?
195
-
196
- # Adding information about SSH key files.
197
- keypair_files_detected(keypair, loc_kpair)
198
-
199
- keypair
200
- end
201
-
202
- def create_keypair(sCloudObj, hParams)
203
- key_name = hParams[:keypair_name]
204
- PrcLib.state("Importing keypair '%s'", key_name)
205
- ssl_error_obj = SSLErrorMgt.new
206
- begin
207
- keypair = controller_create(sCloudObj, hParams)
208
- PrcLib.info("Keypair '%s' imported.", keypair[:name])
209
- rescue StandardError => e
210
- retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
211
- PrcLib.error "error importing keypair '%s'", key_name
212
- end
213
- keypair
214
- end
215
-
216
- # Build keypair data information structure with files found in
217
- # local filesystem. Take care of priv with or without .pem
218
- # and pubkey with pub.
219
- # :keypair_path data settings is changing to become just a path to
220
- # the keypair files, the base keypair.
221
- # Which will introduce a :keypair_base in the setup.
222
- def keypair_detect(keypair_name, key_fullpath, key_basename = nil)
223
- # When uses key_basename, we switch to the new model
224
- # using :keypair_path and :keypair_base in setup
225
- if key_basename.nil?
226
- key_basename = File.basename(key_fullpath)
227
- key_path = File.expand_path(File.dirname(key_fullpath))
228
- else
229
- key_path = File.expand_path(key_fullpath)
230
- end
231
-
232
- obj_match = key_basename.match(/^(.*?)(\.pem|\.pub)?$/)
233
- key_basename = obj_match[1]
234
-
235
- private_key_ext, files = _check_key_file(key_path, key_basename,
236
- ['', '.pem'])
237
-
238
- if private_key_ext
239
- priv_key_exist = true
240
- priv_key_name = key_basename + private_key_ext
241
- else
242
- files.each do |temp_file|
243
- PrcLib.warning('keypair_detect: Private key file name detection has '\
244
- "detected '%s' as a directory. Usually, it should be a "\
245
- 'private key file. Please check.',
246
- temp_file) if File.directory?(temp_file)
247
- end
248
- priv_key_exist = false
249
- priv_key_name = key_basename
250
- end
251
-
252
- pub_key_exist = File.exist?(File.join(key_path, key_basename + '.pub'))
253
- pub_key_name = key_basename + '.pub'
254
-
255
- # keypair basic structure
256
- { :keypair_name => keypair_name,
257
- :keypair_path => key_path, :key_basename => key_basename,
258
- :private_key_name => priv_key_name, :private_key_exist? => priv_key_exist,
259
- :public_key_name => pub_key_name, :public_key_exist? => pub_key_exist
260
- }
261
- end
262
-
263
- def _check_key_file(key_path, key_basename, extensions)
264
- found_ext = nil
265
- files = []
266
- extensions.each do |ext|
267
- temp_file = File.join(key_path, key_basename + ext)
268
- if File.exist?(temp_file) && !File.directory?(temp_file)
269
- found_ext = ext
270
- files << temp_file
271
- end
272
- end
273
- [found_ext, files]
274
- end
275
-
276
- def get_keypairs_path(hParams, hKeys)
277
- keypair_name = hParams[:keypair_name]
278
-
279
- if hKeys[:private_key_exist?]
280
- hParams[:private_key_file] = File.join(hKeys[:keypair_path],
281
- hKeys[:private_key_name])
282
- PrcLib.info("Openssh private key file '%s' exists.",
283
- hParams[:private_key_file])
284
- end
285
- if hKeys[:public_key_exist?]
286
- hParams[:public_key_file] = File.join(hKeys[:keypair_path],
287
- hKeys[:public_key_name])
288
- else
289
- PrcLib.fatal(1, 'Public key file is not found. Please run'\
290
- " 'forj setup %s'", config[:account_name])
291
- end
292
-
293
- PrcLib.state("Searching for keypair '%s'", keypair_name)
294
-
295
- hParams
296
- end
297
-
298
- # Check if 2 keypair objects are coherent (Same public key)
299
- # Parameters:
300
- # - +loc_kpair+ : Keypair structure representing local files existence.
301
- # see keypair_detect
302
- # - +keypair+ : Keypair object to check.
303
- #
304
- # return:
305
- # - coherent : Boolean. True if same public key.
306
- def coherent_keypair?(loc_kpair, keypair)
307
- # send keypairs by parameter
308
- is_coherent = false
309
-
310
- pub_keypair = keypair[:public_key]
311
-
312
- # Check the public key with the one found here, locally.
313
- if !pub_keypair.nil? && pub_keypair != ''
314
- return false unless loc_kpair[:public_key_exist?]
315
- begin
316
- loc_pubkey = File.read(File.join(loc_kpair[:keypair_path],
317
- loc_kpair[:public_key_name]))
318
- rescue => e
319
- PrcLib.error("Unable to read '%s'.\n%s",
320
- loc_kpair[:public_key_file], e.message)
321
- else
322
- if loc_pubkey.split(' ')[1].strip == pub_keypair.split(' ')[1].strip
323
- is_coherent = true
324
- end
325
- end
326
- else
327
- PrcLib.warning('Unable to verify keypair coherence with your local '\
328
- 'SSH keys. No public key (:public_key) provided.')
329
- end
330
- is_coherent
331
- end
332
- end
@@ -1,107 +0,0 @@
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
- # Network Management
22
- class CloudProcess
23
- # Process Create handler
24
- def forj_get_or_create_network(sCloudObj, hParams)
25
- PrcLib.state("Searching for network '%s'", hParams[:network_name])
26
- networks = find_network(sCloudObj, hParams)
27
- if networks.length == 0
28
- network = create_network(sCloudObj, hParams)
29
- else
30
- network = networks[0]
31
- end
32
- register(network)
33
-
34
- # Attaching if missing the subnet.
35
- # Creates an object subnet, attached to the network.
36
- params = {}
37
- unless hParams[:subnetwork_name]
38
- params[:subnetwork_name] = 'sub-' + hParams[:network_name]
39
- end
40
-
41
- process_create(:subnetwork, params)
42
-
43
- network
44
- end
45
-
46
- # Process Delete handler
47
- def forj_delete_network(sCloudObj, hParams)
48
- oProvider.delete(sCloudObj, hParams)
49
- rescue => e
50
- PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
51
- end
52
-
53
- def forj_get_network(sCloudObj, sID, hParams)
54
- oProvider.get(sCloudObj, sID, hParams)
55
- rescue => e
56
- PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
57
- end
58
- end
59
-
60
- # Network Object
61
- # Identify the network
62
- class Lorj::BaseDefinition
63
- define_obj(:network,
64
- :create_e => :forj_get_or_create_network,
65
- :query_e => :controller_query,
66
- :get_e => :forj_get_network,
67
- :delete_e => :forj_delete_network
68
- )
69
- obj_needs :CloudObject, :network_connection
70
- obj_needs :data, :network_name, :for => [:create_e]
71
-
72
- obj_needs_optional
73
- obj_needs :data, :subnetwork_name, :for => [:create_e]
74
-
75
- # Any attribute are queriable
76
- def_attribute :external # true if network is external or not.
77
- end
78
-
79
- # Network Process internal functions #
80
- class CloudProcess
81
- # Network creation
82
- # It returns:
83
- # nil or Provider Object
84
- def create_network(sCloudObj, hParams)
85
- name = hParams[:network_name]
86
- begin
87
- PrcLib.state("Creating network '%s'", name)
88
- network = controller_create(sCloudObj)
89
- PrcLib.info("Network '%s' created", network[:name])
90
- rescue => e
91
- PrcLib.fatal(1, "Unable to create network '%s'", name, e)
92
- end
93
- network
94
- end
95
-
96
- # Search for a network from his name.
97
- # Name may be unique in project context, but not in the cloud system
98
- # It returns:
99
- # nil or Provider Object
100
- def find_network(sCloudObj, hParams)
101
- query = { :name => hParams[:network_name] }
102
-
103
- query_single(sCloudObj, query, hParams[:network_name])
104
- rescue => e
105
- PrcLib.error("%s\n%s", e.message, e.backtrace.join("\n"))
106
- end
107
- end