Skip to content

Commit

Permalink
old ruby hash styles
Browse files Browse the repository at this point in the history
  • Loading branch information
danryan committed Sep 11, 2012
1 parent ba4c2d7 commit c9fb7f3
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 129 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ gem 'tinder'
gem 'net-ssh'
gem 'net-ssh-multi'
gem 'spice'
gem 'faraday'

# Queue processing
gem 'sidekiq', '~> 2.1.1'
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ DEPENDENCIES
database_cleaner (>= 0.7.2)
email_spec (>= 1.2.1)
factory_girl_rails (>= 3.2.0)
faraday
fog (~> 1.5.0)
foreman
forgery (>= 0.5.0)
Expand Down
13 changes: 7 additions & 6 deletions app/models/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ class Definition < ActiveRecord::Base
has_paper_trail

validates :name,
presence: true,
uniqueness: true# ,
# format: { with: /[]}
:presence => true,
:uniqueness => true# ,
# TODO()
# :format => { with: /[]}
validates :content,
presence: true
:presence => true

def to_pdef
parse
Expand All @@ -22,8 +23,8 @@ def to_param

def to_hash
{
name: name,
content: content# ,
:name => name,
:content => content# ,
# pdef: to_pdef
}
end
Expand Down
12 changes: 6 additions & 6 deletions app/models/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ def to_param

def to_hash
{
type: type,
regex: regex,
class: self.class.name,
options: options,
actions: self.class.allowed_actions
:type => type,
:regex => regex,
:class => self.class.name,
:options => options,
:actions => self.class.allowed_actions
}
end

Expand All @@ -64,7 +64,7 @@ def self.register(type)
end

def on_workitem
Mastermind.logger.debug provider: type, action: action, params: params, fields: fields
Mastermind.logger.debug :provider => type, :action => action, :params => params, :fields => fields

@resource = Mastermind.resources[self.class.type].new(params)

Expand Down
6 changes: 3 additions & 3 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def to_param

def to_hash
{
type: type,
class: self.class.name,
options: options
:type => type,
:class => self.class.name,
:options => options
# actions: self.class.allowed_actions
}
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/provider/cm/chef.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Chef < Provider

def connection
Spice::Connection.new(
server_url: options[:server_url],
client_name: options[:client_name],
client_key: options[:client_key]
:server_url => options[:server_url],
:client_name => options[:client_name],
:client_key => options[:client_key]
)
end

Expand Down
6 changes: 1 addition & 5 deletions app/models/provider/notification/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ class Email < Provider
# delivery_method :smtp, options
# end

action :notify do
requires :subject, :body, :from, :to

action :notify do
# TODO

{}
end

end
Expand Down
24 changes: 21 additions & 3 deletions app/models/provider/remote/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@

module Provider::Remote
class HTTP < Provider

def connection
@connection ||= Faraday.new(:url => resource.url)
end

register :http

action :run do
requires :host, :user, :key_data, :command, :output

# attribute :payload, :type => Object, :default => {}
# attribute :headers, :type => Object, :default => {}
# attribute :url, :type => String
# attribute :verb, :type => String
# attribute :response, :type => String

action :get do
resource.output = run_ssh(resource.command)

{}
end

action :post do
end

action :put do
end

action :delete do
end

end
end
27 changes: 10 additions & 17 deletions app/models/provider/server/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class EC2 < Provider

def connection(region=nil)
Fog::Compute.new(
provider: 'AWS',
aws_access_key_id: options[:aws_access_key_id],
aws_secret_access_key: options[:aws_secret_access_key],
region: (region rescue (params['region'] || 'us-east-1'))
:provider => 'AWS',
:aws_access_key_id => options[:aws_access_key_id],
:aws_secret_access_key => options[:aws_secret_access_key],
:region => (region rescue (params['region'] || 'us-east-1'))
)
end

Expand All @@ -27,20 +27,17 @@ def connection(region=nil)
)
server.wait_for { ready? }

resource.attributes = server.attributes
resource.attributes
update_resource_attributes(server.attributes)
end

action :destroy do
requires :instance_id

server = connection(resource.region).servers.get(resource.instance_id)
server.destroy

server.wait_for { state == 'terminated' }

resource.attributes = server.attributes
resource.attributes
update_resource_attributes(server.attributes)
end

action :stop do
Expand All @@ -51,8 +48,7 @@ def connection(region=nil)

server.wait_for { state == 'stopped' }

resource.attributes = server.attributes
resource.attributes
update_resource_attributes(server.attributes)
end

action :start do
Expand All @@ -63,8 +59,7 @@ def connection(region=nil)

server.wait_for { state == 'running' }

resource.attributes = server.attributes
resource.attributes
update_resource_attributes(server.attributes)
end

action :restart do
Expand All @@ -78,8 +73,7 @@ def connection(region=nil)

server.wait_for { state == 'running' }

resource.attributes = server.attributes
resource.attributes
update_resource_attributes(server.attributes)
end

action :reboot do
Expand All @@ -90,8 +84,7 @@ def connection(region=nil)

server.wait_for { state == 'running' }

resource.attributes = server.attributes
resource.attributes
update_resource_attributes(server.attributes)
end

end
Expand Down
8 changes: 4 additions & 4 deletions app/models/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ class Resource
include ActiveAttr::Model
include ActiveAttr::TypecastedAttributes

attribute :action, type: String
attribute :name, type: String
attribute :type, type: String, default: lambda { self.class.type }
attribute :provider, type: Object, default: lambda { Mastermind.providers[self.class.type] }
attribute :action, :type => String
attribute :name, :type => String
attribute :type, :type => String, :default => lambda { self.class.type }
attribute :provider, :type => Object, :default => lambda { Mastermind.providers[self.class.type] }

validates! :action, :name,
:presence => true
Expand Down
18 changes: 9 additions & 9 deletions app/models/resource/cm/chef/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module Resource::CM
class Chef::Node < Resource
register :chef_node

attribute :name, type: String
attribute :run_list, type: Object, default: []
attribute :automatic, type: Object, default: {}
attribute :default, type: Object, default: {}
attribute :normal, type: Object, default: {}
attribute :override, type: Object, default: {}
attribute :_rev, type: String
attribute :chef_type, type: String, default: "node"
attribute :json_class, type: String, default: "Chef::Node"
attribute :name, :type => String
attribute :run_list, :type => Object, :default => []
attribute :automatic, :type => Object, :default => {}
attribute :default, :type => Object, :default => {}
attribute :normal, :type => Object, :default => {}
attribute :override, :type => Object, :default => {}
attribute :_rev, :type => String
attribute :chef_type, :type => String, :default => "node"
attribute :json_class, :type => String, :default => "Chef::Node"

end
end
2 changes: 1 addition & 1 deletion app/models/resource/mock.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Resource::Mock < Resource
register :mock

attribute :message, type: String
attribute :message, :type => String

validates! :message,
:presence => true,
Expand Down
11 changes: 7 additions & 4 deletions app/models/resource/notification/campfire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ module Resource::Notification
class Campfire < Resource
register :campfire

attribute :message, type: String
attribute :source, type: String, default: 'mastermind'
attribute :message_id, type: String
attribute :message_type, type: String
attribute :message, :type => String
attribute :source, :type => String, :default => 'mastermind'
attribute :message_id, :type => String
attribute :message_type, :type => String

validates! :message,
:presence => true,
:on => :notify
end
end
12 changes: 8 additions & 4 deletions app/models/resource/notification/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ module Resource::Notification
class Email < Resource
register :email

attribute :subject, type: String
attribute :to, type: String
attribute :from, type: String
attribute :body, type: String
attribute :subject, :type => String
attribute :to, :type => String
attribute :from, :type => String
attribute :body, :type => String

validates! :subject, :body, :from, :to,
:presence => true,
:on => :notify

end
end
11 changes: 6 additions & 5 deletions app/models/resource/remote/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module Resource::Remote
class HTTP < Resource
register :http

attribute :payload, type: String
attribute :headers, type: Object, default: {}
attribute :url, type: String
attribute :verb, type: String
attribute :response, type: String
attribute :payload, :type => String
attribute :headers, :type => Object, :default => {}
attribute :url, :type => String
attribute :verb, :type => String
attribute :response, :type => String
attribute :status, :type => String
end
end
13 changes: 7 additions & 6 deletions app/models/resource/remote/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ module Resource::Remote
class SSH < Resource
register :ssh

attribute :command, type: String
attribute :host, type: String
attribute :user, type: String
attribute :key_data, type: String
attribute :output, type: String
attribute :command, :type => String
attribute :host, :type => String
attribute :user, :type => String
attribute :key_data, :type => String
attribute :output, :type => String

validates! :command, :host, :user, :key_data,
presence: true
:presence => true,
:on => :run
end
end
13 changes: 7 additions & 6 deletions app/models/resource/remote/ssh_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ module Resource::Remote
class SSHMulti < Resource
register :ssh_multi

attribute :command, type: String
attribute :hosts, type: Object
attribute :user, type: String
attribute :key_data, type: String
attribute :output, type: String
attribute :command, :type => String
attribute :hosts, :type => Object
attribute :user, :type => String
attribute :key_data, :type => String
attribute :output, :type => String

validates! :command, :hosts, :user, :key_data,
presence: true
:presence => true,
:on => :run
end
end
Loading

0 comments on commit c9fb7f3

Please sign in to comment.