cloudpi-runtime 0.1.1

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 (3) hide show
  1. data/lib/CPRuntime.rb +39 -0
  2. data/lib/Credential.rb +16 -0
  3. metadata +46 -0
data/lib/CPRuntime.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'json'
2
+
3
+ home = File.dirname(__FILE__)
4
+ require File.join(home, 'Credential')
5
+
6
+ module CPRuntime
7
+ def credential_map(service_name)
8
+ 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
+ svc_env = ENV['VCAP_SERVICES']
11
+ services = JSON.parse(svc_env, :symbolize_names => true)
12
+ services.values.map { |srvs|
13
+ srvs.map{ |svc|
14
+ if svc[:label] =~ /^#{service_name}/
15
+ for i in 0..svc[:credentials].length-1 do
16
+ c_map = svc[:credentials][i]
17
+ c = Credential.new
18
+ c.username = c_map[:username]
19
+ c.password = c_map[:password]
20
+ c.host = c_map[:host]!=nil ? c_map[:host] : c_map[:host_ip]
21
+ c.port = c_map[:port]
22
+ c.vhost = c_map[:vhost]
23
+ c.db = c_map[:db]!=nil ? c_map[:db] : c_map[:name]
24
+ credential_map[c.host] = c
25
+ # p c.host
26
+ end
27
+ end
28
+ }
29
+ }
30
+ return credential_map
31
+ end
32
+ end
33
+
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
data/lib/Credential.rb ADDED
@@ -0,0 +1,16 @@
1
+ class Credential
2
+ attr_accessor :host,:port,:db,:username,:password,:vhost
3
+ def to_str
4
+ p @host
5
+ p @port
6
+ p @db
7
+ p @username
8
+ p @password
9
+ p @vhost
10
+ end
11
+ end
12
+
13
+ #
14
+ #c = Credential.new
15
+ #c.hostname= 1
16
+ #c.to_str
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudpi-runtime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - xiaoliang tian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-06 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: get service from cloudpi
15
+ email: xiaoliang.tian@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/CPRuntime.rb
21
+ - lib/Credential.rb
22
+ homepage: http://www.samsungcloud.org
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.7.2
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: support for cloudpi service
46
+ test_files: []