cloudpi-runtime 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/CPRuntime.rb +9 -8
- data/lib/Credential.rb +1 -0
- data/lib/cpruntime/MemcacheClient.rb +21 -0
- data/lib/cpruntime/MongoClient.rb +28 -0
- data/lib/cpruntime/MySql2Client.rb +19 -0
- data/lib/cpruntime/RabbitMQClient.rb +21 -0
- data/lib/cpruntime/RedisClient.rb +21 -0
- metadata +6 -1
data/lib/CPRuntime.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
3
|
home = File.dirname(__FILE__)
|
4
|
-
|
4
|
+
$:.unshift(File.dirname(__FILE__))
|
5
|
+
require 'credential'
|
6
|
+
|
7
|
+
#require 'cpruntime/rabbitmqclient'
|
8
|
+
#require 'cpruntime/mongoclient'
|
9
|
+
#require 'cpruntime/redisclient'
|
10
|
+
#require 'cpruntime/memcacheclient'
|
5
11
|
|
6
12
|
module CPRuntime
|
7
13
|
def credential_map(service_name)
|
8
14
|
credential_map = {}
|
9
|
-
#svc_env = '{"mongodb-2.0.20":[{"name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","label":"mongodb-2.0.20","plan":"free","credentials":[{"username":"scalr","host":"ec2-23-20-254-0.compute-1.amazonaws.com","password":"uUfigF6Dlq","name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","db":"cloudpidb","hostname":"ec2-23-20-254-0.compute-1.amazonaws.com","type":"slave","port":27017},{"username":"scalr","host":"ec2-107-22-7-246.compute-1.amazonaws.com","password":"uUfigF6Dlq","name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","db":"cloudpidb","hostname":"ec2-107-22-7-246.compute-1.amazonaws.com","type":"slave","port":27017}]}]}' #svc_env = ENV['VCAP_SERVICES']
|
10
15
|
svc_env = ENV['VCAP_SERVICES']
|
16
|
+
#svc_env = '{"mongodb-2.0.20":[{"name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","label":"mongodb-2.0.20","plan":"free","credentials":[{"username":"scalr","host":"ec2-23-20-254-0.compute-1.amazonaws.com","password":"uUfigF6Dlq","name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","db":"cloudpidb","hostname":"ec2-23-20-254-0.compute-1.amazonaws.com","type":"slave","port":27017},{"username":"scalr","host":"ec2-107-22-7-246.compute-1.amazonaws.com","password":"uUfigF6Dlq","name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","db":"cloudpidb","hostname":"ec2-107-22-7-246.compute-1.amazonaws.com","type":"slave","port":27017}]}]}'
|
11
17
|
services = JSON.parse(svc_env, :symbolize_names => true)
|
12
18
|
services.values.map { |srvs|
|
13
19
|
srvs.map{ |svc|
|
@@ -31,9 +37,4 @@ module CPRuntime
|
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
|
-
#
|
35
|
-
|
36
|
-
#p CloudpiRuntime.class
|
37
|
-
#p CloudpiRuntime::MongoClient.class.methods
|
38
|
-
#CloudpiRuntime::MongoClient.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
39
|
-
#include CloudpiRuntime
|
40
|
+
#CPRuntime::MongoClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
data/lib/Credential.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'memcache'
|
2
|
+
require File.join(File.dirname(__FILE__), '../cpruntime')
|
3
|
+
|
4
|
+
module CPRuntime
|
5
|
+
class MemcacheClient
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class CPRuntime::MemcacheClient
|
11
|
+
include CPRuntime
|
12
|
+
def create_from_svc(hostname)
|
13
|
+
m = credential_map("membase")
|
14
|
+
c = m[hostname];
|
15
|
+
p c
|
16
|
+
client = MemCache.new(c.host+":"+c.port)
|
17
|
+
return client
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#CPRuntime::MemcacheClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
|
3
|
+
#$:.unshift(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), '../cpruntime')
|
6
|
+
|
7
|
+
module CPRuntime
|
8
|
+
class MongoClient
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class CPRuntime::MongoClient
|
14
|
+
include CPRuntime
|
15
|
+
def create_from_svc(hostname)
|
16
|
+
m = credential_map("mongo")
|
17
|
+
c = m[hostname];
|
18
|
+
p c
|
19
|
+
db = Mongo::Connection.new(c.host,c.port).db(c.db)
|
20
|
+
auth = db.authenticate(c.username,c.password)
|
21
|
+
return db
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
#db = CPRuntime::MongoClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
26
|
+
#coll = db.collection("users")
|
27
|
+
#coll.insert("name" => "tian","age" => "25")
|
28
|
+
#p coll.find("name" => "tian").to_a.to_s
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mysql2'
|
2
|
+
require File.join(File.dirname(__FILE__), '../cpruntime')
|
3
|
+
|
4
|
+
module CPRuntime
|
5
|
+
class MySql2Client
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class CPRuntime::MySql2Client
|
10
|
+
include CPRuntime
|
11
|
+
def create_from_svc(hostname)
|
12
|
+
m = credential_map("mysql")
|
13
|
+
c = m[hostname]
|
14
|
+
p c
|
15
|
+
client = Mysql2::Client.new(:host => c.host,:username => c.username,:password=>c.password,:database=>c.db,:port=>c.port)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#CloudpiRuntime::MySql2Client.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bunny'
|
2
|
+
require File.join(File.dirname(__FILE__), '../cpruntime')
|
3
|
+
|
4
|
+
module CPRuntime
|
5
|
+
class RabbitMQClient
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class CPRuntime::RabbitMQClient
|
11
|
+
include CPRuntime
|
12
|
+
def create_from_svc(hostname)
|
13
|
+
m = credential_map("rabbit")
|
14
|
+
c = m[hostname];
|
15
|
+
p c
|
16
|
+
client = Bunny.new(:host => c.host,:port => c.port,:pass => c.password,:user=>c.username,:vhost=>c.vhost)
|
17
|
+
return client
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#CloudpiRuntime::RabbitMQClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require File.join(File.dirname(__FILE__), '../cpruntime')
|
3
|
+
|
4
|
+
module CPRuntime
|
5
|
+
class RedisClient
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class CPRuntime::RedisClient
|
11
|
+
include CPRuntime
|
12
|
+
def create_from_svc(hostname)
|
13
|
+
m = credential_map("redis")
|
14
|
+
c = m[hostname];
|
15
|
+
p c
|
16
|
+
client = Redis.new(:host => c.host,:port => c.port,:password => c.password)
|
17
|
+
return client
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#CloudpiRuntime::RedisClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudpi-runtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,11 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/CPRuntime.rb
|
21
21
|
- lib/Credential.rb
|
22
|
+
- lib/cpruntime/MemcacheClient.rb
|
23
|
+
- lib/cpruntime/MongoClient.rb
|
24
|
+
- lib/cpruntime/MySql2Client.rb
|
25
|
+
- lib/cpruntime/RabbitMQClient.rb
|
26
|
+
- lib/cpruntime/RedisClient.rb
|
22
27
|
homepage: http://www.samsungcloud.org
|
23
28
|
licenses: []
|
24
29
|
post_install_message:
|