Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
96f34fc
added chef assembly sample
dmohanty09 Dec 31, 2013
51d2892
Merge branch 'console_output' into assembly
dmohanty09 Dec 31, 2013
84ae752
converted assembilies to inherit get_output from computeInstance, add…
dmohanty09 Dec 31, 2013
79f5f1a
Appended chef output to stdout
dmohanty09 Dec 31, 2013
55c16f9
fixed spinner
dmohanty09 Jan 3, 2014
4d2d54a
implemented user data
dmohanty09 Jan 7, 2014
d4ff8a5
Implemented Key storage functionality via DataMapper
dmohanty09 Jan 7, 2014
07f00f2
added user api
dmohanty09 Jan 9, 2014
e018f58
Merge branch 'user_data' into assembly
dmohanty09 Jan 10, 2014
f4a3474
implemented puppet assembly
dmohanty09 Jan 15, 2014
32b5062
private dns name for node name
dmohanty09 Jan 16, 2014
f48942a
changed packages to be an array on enc yaml
dmohanty09 Jan 16, 2014
6e6689d
changed packages to be an array on enc yaml
dmohanty09 Jan 16, 2014
c7d0f8a
fixed get_output merge conflict
dmohanty09 Jan 16, 2014
8fd638c
encapsulating assembly spec tests
dmohanty09 Jan 21, 2014
1859d03
implemented Chef Assembly integration test create -> destroy
dmohanty09 Jan 21, 2014
c4ae0bf
converted puppet assembly to use ssh on the master to configure exter…
dmohanty09 Jan 22, 2014
3de965b
converted puppet bootstrap to take place via ssh as opposed to user_d…
dmohanty09 Jan 22, 2014
c7be424
wrote integration test for PuppetAssembly validating configuration of…
dmohanty09 Jan 22, 2014
cb49228
increased complexity threshold
dmohanty09 Jan 23, 2014
3b08a73
implemented Salt Assembly
dmohanty09 Jan 24, 2014
8934cab
implemented Salt Assembly integration test
dmohanty09 Jan 24, 2014
bf59003
added assemblies .harp script
dmohanty09 Jan 24, 2014
72eba88
added rake task db:seed and converted assembly_spec to generate Keys …
dmohanty09 Jan 24, 2014
d0cfc63
merged master
dmohanty09 Jan 24, 2014
e875cdb
added a check for access/secret keys in the db:seed rake task and add…
dmohanty09 Jan 27, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ PATH
dm-mysql-adapter
dm-sqlite-adapter
extlib
faraday (= 0.8.9)
fog
httparty
json
logging
net-ssh
Expand Down Expand Up @@ -69,12 +71,12 @@ GEM
dm-transactions (~> 1.2.0)
dm-types (~> 1.2.0)
dm-validations (~> 1.2.0)
debugger (1.6.3)
debugger (1.6.5)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.2.4)
debugger-ruby_core_source (~> 1.3.1)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.4)
debugger-ruby_core_source (1.3.1)
delayed_job (2.1.4)
activesupport (~> 3.0)
daemons
Expand Down Expand Up @@ -127,16 +129,16 @@ GEM
data_objects (= 0.10.13)
do_sqlite3 (0.10.13)
data_objects (= 0.10.13)
docile (1.1.1)
docile (1.1.2)
erubis (2.7.0)
evalhook (0.5.7)
evalhook (0.5.8)
partialruby (~> 0.3)
sexp_processor (~> 4.0)
excon (0.28.0)
excon (0.31.0)
extlib (0.9.16)
factory_girl (4.3.0)
activesupport (>= 3.0.0)
faraday (0.8.8)
faraday (0.8.9)
multipart-post (~> 1.2.0)
fastercsv (1.5.5)
ffi (1.9.3)
Expand All @@ -146,9 +148,9 @@ GEM
flog (4.2.0)
ruby_parser (~> 3.1, > 3.1.0)
sexp_processor (~> 4.4)
fog (1.18.0)
fog (1.19.0)
builder
excon (~> 0.28.0)
excon (~> 0.31.0)
formatador (~> 0.2.0)
mime-types
multi_json (~> 1.0)
Expand All @@ -160,9 +162,12 @@ GEM
getsource (0.2.1)
gssapi (1.0.3)
ffi (>= 1.0.1)
gyoku (1.1.0)
gyoku (1.1.1)
builder (>= 2.1.2)
hashie (2.0.5)
httparty (0.12.0)
json (~> 1.8)
multi_xml (>= 0.5.2)
httpclient (2.3.4.1)
httpi (0.9.7)
rack
Expand All @@ -183,13 +188,14 @@ GEM
mixlib-authentication (1.3.0)
mixlib-log
mixlib-log (1.6.0)
multi_json (1.8.2)
multi_json (1.8.4)
multi_xml (0.5.5)
multipart-post (1.2.0)
net-http-persistent (2.9)
net-http-persistent (2.9.1)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.7.0)
nio4r (0.5.0)
nio4r (1.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
nori (1.1.5)
Expand All @@ -206,17 +212,17 @@ GEM
puma (2.7.1)
rack (>= 1.1, < 2.0)
rack (1.5.2)
rack-protection (1.5.1)
rack-protection (1.5.2)
rack
rack-test (0.6.2)
rack (>= 1.0)
racksh (1.0.0)
rack (>= 1.0)
rack-test (>= 0.5)
rake (10.1.0)
rake (10.1.1)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.3)
retryable (1.3.4)
rgl (0.4.0)
rake
stream (>= 0.5)
Expand Down Expand Up @@ -255,7 +261,7 @@ GEM
ruby2ruby (2.0.7)
ruby_parser (~> 3.1)
sexp_processor (~> 4.0)
ruby_parser (3.2.2)
ruby_parser (3.3.0)
sexp_processor (~> 4.1)
rubyntlm (0.1.1)
savon (0.9.5)
Expand Down Expand Up @@ -306,7 +312,7 @@ GEM
json (>= 1.4.6)
launchy (>= 2.0.0)
uuidtools (2.1.4)
varia_model (0.2.0)
varia_model (0.3.2)
buff-extensions (~> 0.2)
hashie (>= 2.0.2)
wasabi (1.0.0)
Expand Down
18 changes: 17 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ task :jslint do
end
end

namespace :db do
require "data_mapper"
require 'harp-runtime/models/user_data'
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/dev.db")
DataMapper.finalize
DataMapper.auto_upgrade!

desc "Seed the database with configuration settings."
task :seed do
cnf = YAML::load_file(File.join(File.dirname(File.expand_path(__FILE__)), 'config/settings.yaml'))
raise "Default Access/Secret keys not configured." if cnf['default_creds']['access']== 12345 || cnf['default_creds']['secret']== 67890
cnf['default_creds']['keys'].each{|k| Key.first_or_create(:name=>k['name']).update(:value=>k['private_key']) }
puts "Seeded Keys..."
end
end

begin
namespace :analyzer do
desc "run all code analyzing tools (flog)"
Expand All @@ -45,7 +61,7 @@ begin
require 'flog_cli'
desc "Analyze total code complexity with flog"
task :total do
threshold = 10
threshold = 20
flog = FlogCLI.new
flog.flog %w(app lib spec)
average = flog.average.round(1)
Expand Down
19 changes: 19 additions & 0 deletions app/harp_user_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'sinatra/base'
require 'logging'

class HarpUserApiApp < Sinatra::Base

post '/key' do
key = JSON.parse(request.body.read).symbolize_keys
Key.create(key).to_json
end

get '/key/:key_name' do
Key.get_by_name(params[:key_name]).to_json
end

get '/puppet-emc/:master_ip' do
PuppetENC.find(params[:master_ip]).first.attributes[:yaml]
end

end
12 changes: 12 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require 'app/root'
require 'app/api_base'
require 'app/harp_api'
require 'app/harp_debug_api'
require 'app/harp_user_api'
require 'app/editor'
require 'data_mapper'
require 'delayed_job_data_mapper'
Expand Down Expand Up @@ -69,6 +70,17 @@ map "/api/v1/harp" do
run HarpApiApp
end

#
# Harp User API
#
##~ a = sapi.apis.add
##
##~ a.set :path => "/user.{format}", :format => "json"
##~ a.description = "Harp User API"
map "/api/v1/user" do
run HarpUserApiApp
end

map "/edit" do
run EditorApp
end
Expand Down
31 changes: 31 additions & 0 deletions config/settings.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,34 @@
default_creds:
access: 12345
secret: 67890
keys:
-
name: default
private_key: |
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAyXrPvzeVEj796mWg5xV3yi39SAXBXPFH/03xQFe0v8egSdOi
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hjDkvqSpovzQey7nrAk2ab51l68I1tol
Xm7Rw+zwL9oASOb10iH8Pcv9k8clUs7a7GhDfVVU65nfqPcpx7/NQkugSqmpfg00
9hhnFKqMSgnknVQ+Eut+fvMCgYAyumrFPPiv8XD51ttAbsskhP9S0VlOKMCYprXK
T0pW54e9AModCmgJftIU7db6pwaHSyDOptJxq1vpLybb+u3psDVjeFEdhrkmlQ+2
DU1MMOtm4OSTviLsZS9e8b86c9I9q+q3sc5/E8Pdp8xhNnZI3vdNfaQzj6bJJETK
kpFLzQKBgFzSMD0t8Kbxb4O226HSgZevqNqXSuk/KbAsc3WB4xhCbCb8rd2v3q+6
LMWSJN9ynkkrf1KUfR0MHh0rQLCI3GUig5+JRf9ljnpPhe14zn8h/2tX4pW5AWSF
jz3nB3v6Tj0KktAKoOAYHlezQMgkiZ57nZwDGRdFoj838Hm1hwHz
-----END RSA PRIVATE KEY-----
2 changes: 2 additions & 0 deletions harp-runtime.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "puma"
gem.add_runtime_dependency "delayed_job"
gem.add_runtime_dependency "delayed_job_data_mapper"
gem.add_runtime_dependency "faraday",["= 0.8.9"]
gem.add_runtime_dependency "ridley"
gem.add_runtime_dependency "ridley-connectors"
gem.add_runtime_dependency "httparty"

gem.add_development_dependency "rspec"
gem.add_development_dependency "shotgun"
Expand Down
11 changes: 6 additions & 5 deletions lib/harp-runtime/cloud/cloud_mutator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ def get_harp_resource(resource_name)
end

def get_output(resource, persisted)
resource = Harp::Resources::AvailableResource.from_name resource['type']
if resource.nil?
@@logger.error "No resource type #{resource_def['type']}"
res = Harp::Resources::AvailableResource.from_name resource['type']
if res.nil?
@@logger.error "No resource type #{resource['type']}"
return
end
service = establish_connect(resource)
output = resource.get_output(service, persisted)
res.populate(resource)
service = establish_connect(res)
output = res.get_output(service, persisted)
end

def add_all(resources)
Expand Down
8 changes: 7 additions & 1 deletion lib/harp-runtime/models/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ class Assembly < HarpResource

# AssemblyChef is the datastore representation of a Harp Assembly with Chef.
class AssemblyChef < HarpResource
property :public_ip_address, String
property :private_ip_address, String
end

# AssemblyPuppet is the datastore representation of an Assembly with Puppet.
class AssemblyPuppet < HarpResource
property :public_ip_address, String
property :private_ip_address, String
end

# AssemblySalt is the datastore representation of an Assembly with Salt.
class AssemblySalt < HarpResource
property :public_ip_address, String
property :private_ip_address, String
end

# AssemblyDocker is the datastore representation of an Assembly with Docker.
class AssemblyDocker < HarpResource
end
end
37 changes: 37 additions & 0 deletions lib/harp-runtime/models/user_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'harp-runtime/models/base'

# Represents a harp user.
class HarpUser
include DataMapper::Resource
property :id, Serial, :key => true

property :name, String

has n, :harp_scripts, :through => Resource
has n, :keys, :through => Resource
end

class Key
include DataMapper::Resource
property :id, Serial
property :name, String, :key => true
property :value, Text

has n, :harp_users, :through => Resource

def temp_file
t = Tempfile.new(name)
t << value
t.close
t
end
def self.get_by_name(key_name)
Key.all(:name => key_name).first
end
end

class PuppetENC
include DataMapper::Resource
property :master_ip, String, :key => true
property :yaml, Text
end
31 changes: 28 additions & 3 deletions lib/harp-runtime/resources/assembly/assembly.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'set'
require 'fog/core/model'
require 'harp-runtime/models/assembly'
require 'harp-runtime/models/user_data'
require 'harp-runtime/resources/compute/instance'
require 'json'

module Harp
Expand All @@ -9,7 +11,7 @@ module Resources
# An Assembly is an operating system image combined with some bootstrapped
# configuration. For example, an Ubuntu image with a Chef client and an
# initial Chef role can be saved as an assembly.
class Assembly < AvailableResource
class Assembly < ComputeInstance

include Harp::Resources

Expand Down Expand Up @@ -41,12 +43,14 @@ def self.persistent_type()
end

def create(service)
@service = service
provisioner = init_provisioner
atts = self.attribs[:attributes]
assembly = service.servers.create(atts[:server_options].symbolize_keys)
assembly.wait_for { ready? }
self.id = assembly.id
provision_server(assembly.public_ip_address)
return self
provision_server(assembly.public_ip_address,provisioner)
return assembly
end

def destroy(service)
Expand All @@ -59,6 +63,27 @@ def destroy(service)
return self
end

# Return a token to signify output from the current action
def output_token(args={})
return "#{name}:#{id}"
end

def get_output(service, persisted)
output = ""
output = get_provisioner_output(service, persisted)
response = service.get_console_output(persisted.id)
if response.status == 200
output += "\nstdout:\n"
output += response.body['output'] if !response.body['output'].nil?
# escape special characters to ensure valid JSON.
output = output.gsub('"', '\\"')
output = output.gsub("\r", '')
output = output.gsub("\n", '\\n')
output = output.gsub("\e", 'ESC')
end
output
end

end
end
end
Loading