vipruby 0.0.3
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.
- checksums.yaml +7 -0
 - data/lib/vipruby.rb +119 -0
 - metadata +72 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 859fdc3d02ffb93a4a93bfdbe2abbf016d0725e0
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 085f71d3e2dd1d028bf9de8b7d1b372b6016e2e4
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e81319d55113ee1e5aecd899fadb0c0713c62e1b7d7c8cbace98f2155c1322ad612b9006b9db585e4034132ef2af454d60ba6b62047e2c1aa0648a14da4f6f69
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 95891fb9c1c89be9fa95fcc94346254f01ad85f9bc4ba44d1ea4d82ea252cf3f9376161db2c824215cecc10f2fef4ca6410781efc2da53274b5eb0d69e1db425
         
     | 
    
        data/lib/vipruby.rb
    ADDED
    
    | 
         @@ -0,0 +1,119 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rest_client'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'json'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            class Vipruby
         
     | 
| 
      
 5 
     | 
    
         
            +
              attr_accessor :tenant_uid, :auth_token, :base_url
         
     | 
| 
      
 6 
     | 
    
         
            +
              SSL_VERSION = 'TLSv1'
         
     | 
| 
      
 7 
     | 
    
         
            +
              
         
     | 
| 
      
 8 
     | 
    
         
            +
              def initialize(base_url,user_name,password)
         
     | 
| 
      
 9 
     | 
    
         
            +
                #add condition later for trusted certs (This ignores)
         
     | 
| 
      
 10 
     | 
    
         
            +
                #OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
         
     | 
| 
      
 11 
     | 
    
         
            +
                @base_url = base_url
         
     | 
| 
      
 12 
     | 
    
         
            +
                @auth_token = get_auth_token(user_name,password)
         
     | 
| 
      
 13 
     | 
    
         
            +
                @tenant_uid = get_tenant_uid['id']
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              def get_tenant_uid
         
     | 
| 
      
 17 
     | 
    
         
            +
                JSON.parse(RestClient::Request.execute(method: :get,url: "#{base_url}/tenant",
         
     | 
| 
      
 18 
     | 
    
         
            +
                  headers: {:'X-SDS-AUTH-TOKEN' => @auth_token,
         
     | 
| 
      
 19 
     | 
    
         
            +
                    accept: :json
         
     | 
| 
      
 20 
     | 
    
         
            +
                  },
         
     | 
| 
      
 21 
     | 
    
         
            +
                  ssl_version: SSL_VERSION
         
     | 
| 
      
 22 
     | 
    
         
            +
                  ))
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              def login(user_name,password)
         
     | 
| 
      
 26 
     | 
    
         
            +
                RestClient::Request.execute(method: :get,url: "#{base_url}/login", user: user_name, password: password,ssl_version: SSL_VERSION)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              
         
     | 
| 
      
 29 
     | 
    
         
            +
              def get_auth_token(user_name,password)
         
     | 
| 
      
 30 
     | 
    
         
            +
                login(user_name,password).headers[:x_sds_auth_token]
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
              
         
     | 
| 
      
 33 
     | 
    
         
            +
              def add_host(host)
         
     | 
| 
      
 34 
     | 
    
         
            +
                 RestClient::Request.execute(method: :post,
         
     | 
| 
      
 35 
     | 
    
         
            +
                   url: "#{base_url}/tenants/#{@tenant_uid}/hosts",
         
     | 
| 
      
 36 
     | 
    
         
            +
                   ssl_version: SSL_VERSION,
         
     | 
| 
      
 37 
     | 
    
         
            +
                   payload: host,
         
     | 
| 
      
 38 
     | 
    
         
            +
                   headers: {
         
     | 
| 
      
 39 
     | 
    
         
            +
                     :'X-SDS-AUTH-TOKEN' => @auth_token,
         
     | 
| 
      
 40 
     | 
    
         
            +
                     content_type: 'application/json',
         
     | 
| 
      
 41 
     | 
    
         
            +
                     accept: :json
         
     | 
| 
      
 42 
     | 
    
         
            +
                   })
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
              
         
     | 
| 
      
 45 
     | 
    
         
            +
              def add_initiators(initiators,host_href)
         
     | 
| 
      
 46 
     | 
    
         
            +
                initiators.each do |initiator|
         
     | 
| 
      
 47 
     | 
    
         
            +
                  RestClient::Request.execute(method: :post,
         
     | 
| 
      
 48 
     | 
    
         
            +
                    url: "#{base_url}#{host_href}/initiators",
         
     | 
| 
      
 49 
     | 
    
         
            +
                    ssl_version: SSL_VERSION,
         
     | 
| 
      
 50 
     | 
    
         
            +
                    payload: initiator,
         
     | 
| 
      
 51 
     | 
    
         
            +
                    headers: {
         
     | 
| 
      
 52 
     | 
    
         
            +
                      :'X-SDS-AUTH-TOKEN' => @auth_token,
         
     | 
| 
      
 53 
     | 
    
         
            +
                      content_type: 'application/json',
         
     | 
| 
      
 54 
     | 
    
         
            +
                      accept: :json
         
     | 
| 
      
 55 
     | 
    
         
            +
                    })
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
              
         
     | 
| 
      
 59 
     | 
    
         
            +
              def get_hosts
         
     | 
| 
      
 60 
     | 
    
         
            +
                RestClient::Request.execute(method: :get,url: "#{base_url}/tenants/#{@tenant_uid}/hosts",
         
     | 
| 
      
 61 
     | 
    
         
            +
                  ssl_version: SSL_VERSION,
         
     | 
| 
      
 62 
     | 
    
         
            +
                  headers: {
         
     | 
| 
      
 63 
     | 
    
         
            +
                    :'X-SDS-AUTH-TOKEN' => @auth_token,
         
     | 
| 
      
 64 
     | 
    
         
            +
                    accept: :json
         
     | 
| 
      
 65 
     | 
    
         
            +
                  })
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
              
         
     | 
| 
      
 68 
     | 
    
         
            +
              def add_host_and_initiators(host)
         
     | 
| 
      
 69 
     | 
    
         
            +
                new_host = JSON.parse(add_host(host.generate_json))
         
     | 
| 
      
 70 
     | 
    
         
            +
                add_initiators(host.generate_initiators_json,new_host['resource']['link']['href'])
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
              
         
     | 
| 
      
 73 
     | 
    
         
            +
              def host_exists?(hostname)
         
     | 
| 
      
 74 
     | 
    
         
            +
                JSON.parse(find_vipr_object(hostname))['resource'].any?
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
              
         
     | 
| 
      
 77 
     | 
    
         
            +
              def find_vipr_object(search_hash)
         
     | 
| 
      
 78 
     | 
    
         
            +
                RestClient::Request.execute(method: :get,
         
     | 
| 
      
 79 
     | 
    
         
            +
                  url: "#{base_url}/compute/hosts/search?name=#{search_hash}",
         
     | 
| 
      
 80 
     | 
    
         
            +
                  ssl_version: SSL_VERSION,
         
     | 
| 
      
 81 
     | 
    
         
            +
                  headers: {
         
     | 
| 
      
 82 
     | 
    
         
            +
                    :'X-SDS-AUTH-TOKEN' => @auth_token,
         
     | 
| 
      
 83 
     | 
    
         
            +
                    accept: :json
         
     | 
| 
      
 84 
     | 
    
         
            +
                  })
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
              
         
     | 
| 
      
 87 
     | 
    
         
            +
              private :login, :get_auth_token, :get_tenant_uid
         
     | 
| 
      
 88 
     | 
    
         
            +
            end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            class Host
         
     | 
| 
      
 91 
     | 
    
         
            +
              attr_accessor :fqdn, :ip_address, :type, :name, :discoverable, :initiators_port, :initiator_node, :protocol
         
     | 
| 
      
 92 
     | 
    
         
            +
              
         
     | 
| 
      
 93 
     | 
    
         
            +
              def initialize params = {}
         
     | 
| 
      
 94 
     | 
    
         
            +
                params.each { |key, value| send "#{key}=", value }
         
     | 
| 
      
 95 
     | 
    
         
            +
              end
         
     | 
| 
      
 96 
     | 
    
         
            +
              
         
     | 
| 
      
 97 
     | 
    
         
            +
              def generate_json
         
     | 
| 
      
 98 
     | 
    
         
            +
                {
         
     | 
| 
      
 99 
     | 
    
         
            +
                  type: @type.capitalize,
         
     | 
| 
      
 100 
     | 
    
         
            +
                  name: @name,
         
     | 
| 
      
 101 
     | 
    
         
            +
                  host_name: @fqdn,
         
     | 
| 
      
 102 
     | 
    
         
            +
                  discoverable: @discoverable.downcase
         
     | 
| 
      
 103 
     | 
    
         
            +
                }.to_json
         
     | 
| 
      
 104 
     | 
    
         
            +
              end
         
     | 
| 
      
 105 
     | 
    
         
            +
              
         
     | 
| 
      
 106 
     | 
    
         
            +
              def generate_initiators_json
         
     | 
| 
      
 107 
     | 
    
         
            +
                initiator_json = []
         
     | 
| 
      
 108 
     | 
    
         
            +
                @initiators_port.each do |initiator|
         
     | 
| 
      
 109 
     | 
    
         
            +
                  initiator_json <<
         
     | 
| 
      
 110 
     | 
    
         
            +
                  {
         
     | 
| 
      
 111 
     | 
    
         
            +
                    protocol: @protocol.upcase,
         
     | 
| 
      
 112 
     | 
    
         
            +
                    initiator_port: initiator,
         
     | 
| 
      
 113 
     | 
    
         
            +
                    initiator_node: @initiator_node
         
     | 
| 
      
 114 
     | 
    
         
            +
                  }.to_json
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
                initiator_json
         
     | 
| 
      
 117 
     | 
    
         
            +
              end
         
     | 
| 
      
 118 
     | 
    
         
            +
              
         
     | 
| 
      
 119 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,72 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: vipruby
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Craig J Smith
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-08-17 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: json
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '1.8'
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '1.8'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: rest-client
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - '='
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 1.7.2
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - '='
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: 1.7.2
         
     | 
| 
      
 41 
     | 
    
         
            +
            description: Currently limited to host and initiator add functions
         
     | 
| 
      
 42 
     | 
    
         
            +
            email: nctiggy@gmail.com
         
     | 
| 
      
 43 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 44 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 45 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 46 
     | 
    
         
            +
            files:
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib/vipruby.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
            homepage: https://github.com/nctiggy/Vipruby
         
     | 
| 
      
 49 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 50 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 51 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 52 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 53 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 54 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 55 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 56 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 57 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 58 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 59 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 60 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 61 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 62 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 63 
     | 
    
         
            +
              - - '>='
         
     | 
| 
      
 64 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 65 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 66 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 67 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 68 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
      
 69 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 70 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 71 
     | 
    
         
            +
            summary: A Ruby Library for EMC's ViPR
         
     | 
| 
      
 72 
     | 
    
         
            +
            test_files: []
         
     |