foreman_google 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -4
  3. data/app/lib/foreman_google/google_compute_adapter.rb +178 -0
  4. data/app/lib/google_cloud_compute/compute_attributes.rb +98 -0
  5. data/app/lib/google_cloud_compute/compute_collection.rb +23 -0
  6. data/app/lib/google_extensions/attached_disk.rb +22 -0
  7. data/app/models/concerns/foreman_google/host_managed_extensions.rb +11 -0
  8. data/app/models/foreman_google/gce.rb +98 -38
  9. data/app/models/foreman_google/google_compute.rb +68 -58
  10. data/app/views/compute_resources/form/_gce.html.erb +10 -0
  11. data/app/views/compute_resources/show/_gce.html.erb +0 -0
  12. data/app/views/compute_resources_vms/form/gce/_base.html.erb +18 -0
  13. data/app/views/compute_resources_vms/form/gce/_volume.html.erb +5 -0
  14. data/app/views/compute_resources_vms/index/_gce.html.erb +26 -0
  15. data/app/views/compute_resources_vms/show/_gce.html.erb +21 -0
  16. data/app/views/images/form/_gce.html.erb +3 -0
  17. data/db/migrate/20220331113745_foreman_gce_to_foreman_google_gce.rb +24 -0
  18. data/lib/foreman_google/engine.rb +9 -1
  19. data/lib/foreman_google/version.rb +1 -1
  20. data/locale/action_names.rb +6 -0
  21. data/locale/en/foreman_google.edit.po +116 -0
  22. data/locale/en/foreman_google.po +74 -2
  23. data/locale/en/foreman_google.po.time_stamp +0 -0
  24. data/locale/foreman_google.pot +112 -8
  25. data/locale/gemspec.rb +1 -1
  26. data/package.json +7 -7
  27. data/test/fixtures/disks_delete.json +14 -0
  28. data/test/fixtures/disks_get.json +13 -0
  29. data/test/fixtures/disks_insert.json +12 -0
  30. data/test/fixtures/instance.json +1 -1
  31. data/test/fixtures/instance_insert.json +15 -0
  32. data/test/fixtures/instance_list.json +86 -0
  33. data/test/fixtures/instance_set_disk_auto_delete.json +14 -0
  34. data/test/fixtures/operation_error.json +26 -0
  35. data/test/fixtures/operation_get.json +13 -0
  36. data/test/models/foreman_google/gce_test.rb +43 -5
  37. data/test/models/foreman_google/google_compute_test.rb +90 -32
  38. data/test/unit/foreman_google/google_compute_adapter_test.rb +103 -4
  39. data/test/unit/google_extensions/attached_disk_test.rb +17 -0
  40. data/webpack/global_index.js +2 -13
  41. data/webpack/legacy.js +16 -0
  42. metadata +63 -15
  43. data/lib/foreman_google/google_compute_adapter.rb +0 -91
@@ -0,0 +1,17 @@
1
+ require 'test_google_helper'
2
+
3
+ module GoogleExtensions
4
+ class AttachedDiskTest < GoogleTestCase
5
+ describe 'insert_attrs' do
6
+ it 'with source image' do
7
+ disk = Google::Cloud::Compute::V1::AttachedDisk.new(source: 'source-image')
8
+ assert_equal 'source-image', disk.insert_attrs[:source_image]
9
+ end
10
+
11
+ it 'without source image' do
12
+ disk = Google::Cloud::Compute::V1::AttachedDisk.new
13
+ assert_empty disk.insert_attrs[:source_image]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,17 +1,6 @@
1
- import { registerReducer } from 'foremanReact/common/MountingService';
2
- // import { addGlobalFill } from 'foremanReact/components/common/Fill/GlobalFill';
3
1
  import { registerRoutes } from 'foremanReact/routes/RoutingService';
4
2
  import Routes from './src/Router/routes';
5
- import reducers from './src/reducers';
3
+ import { registerLegacy } from './legacy';
6
4
 
7
- // register reducers
8
- Object.entries(reducers).forEach(([key, reducer]) =>
9
- registerReducer(key, reducer)
10
- );
11
-
12
- // register client routes
13
5
  registerRoutes('ForemanGoogle', Routes);
14
-
15
- // register fills for extending foreman core
16
- // http://foreman.surge.sh/?path=/docs/introduction-slot-and-fill--page
17
- // addGlobalFill('<slotId>', '<fillId>', <div key='plugin-template-example' />, 300);
6
+ registerLegacy();
data/webpack/legacy.js ADDED
@@ -0,0 +1,16 @@
1
+ const jsonLoader = input => {
2
+ const file = input.files[0];
3
+ const reader = new FileReader();
4
+ reader.onload = () => {
5
+ const text = reader.result;
6
+ const outputTextField = document.getElementById('gce_json');
7
+ outputTextField.value = text;
8
+ };
9
+ reader.readAsText(file);
10
+ };
11
+
12
+ export const registerLegacy = () => {
13
+ window.tfm = Object.assign(window.tfm || {}, {
14
+ gce: { jsonLoader },
15
+ });
16
+ };
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_google
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Foreman Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2022-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-apis-compute_v1
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.14'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: google-cloud-compute
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -49,37 +63,62 @@ files:
49
63
  - README.md
50
64
  - Rakefile
51
65
  - app/controllers/concerns/foreman_google/temporary_prepend_path.rb
66
+ - app/lib/foreman_google/google_compute_adapter.rb
67
+ - app/lib/google_cloud_compute/compute_attributes.rb
68
+ - app/lib/google_cloud_compute/compute_collection.rb
69
+ - app/lib/google_extensions/attached_disk.rb
70
+ - app/models/concerns/foreman_google/host_managed_extensions.rb
52
71
  - app/models/foreman_google/gce.rb
53
72
  - app/models/foreman_google/google_compute.rb
73
+ - app/views/compute_resources/form/_gce.html.erb
74
+ - app/views/compute_resources/show/_gce.html.erb
75
+ - app/views/compute_resources_vms/form/gce/_base.html.erb
76
+ - app/views/compute_resources_vms/form/gce/_volume.html.erb
77
+ - app/views/compute_resources_vms/index/_gce.html.erb
78
+ - app/views/compute_resources_vms/show/_gce.html.erb
79
+ - app/views/images/form/_gce.html.erb
54
80
  - config/routes.rb
81
+ - db/migrate/20220331113745_foreman_gce_to_foreman_google_gce.rb
55
82
  - lib/foreman_google.rb
56
83
  - lib/foreman_google/engine.rb
57
- - lib/foreman_google/google_compute_adapter.rb
58
84
  - lib/foreman_google/version.rb
59
85
  - lib/tasks/foreman_google_tasks.rake
60
86
  - locale/Makefile
87
+ - locale/action_names.rb
88
+ - locale/en/foreman_google.edit.po
61
89
  - locale/en/foreman_google.po
90
+ - locale/en/foreman_google.po.time_stamp
62
91
  - locale/foreman_google.pot
63
92
  - locale/gemspec.rb
64
93
  - package.json
65
94
  - test/factories/gce.rb
95
+ - test/fixtures/disks_delete.json
96
+ - test/fixtures/disks_get.json
97
+ - test/fixtures/disks_insert.json
66
98
  - test/fixtures/images_centos_cloud.json
67
99
  - test/fixtures/images_coastal.json
68
100
  - test/fixtures/images_deprecated.json
69
101
  - test/fixtures/images_nothing_found.json
70
102
  - test/fixtures/instance.json
103
+ - test/fixtures/instance_insert.json
104
+ - test/fixtures/instance_list.json
105
+ - test/fixtures/instance_set_disk_auto_delete.json
71
106
  - test/fixtures/instance_start.json
72
107
  - test/fixtures/instance_stop.json
73
108
  - test/fixtures/machine_types.json
74
109
  - test/fixtures/networks.json
110
+ - test/fixtures/operation_error.json
111
+ - test/fixtures/operation_get.json
75
112
  - test/fixtures/zones.json
76
113
  - test/models/foreman_google/gce_test.rb
77
114
  - test/models/foreman_google/google_compute_test.rb
78
115
  - test/test_google_helper.rb
79
116
  - test/unit/foreman_google/google_compute_adapter_test.rb
117
+ - test/unit/google_extensions/attached_disk_test.rb
80
118
  - webpack/global_index.js
81
119
  - webpack/global_test_setup.js
82
120
  - webpack/index.js
121
+ - webpack/legacy.js
83
122
  - webpack/src/Extends/index.js
84
123
  - webpack/src/Router/routes.js
85
124
  - webpack/src/reducers.js
@@ -105,23 +144,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
144
  - !ruby/object:Gem::Version
106
145
  version: '0'
107
146
  requirements: []
108
- rubygems_version: 3.3.7
147
+ rubygems_version: 3.1.6
109
148
  signing_key:
110
149
  specification_version: 4
111
150
  summary: Google Compute Engine plugin for the Foreman
112
151
  test_files:
113
- - test/models/foreman_google/google_compute_test.rb
114
- - test/models/foreman_google/gce_test.rb
115
- - test/unit/foreman_google/google_compute_adapter_test.rb
116
- - test/factories/gce.rb
117
- - test/fixtures/networks.json
118
- - test/fixtures/instance.json
119
- - test/fixtures/zones.json
120
- - test/fixtures/instance_stop.json
121
- - test/fixtures/machine_types.json
152
+ - test/fixtures/disks_delete.json
153
+ - test/fixtures/disks_get.json
154
+ - test/fixtures/disks_insert.json
155
+ - test/fixtures/images_centos_cloud.json
122
156
  - test/fixtures/images_coastal.json
123
- - test/fixtures/instance_start.json
124
157
  - test/fixtures/images_deprecated.json
125
- - test/fixtures/images_centos_cloud.json
126
158
  - test/fixtures/images_nothing_found.json
159
+ - test/fixtures/instance.json
160
+ - test/fixtures/instance_insert.json
161
+ - test/fixtures/instance_list.json
162
+ - test/fixtures/instance_set_disk_auto_delete.json
163
+ - test/fixtures/instance_start.json
164
+ - test/fixtures/instance_stop.json
165
+ - test/fixtures/machine_types.json
166
+ - test/fixtures/networks.json
167
+ - test/fixtures/operation_error.json
168
+ - test/fixtures/operation_get.json
169
+ - test/fixtures/zones.json
170
+ - test/factories/gce.rb
171
+ - test/unit/foreman_google/google_compute_adapter_test.rb
172
+ - test/unit/google_extensions/attached_disk_test.rb
173
+ - test/models/foreman_google/gce_test.rb
174
+ - test/models/foreman_google/google_compute_test.rb
127
175
  - test/test_google_helper.rb
@@ -1,91 +0,0 @@
1
- require 'google-cloud-compute'
2
-
3
- module ForemanGoogle
4
- class GoogleComputeAdapter
5
- def initialize(auth_json_string:)
6
- @auth_json = JSON.parse(auth_json_string)
7
- end
8
-
9
- def project_id
10
- @auth_json['project_id']
11
- end
12
-
13
- # ------ RESOURCES ------
14
-
15
- # Returns an Google::Instance identified by instance_identity within given zone.
16
- # @param zone [String] eighter full url or just zone name
17
- # @param instance_identity [String] eighter an instance name or its id
18
- def instance(zone, instance_identity)
19
- get('instances', instance: instance_identity, zone: zone)
20
- end
21
-
22
- def zones
23
- list('zones')
24
- end
25
-
26
- def networks
27
- list('networks')
28
- end
29
-
30
- def machine_types(zone)
31
- list('machine_types', zone: zone)
32
- end
33
-
34
- def start(zone, instance_identity)
35
- manage_instance(:start, zone, instance_identity)
36
- end
37
-
38
- def stop(zone, instance_identity)
39
- manage_instance(:stop, zone, instance_identity)
40
- end
41
-
42
- # Setting filter to '(deprecated.state != "DEPRECATED") AND (deprecated.state != "OBSOLETE")'
43
- # doesn't work and returns empty array, no idea what is happening there
44
- def images(filter: nil)
45
- projects = [project_id] + all_projects
46
- all_images = projects.map { |project| list_images(project, filter: filter) }
47
- all_images.flatten.reject(&:deprecated)
48
- end
49
-
50
- private
51
-
52
- def list(resource_name, **opts)
53
- response = resource_client(resource_name).list(project: project_id, **opts).response
54
- response.items
55
- rescue ::Google::Cloud::Error => e
56
- raise Foreman::WrappedException.new(e, 'Cannot list Google resource %s', resource_name)
57
- end
58
-
59
- def list_images(project, **opts)
60
- resource_name = 'images'
61
- response = resource_client(resource_name).list(project: project, **opts).response
62
- response.items
63
- rescue ::Google::Cloud::Error => e
64
- raise Foreman::WrappedException.new(e, 'Cannot list Google resource %s', resource_name)
65
- end
66
-
67
- def get(resource_name, **opts)
68
- resource_client(resource_name).get(project: project_id, **opts)
69
- rescue ::Google::Cloud::Error => e
70
- raise Foreman::WrappedException.new(e, 'Could not fetch Google resource %s', resource_name)
71
- end
72
-
73
- def manage_instance(action, zone, instance_identity)
74
- resource_client('instances').send(action, project: project_id, zone: zone, instance: instance_identity)
75
- rescue ::Google::Cloud::Error => e
76
- raise Foreman::WrappedException.new(e, 'Could not %s Google resource %s', action.to_s, resource_name)
77
- end
78
-
79
- def resource_client(resource_name)
80
- ::Google::Cloud::Compute.public_send(resource_name) do |config|
81
- config.credentials = @auth_json
82
- end
83
- end
84
-
85
- def all_projects
86
- %w[centos-cloud cos-cloud coreos-cloud debian-cloud opensuse-cloud
87
- rhel-cloud rhel-sap-cloud suse-cloud suse-sap-cloud
88
- ubuntu-os-cloud windows-cloud windows-sql-cloud].freeze
89
- end
90
- end
91
- end