cp_aws 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7387e730e94f6166e13cf7a9bbaf030806bce617
4
+ data.tar.gz: 330c27228ce33b6a3abf11c4b173b46970d35689
5
+ SHA512:
6
+ metadata.gz: 7083f4b95315a926eb7fe07b966c82634ca2049629026ee9438a316fb8c76c8229a8d817b7f9d814f67285e4f053ab14106346a5935e975207eab35291428779
7
+ data.tar.gz: 2c2591172b5118a32c9326382a11edf920d4ab95647e4aeef2386133f0030400e9062bf6c339196dd633ee3abdb9be703d7366369b4468d4290e9c1a7d1675fb
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Joel Nation
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # CpAws
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'cp_aws'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install cp_aws
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'CpAws'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/cp_aws .js
2
+ //= link_directory ../stylesheets/cp_aws .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -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,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -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,5 @@
1
+ module CpAws
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module CpAws
2
+ class Ec2ComponentsController < CloudComponentsController
3
+ def component_params
4
+ params.require(:cp_aws_ec2_component).permit(:name, :flavor_id, :availability_zone, :tenancy, :placement_group)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module CpAws
2
+ class Ec2InstancesController < CloudInstancesController
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module CpAws
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module CpAws
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module CpAws
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module CpAws
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ module CpAws
2
+ class Ec2Component < CloudComponent
3
+ include CpAws::Ec2Mixin
4
+
5
+ store :config, accessors: [:tags, :flavor_id, :availability_zone, :tenancy, :placement_group], coder: JSON
6
+
7
+ enum tenancy: [:default, :dedicated, :host]
8
+
9
+ validates :name, :presence => true
10
+
11
+ def name
12
+ self.tags['name'] unless self.tags.nil?
13
+ end
14
+
15
+ def name= value
16
+ self.tags = {} unless !self.tags.nil?
17
+ self.tags['name'] = value
18
+ end
19
+
20
+ def pretty_type
21
+ 'Amazon EC2 Instance'
22
+ end
23
+
24
+ def instance_name
25
+ if !name.nil? then name end
26
+ end
27
+
28
+ def instance_type
29
+ "CpAws::Ec2Instance"
30
+ end
31
+
32
+ def flavors
33
+ connection.flavors
34
+ end
35
+
36
+ def regions
37
+ {
38
+ 'US East (N.Virignia)': 'us-east-1',
39
+ 'US East (Ohio)': 'us-east-2',
40
+ 'US West (N. California)': 'us-west-1',
41
+ 'US West (Oregon)': 'us-west-2',
42
+ 'Asia Pacific (Mumbai)': 'ap-south-1',
43
+ 'Asia Pacific (Seoul)': 'ap-northeast-2',
44
+ 'Asia Pacific (Singapore)': 'ap-southeast-1',
45
+ 'Asia Pacific (Sydney)': 'ap-southeast-2',
46
+ 'Asia Pacific (Tokyo)': 'ap-northeast-1',
47
+ 'Canada (Central)': 'ca-central-1',
48
+ 'China (Beijing)': 'cn-north-1',
49
+ 'EU (Frankfurt)': 'eu-central-1',
50
+ 'EU (Ireland)': 'eu-west-1',
51
+ 'EU (London)': 'eu-west-2',
52
+ 'South America (Sao Paulo)': 'sa-east-1',
53
+ 'AWS GovCloud (US)': 'us-gov-west-1'
54
+ }
55
+ end
56
+
57
+ def connection
58
+ @connection ||= Fog::Compute.new :provider => 'AWS', :region => CpAws.region, :aws_access_key_id => CpAws.aws_access_key_id, :aws_secret_access_key => CpAws.aws_secret_access_key
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,58 @@
1
+ module CpAws
2
+ class Ec2Instance < CloudInstance
3
+ include CpAws::Ec2Mixin
4
+
5
+ def to_s
6
+ init_config['tags']['name'].nil? ? name : init_config['tags']['name']
7
+ end
8
+
9
+ def provider
10
+ "AWS"
11
+ end
12
+
13
+ def cloud_type
14
+ "EC2"
15
+ end
16
+
17
+ def icon
18
+ "fa-desktop"
19
+ end
20
+
21
+ def calc_cost(start_date, end_date)
22
+ cost = 0
23
+ cost = (end_date - start_date) * (month_cost / 30)
24
+ cost
25
+ end
26
+
27
+ def month_cost
28
+ cost = calculate_monthly_cost(init_config)
29
+ cost
30
+ end
31
+
32
+ def _provision
33
+ @server = connection.servers.create(init_config)
34
+ self.update(name: @server.id)
35
+ end
36
+
37
+ def fog
38
+ @server ||= connection.servers.get(name)
39
+ @server
40
+ end
41
+
42
+ def attr_get(attribute)
43
+ begin
44
+ fog.attributes[attribute.to_sym]
45
+ rescue Fog::Compute::AWS::NotFound
46
+ "Error"
47
+ end
48
+ end
49
+
50
+ def wait
51
+ fog.wait_for { ready? }
52
+ end
53
+
54
+ def connection
55
+ @connection ||= Fog::Compute.new :provider => 'AWS', :region => CpAws.region, :aws_access_key_id => CpAws.aws_access_key_id, :aws_secret_access_key => CpAws.aws_secret_access_key
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module CpAws
2
+
3
+ class Ec2ComponentPolicy < CloudComponentPolicy
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module CpAws
2
+
3
+ class Ec2InstancePolicy < CloudInstancePolicy
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ <ul class="nav nav-tabs">
2
+ <li role="presentation" class="nav-item"><a href="#general" class="nav-link" data-toggle="tab">General</a></li>
3
+ <li role="presentation" class="nav-item"><a href="#placement" class="nav-link" data-toggle="tab">Placement</a></li>
4
+ </ul>
5
+ <div class="tab-content ">
6
+ <div class="tab-pane active" id="general">
7
+ <%= f.input :name %>
8
+ <%= f.input :flavor_id, collection: @component.flavors, label_method: lambda { | flav| "#{flav.name} (#{flav.id})"} %>
9
+ </div>
10
+ <div class="tab-pane" id="placement">
11
+ <%= f.input :availability_zone, collection: @component.regions %>
12
+ <%= f.input :tenancy %>
13
+ <%= f.input :placement_group %>
14
+ </div>
15
+ </div>
@@ -0,0 +1,35 @@
1
+ </div>
2
+ </div>
3
+ <div class="row">
4
+ <div class="col-md-8">
5
+ <div class="row">
6
+ <div class="col-xs-6 col-lg-4">
7
+ <div class="card">
8
+ <div class="card-block p-a-0 clearfix">
9
+ <i class="fa fa-dollar bg-primary p-a-2 font-2xl m-r-1 pull-left"></i>
10
+ <div class="h5 text-primary m-b-0 p-t-1"><%= number_to_currency(instance.month_cost) %></div>
11
+ <div class="text-muted text-uppercase font-weight-bold font-xs">Cost Per Month</div>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ <div class="col-xs-6 col-lg-4">
16
+ <div class="card">
17
+ <div class="card-block p-a-0 clearfix">
18
+ <i class="fa fa-heartbeat bg-<%= instance.attr_get('state') == 'running' ? 'success' : 'danger' %> p-a-2 font-2xl m-r-1 pull-left"></i>
19
+ <div class="h5 text-<%= instance.attr_get('state') == 'running' ? 'success' : 'danger' %> m-b-0 p-t-1"><%= instance.attr_get('state').capitalize %></div>
20
+ <div class="text-muted text-uppercase font-weight-bold font-xs">Status</div>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ <div class="col-xs-6 col-lg-4">
25
+ <div class="card">
26
+ <div class="card-block p-a-0 clearfix">
27
+ <i class="fa fa-list-alt bg-info p-a-2 font-2xl m-r-1 pull-left"></i>
28
+ <div class="h5 text-info m-b-0 p-t-1"><%= instance.attr_get('flavor_id') %></div>
29
+ <div class="text-muted text-uppercase font-weight-bold font-xs">Flavour</div>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
@@ -0,0 +1,14 @@
1
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">AWS<span class="caret"></span>
2
+ </button>
3
+ <ul class="dropdown-menu">
4
+ <% CpAws.active_components.each do | comp | %>
5
+ <li class="dropdown-item">
6
+ <% if comp == 'EC2' %>
7
+ <%= link_to [@product, CpAws::Ec2Component, action: :new] do %>
8
+ <i class="fa fa-desktop"></i>
9
+ EC2 Instance
10
+ <% end %>
11
+ <% end %>
12
+ </li>
13
+ <% end %>
14
+ </ul>
@@ -0,0 +1 @@
1
+ Fog.mock!
@@ -0,0 +1,12 @@
1
+ Rails.application.routes.draw do
2
+ namespace :cp_aws do
3
+ get 'admin' => 'admin#dashboard'
4
+ resources :ec2_instances, type: 'CpAws::Ec2Instance'
5
+ end
6
+
7
+ resources :products do
8
+ namespace :cp_aws do
9
+ resources :ec2_components, type: 'CpAws::Ec2Component'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ require "cp_aws/engine"
2
+
3
+ module CpAws
4
+ extend ActiveSupport::Autoload
5
+
6
+ mattr_accessor :aws_access_key_id
7
+ mattr_accessor :aws_secret_access_key
8
+ mattr_accessor :region
9
+ mattr_accessor :active_components
10
+ mattr_accessor :rate_card
11
+
12
+ autoload :Ec2Mixin
13
+
14
+ def self.setup
15
+ yield self
16
+ end
17
+
18
+ def self.to_s
19
+ "AWS"
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module CpAws
2
+ module Ec2Mixin
3
+ def calculate_monthly_cost(override=nil)
4
+ if override.nil? then override = config end
5
+
6
+ #type = !override['flavor_id'].nil? ? override['flavor_id'] : (flavor_id || fog.flavor_id)
7
+ if override['flavor_id'] then type = override['flavor_id']
8
+ elsif defined? flavor_id and !flavor_id.nil? then type = flavor_id
9
+ elsif defined? fog and !fog.nil? then type = fog.flavor_id
10
+ else type = 't1.micro' end
11
+ puts "Type: #{type}"
12
+
13
+ case CpAws.region
14
+ when 'us-west-2'
15
+ case type
16
+ when 't1.micro'
17
+ rate = 0.02
18
+ when 'm1.large'
19
+ rate = 0.175
20
+ else
21
+ rate = 0
22
+ end
23
+ end
24
+ rate * 24 * 30
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ require 'fog/aws'
2
+
3
+ module CpAws
4
+ class Engine < ::Rails::Engine
5
+
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module CpAws
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cp_aws do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cp_aws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joel Nation
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: fog-aws
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: sqlite3
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: Plugin for Cloud_Portal to add support for Amazon Web Services
62
+ email:
63
+ - joel.nation@outlook.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - app/assets/config/cp_aws_manifest.js
72
+ - app/assets/javascripts/cp_aws/application.js
73
+ - app/assets/javascripts/cp_aws/cp_aws/ec2_components.js
74
+ - app/assets/stylesheets/cp_aws/application.css
75
+ - app/assets/stylesheets/cp_aws/cp_aws/ec2_components.css
76
+ - app/controllers/cp_aws/application_controller.rb
77
+ - app/controllers/cp_aws/ec2_components_controller.rb
78
+ - app/controllers/cp_aws/ec2_instances_controller.rb
79
+ - app/helpers/cp_aws/application_helper.rb
80
+ - app/jobs/cp_aws/application_job.rb
81
+ - app/mailers/cp_aws/application_mailer.rb
82
+ - app/models/cp_aws/application_record.rb
83
+ - app/models/cp_aws/ec2_component.rb
84
+ - app/models/cp_aws/ec2_instance.rb
85
+ - app/policies/cp_aws/ec2_component_policy.rb
86
+ - app/policies/cp_aws/ec2_instance_policy.rb
87
+ - app/views/cp_aws/ec2_components/_fields.html.erb
88
+ - app/views/cp_aws/ec2_instances/_show.html.erb
89
+ - app/views/products/_cp_aws_component_menu.html.erb
90
+ - config/initializers/fog.rb
91
+ - config/routes.rb
92
+ - lib/cp_aws.rb
93
+ - lib/cp_aws/ec2_mixin.rb
94
+ - lib/cp_aws/engine.rb
95
+ - lib/cp_aws/version.rb
96
+ - lib/tasks/cp_aws_tasks.rake
97
+ homepage: http://github.com/Joelith
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Plugin for Cloud_Portal to add support for Amazon Web Services
121
+ test_files: []