cloudpi 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.
- data/lib/CloudpiRuntime.rb +39 -0
- data/lib/Credential.rb +16 -0
- data/lib/client/MemcacheClient.rb +23 -0
- data/lib/client/MongoClient.rb +28 -0
- data/lib/client/MySql2Client.rb +22 -0
- data/lib/client/RabbitMQClient.rb +23 -0
- data/lib/client/RedisClient.rb +23 -0
- data/lib/test.rb +2 -0
- metadata +52 -0
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            home =   File.dirname(__FILE__)
         | 
| 4 | 
            +
            require File.join(home, 'Credential')
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module CloudpiRuntime
         | 
| 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,23 @@ | |
| 1 | 
            +
            require '../CloudpiRuntime'
         | 
| 2 | 
            +
            require 'memcache'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','..','vendor','cache')))
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module CloudpiRuntime
         | 
| 7 | 
            +
              class MemcacheClient
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            class CloudpiRuntime::MemcacheClient
         | 
| 13 | 
            +
              include CloudpiRuntime
         | 
| 14 | 
            +
              def create_from_svc(hostname)
         | 
| 15 | 
            +
                m = credential_map("membase")
         | 
| 16 | 
            +
                c = m[hostname];
         | 
| 17 | 
            +
                p c
         | 
| 18 | 
            +
                client = MemCache.new(c.host+":"+c.port)
         | 
| 19 | 
            +
                return client
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            #CloudpiRuntime::MemcacheClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require '../CloudpiRuntime'  
         | 
| 2 | 
            +
            require 'mongo'
         | 
| 3 | 
            +
            $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','..','vendor','cache')))
         | 
| 4 | 
            +
             | 
| 5 | 
            +
             | 
| 6 | 
            +
             | 
| 7 | 
            +
            module CloudpiRuntime
         | 
| 8 | 
            +
              class MongoClient
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            class CloudpiRuntime::MongoClient
         | 
| 14 | 
            +
              include CloudpiRuntime
         | 
| 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 = CloudpiRuntime::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,22 @@ | |
| 1 | 
            +
            require "json"
         | 
| 2 | 
            +
            require 'mysql2'
         | 
| 3 | 
            +
            require '../CloudpiRuntime'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            #$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','..','vendor','cache')))
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module CloudpiRuntime
         | 
| 8 | 
            +
              class MySql2Client
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            class CloudpiRuntime::MySql2Client
         | 
| 13 | 
            +
              include CloudpiRuntime
         | 
| 14 | 
            +
              def create_from_svc(hostname)
         | 
| 15 | 
            +
                m = credential_map("mysql")
         | 
| 16 | 
            +
                c = m[hostname]
         | 
| 17 | 
            +
                p c
         | 
| 18 | 
            +
                client = Mysql2::Client.new(:host => c.host,:username => c.username,:password=>c.password,:database=>c.db,:port=>c.port)
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            CloudpiRuntime::MySql2Client.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            require '../CloudpiRuntime'
         | 
| 2 | 
            +
            require 'bunny'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','..','vendor','cache')))
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module CloudpiRuntime
         | 
| 7 | 
            +
              class RabbitMQClient
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            class CloudpiRuntime::RabbitMQClient
         | 
| 13 | 
            +
              include CloudpiRuntime
         | 
| 14 | 
            +
              def create_from_svc(hostname)
         | 
| 15 | 
            +
                m = credential_map("rabbit")
         | 
| 16 | 
            +
                c = m[hostname];
         | 
| 17 | 
            +
                p c
         | 
| 18 | 
            +
                client = Bunny.new(:host => c.host,:port => c.port,:pass => c.password,:user=>c.username,:vhost=>c.vhost)
         | 
| 19 | 
            +
                return client
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            #CloudpiRuntime::RabbitMQClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            require '../CloudpiRuntime'
         | 
| 2 | 
            +
            require 'redis'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),'..','..','vendor','cache')))
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module CloudpiRuntime
         | 
| 7 | 
            +
              class RedisClient
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            class CloudpiRuntime::RedisClient
         | 
| 13 | 
            +
              include CloudpiRuntime
         | 
| 14 | 
            +
              def create_from_svc(hostname)
         | 
| 15 | 
            +
                m = credential_map("redis")
         | 
| 16 | 
            +
                c = m[hostname];
         | 
| 17 | 
            +
                p c
         | 
| 18 | 
            +
                client = Redis.new(:host => c.host,:port => c.port,:password => c.password)
         | 
| 19 | 
            +
                return client
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            #CloudpiRuntime::RedisClient.new.create_from_svc("ec2-23-20-254-0.compute-1.amazonaws.com")
         | 
    
        data/lib/test.rb
    ADDED
    
    
    
        metadata
    ADDED
    
    | @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: cloudpi
         | 
| 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-05 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/CloudpiRuntime.rb
         | 
| 21 | 
            +
            - lib/Credential.rb
         | 
| 22 | 
            +
            - lib/test.rb
         | 
| 23 | 
            +
            - lib/client/MemcacheClient.rb
         | 
| 24 | 
            +
            - lib/client/MongoClient.rb
         | 
| 25 | 
            +
            - lib/client/MySql2Client.rb
         | 
| 26 | 
            +
            - lib/client/RabbitMQClient.rb
         | 
| 27 | 
            +
            - lib/client/RedisClient.rb
         | 
| 28 | 
            +
            homepage: http://www.samsungcloud.org
         | 
| 29 | 
            +
            licenses: []
         | 
| 30 | 
            +
            post_install_message: 
         | 
| 31 | 
            +
            rdoc_options: []
         | 
| 32 | 
            +
            require_paths:
         | 
| 33 | 
            +
            - lib
         | 
| 34 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 35 | 
            +
              none: false
         | 
| 36 | 
            +
              requirements:
         | 
| 37 | 
            +
              - - ! '>='
         | 
| 38 | 
            +
                - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                  version: '0'
         | 
| 40 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 41 | 
            +
              none: false
         | 
| 42 | 
            +
              requirements:
         | 
| 43 | 
            +
              - - ! '>='
         | 
| 44 | 
            +
                - !ruby/object:Gem::Version
         | 
| 45 | 
            +
                  version: '0'
         | 
| 46 | 
            +
            requirements: []
         | 
| 47 | 
            +
            rubyforge_project: 
         | 
| 48 | 
            +
            rubygems_version: 1.7.2
         | 
| 49 | 
            +
            signing_key: 
         | 
| 50 | 
            +
            specification_version: 3
         | 
| 51 | 
            +
            summary: support for cloudpi service
         | 
| 52 | 
            +
            test_files: []
         |