cp_oraclecloud 0.1.11 → 0.1.12

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/cp_oraclecloud/admin.js +2 -0
  3. data/app/assets/stylesheets/cp_oraclecloud/admin.css +4 -0
  4. data/app/controllers/cp_oraclecloud/admin_controller.rb +31 -0
  5. data/app/controllers/cp_oraclecloud/images_controller.rb +70 -0
  6. data/app/controllers/cp_oraclecloud/ssh_keys_controller.rb +16 -14
  7. data/app/helpers/cp_oraclecloud/admin_helper.rb +2 -0
  8. data/app/models/cp_oraclecloud/compute_instance.rb +5 -1
  9. data/app/models/cp_oraclecloud/database_component.rb +1 -1
  10. data/app/models/cp_oraclecloud/database_instance.rb +15 -3
  11. data/app/models/cp_oraclecloud/image.rb +77 -0
  12. data/app/models/cp_oraclecloud/java_instance.rb +7 -4
  13. data/app/models/cp_oraclecloud/soa_instance.rb +5 -1
  14. data/app/models/cp_oraclecloud/ssh_key.rb +31 -14
  15. data/app/policies/cp_oraclecloud/image_policy.rb +26 -0
  16. data/app/views/cp_oraclecloud/admin/dashboard.html.erb +178 -0
  17. data/app/views/cp_oraclecloud/database_instances/_show.html.erb +149 -107
  18. data/app/views/cp_oraclecloud/java_components/_fields.html.erb +8 -6
  19. data/app/views/cp_oraclecloud/java_instances/_show.html.erb +82 -34
  20. data/app/views/cp_oraclecloud/ssh_keys/_form.html.erb +1 -1
  21. data/app/views/cp_oraclecloud/ssh_keys/edit.html.erb +19 -4
  22. data/app/views/cp_oraclecloud/ssh_keys/new.html.erb +19 -4
  23. data/app/views/products/_cp_oraclecloud_component_menu.html.erb +18 -6
  24. data/config/initializers/fog.rb +3 -0
  25. data/config/routes.rb +2 -0
  26. data/lib/cp_oraclecloud.rb +4 -0
  27. data/lib/cp_oraclecloud/compute_mixin.rb +2 -1
  28. data/lib/cp_oraclecloud/database_mixin.rb +5 -4
  29. data/lib/cp_oraclecloud/engine.rb +2 -3
  30. data/lib/cp_oraclecloud/java_mixin.rb +6 -5
  31. data/lib/cp_oraclecloud/soa_mixin.rb +4 -3
  32. data/lib/cp_oraclecloud/version.rb +1 -1
  33. metadata +38 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45071c8290ac64652b2673b95d58f43f5e5ed372
4
- data.tar.gz: 21a89e55d533e9431b20911afdb85e9b6da7ffc0
3
+ metadata.gz: 4190430a8ab637918083a4079c35da1260e250ec
4
+ data.tar.gz: 734aae870038e47627a5bc12a0535ff1fd7e90f2
5
5
  SHA512:
6
- metadata.gz: ff8e4da6966f985abbbf49d27899acd25a2ead1162a275f85d4521f8dea3f1956715cb161aedd0519071c18d25fee50611645ea30a7b371f2734c24943ef8194
7
- data.tar.gz: 54a16102e188637e42710463b44af6ed8fc8e2bc1f634e6566ba21b896b0cd7b15551d4eedaf540faaede6a267151369e392d01c27ec1f65fe7f33b2afc12c04
6
+ metadata.gz: c1fe6ef99a9fffcfb73b767c138dac24e44b07c4a48a4e119f73dbad6d5c07ce29531eef2b04095d9470ebb7c4497423606d5a66f7d3f83234af55f4470d641e
7
+ data.tar.gz: c8b843326660b1d6841f8d5df2e1a7369aeb47776642fda8b50a921cd3b8b4798ccc8b0c0c934b82f7684aab738bcfc850deda952fe3d8e8f60cffa01dc23cb8
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,31 @@
1
+ class CpOraclecloud::AdminController < ApplicationController
2
+ def dashboard
3
+ @ssh_keys = policy_scope(CpOraclecloud::SshKey)
4
+ @images = policy_scope(CpOraclecloud::Image)
5
+ @instances = CloudInstance.eager_load(environment: :project).where("type LIKE :prefix", prefix: "CpOraclecloud%")
6
+
7
+ @totals = {
8
+ :database => {:total => 0, :cost=>0},
9
+ :java => {:total => 0, :cost=>0},
10
+ :soa => {:total => 0, :cost=>0},
11
+ :compute => {:total => 0, :cost=>0}
12
+ }
13
+ @instances.each do |i|
14
+ key = nil
15
+ case i.type
16
+ when "CpOraclecloud::DatabaseInstance"
17
+ key = :database
18
+ when "CpOraclecloud::JavaInstance"
19
+ key = :java
20
+ when "CpOraclecloud::SoaInstance"
21
+ key = :soa
22
+ when "CpOraclecloud::ComputeInstance"
23
+ key = :compute
24
+ end
25
+ if key
26
+ @totals[key.to_sym][:total] += 1
27
+ @totals[key.to_sym][:cost] += i.calc_cost(i.environment.start_date, i.environment.end_date)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,70 @@
1
+ module CpOraclecloud
2
+ class ImagesController < ApplicationController
3
+ before_action :set_image, only: [:edit, :update, :destroy]
4
+
5
+ def index
6
+ authorize Image
7
+ @images = CpOraclecloud::Image.all
8
+ end
9
+
10
+ def new
11
+ authorize Image
12
+ @image = CpOraclecloud::Image.new
13
+ end
14
+
15
+ #def show
16
+ # authorize @ssh_key
17
+ #end
18
+
19
+ def create
20
+ authorize Image
21
+ @image = Image.new(image_params )
22
+
23
+ if @image.valid?
24
+ image = Image.create(image_params )
25
+ flash[:notice] = "Image has been created."
26
+ redirect_to cp_oraclecloud_admin_path
27
+ else
28
+ flash.now[:alert] = "Image has not been created."
29
+ render "new"
30
+ end
31
+ end
32
+
33
+ def edit
34
+ #authorize @image
35
+ end
36
+
37
+ def destroy
38
+ authorize @image
39
+ #@image.destroy
40
+ Image.delete(@image.id)
41
+ flash[:notice] = "Image has been deleted."
42
+
43
+ redirect_to cp_oraclecloud_admin_path
44
+ end
45
+
46
+ def update
47
+ authorize @image
48
+ if @image.update(image_params)
49
+ flash[:notice] = "Image has been updated."
50
+ redirect_to cp_oraclecloud_admin_path
51
+ else
52
+ flash.now[:alert] = "Image has not been updated."
53
+ render "edit"
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def set_image
60
+ @image = CpOraclecloud::Image.find_by_id(params[:id])
61
+ rescue ActiveRecord::RecordNotFound
62
+ flash[:alert] = "The Image you were looking for could not be found."
63
+ redirect_to cp_oraclecloud_admin_path
64
+ end
65
+
66
+ def image_params
67
+ params.require(:cp_oraclecloud_image).permit(:name, :default, :description)
68
+ end
69
+ end
70
+ end
@@ -1,10 +1,10 @@
1
1
  module CpOraclecloud
2
2
  class SshKeysController < ApplicationController
3
- before_action :set_ssh_key, only: [:show, :edit, :update, :destroy]
3
+ before_action :set_ssh_key, only: [:edit, :update, :destroy]
4
4
 
5
5
  def index
6
6
  authorize SshKey
7
- @ssh_keys = policy_scope(SshKey)
7
+ @ssh_keys = SshKey.all
8
8
  end
9
9
 
10
10
  def new
@@ -12,17 +12,18 @@ module CpOraclecloud
12
12
  @ssh_key = CpOraclecloud::SshKey.new
13
13
  end
14
14
 
15
- def show
16
- authorize @ssh_key
17
- end
15
+ #def show
16
+ # authorize @ssh_key
17
+ #end
18
18
 
19
19
  def create
20
20
  authorize SshKey
21
21
  @ssh_key = SshKey.new(ssh_key_params)
22
22
 
23
- if @ssh_key.save
23
+ if @ssh_key.valid?
24
+ ssh_key = SshKey.create(ssh_key_params)
24
25
  flash[:notice] = "SSH Key has been created."
25
- redirect_to cp_oraclecloud_ssh_keys_path
26
+ redirect_to cp_oraclecloud_admin_path
26
27
  else
27
28
  flash.now[:alert] = "SSH Key has not been created."
28
29
  render "new"
@@ -30,22 +31,23 @@ module CpOraclecloud
30
31
  end
31
32
 
32
33
  def edit
33
- authorize @ssh_key
34
+ #authorize @ssh_key
34
35
  end
35
36
 
36
37
  def destroy
37
38
  authorize @ssh_key
38
- @ssh_key.destroy
39
+ #@ssh_key.destroy
40
+ SshKey.delete(@ssh_key.id)
39
41
  flash[:notice] = "SSH Key has been deleted."
40
42
 
41
- redirect_to cp_oraclecloud_ssh_keys_path
43
+ redirect_to cp_oraclecloud_admin_path
42
44
  end
43
45
 
44
46
  def update
45
47
  authorize @ssh_key
46
- if @ssh_key.update_attributes(ssh_key_params)
48
+ if @ssh_key.update(ssh_key_params)
47
49
  flash[:notice] = "SSH Key has been updated."
48
- redirect_to cp_oraclecloud_ssh_keys_path
50
+ redirect_to cp_oraclecloud_admin_path
49
51
  else
50
52
  flash.now[:alert] = "SSH Key has not been updated."
51
53
  render "edit"
@@ -55,10 +57,10 @@ module CpOraclecloud
55
57
  private
56
58
 
57
59
  def set_ssh_key
58
- @project = CpOraclecloud::SshKey.find(params[:name])
60
+ @ssh_key = CpOraclecloud::SshKey.find_by_id(params[:id])
59
61
  rescue ActiveRecord::RecordNotFound
60
62
  flash[:alert] = "The SSH Key you were looking for could not be found."
61
- redirect_to cp_oraclecloud_ssh_keys_path
63
+ redirect_to cp_oraclecloud_admin_path
62
64
  end
63
65
 
64
66
  def ssh_key_params
@@ -0,0 +1,2 @@
1
+ module CpOraclecloud::AdminHelper
2
+ end
@@ -2,7 +2,7 @@ module CpOraclecloud
2
2
  class ComputeInstance < CloudInstance
3
3
  include CpOraclecloud::ComputeMixin
4
4
 
5
- def provision
5
+ def _provision
6
6
  connection.instances.create(init_config)
7
7
  end
8
8
 
@@ -18,6 +18,10 @@ module CpOraclecloud
18
18
  "Compute"
19
19
  end
20
20
 
21
+ def icon
22
+ "fa-desktop"
23
+ end
24
+
21
25
  def fog
22
26
  @instance ||= connection.instances.get(name)
23
27
  @instance
@@ -21,7 +21,7 @@ module CpOraclecloud
21
21
  validates :backup_destination, :presence => true
22
22
 
23
23
  def pretty_type
24
- 'Oracle Database CS'
24
+ 'Oracle Database Cloud Service'
25
25
  end
26
26
 
27
27
  def pretty_size
@@ -2,10 +2,14 @@ module CpOraclecloud
2
2
  class DatabaseInstance < CloudInstance
3
3
  include CpOraclecloud::DatabaseMixin
4
4
 
5
- def provision
5
+ def _provision
6
6
  @instance = connection.instances.create(init_config)
7
7
  end
8
8
 
9
+ def _deprovision
10
+ fog.destroy()
11
+ end
12
+
9
13
  def wait
10
14
  fog.wait_for { ready? }
11
15
  end
@@ -18,9 +22,17 @@ module CpOraclecloud
18
22
  "Database"
19
23
  end
20
24
 
25
+ def icon
26
+ "fa-database"
27
+ end
28
+
21
29
  def fog
22
- @instance ||= connection.instances.get(name)
23
- @instance
30
+ begin
31
+ @instance ||= connection.instances.get(name)
32
+ @instance
33
+ rescue Fog::OracleCloud::Database::NotFound
34
+ nil
35
+ end
24
36
  end
25
37
 
26
38
  def attr_get(attribute)
@@ -0,0 +1,77 @@
1
+ module CpOraclecloud
2
+ class Image
3
+ include ActiveModel::Validations
4
+ include ActiveModel::Conversion
5
+ extend ActiveModel::Naming
6
+
7
+ attr_accessor :id, :uri, :name, :default, :description, :entries
8
+
9
+ validates :name, :presence => true
10
+
11
+ def initialize(attributes = {})
12
+ if !attributes[:name].blank?
13
+ regex = attributes[:name].match(/\/.*\/(.*)/)
14
+ if regex && regex.length > 1
15
+ clean_name = regex[1]
16
+ attributes[:id] = clean_name
17
+ attributes[:name] = clean_name
18
+ end
19
+ end
20
+ attributes.each do |field, value|
21
+ send("#{field}=", value)
22
+ end
23
+ end
24
+
25
+ def to_s
26
+ name
27
+ end
28
+
29
+ def to_model
30
+ self
31
+ end
32
+
33
+ def persisted?
34
+ !id.blank?
35
+ end
36
+
37
+ def self.all
38
+ result = []
39
+ connection.image_lists.each { |k| result.push(CpOraclecloud::Image.new(k.attributes))}
40
+ result
41
+ end
42
+
43
+ def self.find_by_id(id)
44
+ data = connection.image_lists.get(id)
45
+ CpOraclecloud::Image.new(data.attributes)
46
+ end
47
+
48
+ def self.create(params)
49
+ connection.image_lists.create(:name => params[:name],
50
+ :default => params[:default],
51
+ :description => params[:description])
52
+ end
53
+
54
+ def update(params)
55
+ fog = self.class.connection.image_lists.get(id)
56
+
57
+ [:name, :default, :description].each do |field|
58
+ fog.attributes[field.to_sym] = params[field.to_sym]
59
+ end
60
+ fog.update
61
+ end
62
+
63
+ def self.delete(id)
64
+ connection.image_lists.get(id).destroy
65
+ end
66
+
67
+ def self.connection
68
+ @connection ||= Fog::Compute.new(
69
+ :provider => 'OracleCloud',
70
+ :oracle_username => CpOraclecloud.username,
71
+ :oracle_password => CpOraclecloud.password,
72
+ :oracle_domain => CpOraclecloud.domain,
73
+ :oracle_compute_api => CpOraclecloud.compute_api
74
+ )
75
+ end
76
+ end
77
+ end
@@ -2,7 +2,7 @@ module CpOraclecloud
2
2
  class JavaInstance < CloudInstance
3
3
  include CpOraclecloud::JavaMixin
4
4
 
5
- def provision
5
+ def _provision
6
6
  connection.instances.create(init_config)
7
7
  end
8
8
 
@@ -18,6 +18,10 @@ module CpOraclecloud
18
18
  "Java"
19
19
  end
20
20
 
21
+ def icon
22
+ "fae-java"
23
+ end
24
+
21
25
  def fog
22
26
  @instance ||= connection.instances.get(name)
23
27
  @instance
@@ -25,9 +29,8 @@ module CpOraclecloud
25
29
 
26
30
  def attr_get(attribute)
27
31
  begin
28
- @instance ||= connection.instances.get(name)
29
- @instance.attributes[attribute.to_sym]
30
- rescue Fog::OracleCloud::Database::NotFound
32
+ fog.attributes[attribute.to_sym]
33
+ rescue Fog::OracleCloud::Java::NotFound
31
34
  "Error"
32
35
  end
33
36
  end
@@ -2,7 +2,7 @@ module CpOraclecloud
2
2
  class SoaInstance < CloudInstance
3
3
  include CpOraclecloud::SoaMixin
4
4
 
5
- def provision
5
+ def _provision
6
6
  connection.instances.create(init_config)
7
7
  end
8
8
 
@@ -18,6 +18,10 @@ module CpOraclecloud
18
18
  "SOA"
19
19
  end
20
20
 
21
+ def icon
22
+ "fa-code-fork"
23
+ end
24
+
21
25
  def fog
22
26
  @instance ||= connection.instances.get(name)
23
27
  @instance
@@ -4,45 +4,62 @@ module CpOraclecloud
4
4
  include ActiveModel::Conversion
5
5
  extend ActiveModel::Naming
6
6
 
7
- attr_accessor :uri, :enabled, :key, :name
7
+ attr_accessor :id, :uri, :enabled, :key, :name
8
8
 
9
- validates :enabled, inclusion: [true, false]
9
+ validates :enabled, inclusion: ["true", "false"]
10
10
  validates :key, :presence => true
11
11
  validates :name, :presence => true
12
12
 
13
-
14
13
  def initialize(attributes = {})
15
- attributes.each do |name, value|
16
- send("#{name}=", value)
14
+ if !attributes[:name].blank?
15
+ regex = attributes[:name].match(/\/.*\/(.*)/)
16
+ if regex && regex.length > 1
17
+ clean_name = regex[1]
18
+ attributes[:id] = clean_name
19
+ attributes[:name] = clean_name
20
+ end
21
+ end
22
+ attributes.each do |field, value|
23
+ send("#{field}=", value)
17
24
  end
18
25
  end
19
26
 
27
+ def to_s
28
+ name
29
+ end
30
+
20
31
  def to_model
21
32
  self
22
33
  end
23
34
 
24
35
  def persisted?
25
- false
36
+ !id.blank?
26
37
  end
27
38
 
28
39
  def self.all
29
- connection.ssh_keys
40
+ result = []
41
+ connection.ssh_keys.each { |k| result.push(CpOraclecloud::SshKey.new(k.attributes))}
42
+ result
30
43
  end
31
44
 
32
45
  def self.find_by_id(id)
33
- connection.ssh_keys.get(id)
46
+ data = connection.ssh_keys.get(id)
47
+ CpOraclecloud::SshKey.new(data.attributes)
34
48
  end
35
49
 
36
50
  def self.create(params)
37
51
  connection.ssh_keys.create(:name => params[:name],
38
- :enabled => params[:enabled],
39
- :key => params[:key])
52
+ :enabled => params[:enabled],
53
+ :key => params[:key])
40
54
  end
41
55
 
42
- def save
43
- self.connection.ssh_keys.create(:name => name,
44
- :enabled => enabled,
45
- :key => key)
56
+ def update(params)
57
+ fog_key = self.class.connection.ssh_keys.get(id)
58
+
59
+ [:name, :enabled, :key].each do |field|
60
+ fog_key.attributes[field.to_sym] = params[field.to_sym]
61
+ end
62
+ fog_key.update
46
63
  end
47
64
 
48
65
  def self.delete(id)