cpruntime 0.2.5 → 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.
data/lib/cpruntime.rb CHANGED
@@ -9,12 +9,38 @@ require 'credential'
9
9
  #require 'cpruntime/redisclient'
10
10
  #require 'cpruntime/memcacheclient'
11
11
 
12
- module CPRuntime
13
- def credential_map(service_name)
12
+ module CPRuntime
13
+ @@service_json_doc = ENV['VCAP_SERVICES']
14
+ META_DATA_PATH = "/metadata/services/"
15
+ def self.service_json_doc= (json)
16
+ @@service_json_doc=json
17
+ end
18
+ def self.service_json_doc()
19
+ @@service_json_doc
20
+ end
21
+ def getHosts()
22
+ hosts = [];
23
+ m = credential_map('membase')
24
+ i=0
25
+ m.each{|k,v|
26
+ h = Hosts.new
27
+ h.hostname = k
28
+ hosts[i] = h
29
+ i = i+1
30
+ }
31
+ return hosts
32
+ end
33
+ def self.refreshDedicatedServiceJsonDoc()
34
+ app_uuid = ENV['app_uuid']
35
+ endpoint = ENV['endpoint']
36
+ @@service_json_doc = `curl #{endpoint}#{META_DATA_PATH}#{app_uuid}`
37
+ end
38
+
39
+ def credential_map(service_name)
14
40
  credential_map = {}
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}]}]}'
17
- services = JSON.parse(svc_env, :symbolize_names => true)
41
+
42
+ #@service_json_doc = '{"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}]}]}'
43
+ services = JSON.parse(@@service_json_doc, :symbolize_names => true)
18
44
  services.values.map { |srvs|
19
45
  srvs.map{ |svc|
20
46
  if svc[:label] =~ /^#{service_name}/
@@ -28,7 +54,7 @@ module CPRuntime
28
54
  c.vhost = c_map[:vhost]
29
55
  c.db = c_map[:db]!=nil ? c_map[:db] : c_map[:name]
30
56
  credential_map[c.host] = c
31
- # p c.host
57
+ # p c.host
32
58
  end
33
59
  end
34
60
  }
@@ -8,7 +8,7 @@ module CPRuntime
8
8
  end
9
9
 
10
10
  class CPRuntime::MemcacheClient
11
- include CPRuntime
11
+ include CPRuntime
12
12
  def create_from_svc(hostname)
13
13
  m = credential_map("membase")
14
14
  c = m[hostname];
@@ -18,4 +18,5 @@ class CPRuntime::MemcacheClient
18
18
  end
19
19
  end
20
20
 
21
- #CPRuntime::MemcacheClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
21
+ #CPRuntime::MemcacheClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
22
+
metadata CHANGED
@@ -1,51 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cpruntime
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.5
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - xiaoliang tian
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-04-09 00:00:00.000000000Z
16
+
17
+ date: 2012-08-17 00:00:00 Z
13
18
  dependencies: []
19
+
14
20
  description: get service from cloudpi
15
21
  email: xiaoliang.tian@gmail.com
16
22
  executables: []
23
+
17
24
  extensions: []
25
+
18
26
  extra_rdoc_files: []
19
- files:
27
+
28
+ files:
20
29
  - lib/cpruntime.rb
21
30
  - lib/credential.rb
22
31
  - lib/cpruntime/memcacheclient.rb
23
- - lib/cpruntime/mongoclient.rb
24
- - lib/cpruntime/mysql2client.rb
25
32
  - lib/cpruntime/rabbitmqclient.rb
26
33
  - lib/cpruntime/redisclient.rb
34
+ - lib/cpruntime/mysql2client.rb
35
+ - lib/cpruntime/mongoclient.rb
27
36
  homepage: http://www.samsungcloud.org
28
37
  licenses: []
38
+
29
39
  post_install_message:
30
40
  rdoc_options: []
31
- require_paths:
41
+
42
+ require_paths:
32
43
  - lib
33
- required_ruby_version: !ruby/object:Gem::Requirement
44
+ required_ruby_version: !ruby/object:Gem::Requirement
34
45
  none: false
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: '0'
39
- required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
54
  none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
45
62
  requirements: []
63
+
46
64
  rubyforge_project:
47
- rubygems_version: 1.7.2
65
+ rubygems_version: 1.8.15
48
66
  signing_key:
49
67
  specification_version: 3
50
68
  summary: support for cloudpi service
51
69
  test_files: []
70
+