mirror of
				https://github.com/fog/fog.git
				synced 2022-11-09 13:51:43 -05:00 
			
		
		
		
	make eips useable in a VPC
This commit is contained in:
		
							parent
							
								
									ffbb2b06bd
								
							
						
					
					
						commit
						2ee5bf3f23
					
				
					 5 changed files with 16 additions and 8 deletions
				
			
		| 
						 | 
					@ -9,6 +9,7 @@ module Fog
 | 
				
			||||||
        identity  :public_ip, :aliases => 'publicIp'
 | 
					        identity  :public_ip, :aliases => 'publicIp'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        attribute :server_id, :aliases => 'instanceId'
 | 
					        attribute :server_id, :aliases => 'instanceId'
 | 
				
			||||||
 | 
					        attribute :domain
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def initialize(attributes = {})
 | 
					        def initialize(attributes = {})
 | 
				
			||||||
          # assign server first to prevent race condition with new_record?
 | 
					          # assign server first to prevent race condition with new_record?
 | 
				
			||||||
| 
						 | 
					@ -33,7 +34,7 @@ module Fog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def save
 | 
					        def save
 | 
				
			||||||
          raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
 | 
					          raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
 | 
				
			||||||
          data = connection.allocate_address.body
 | 
					          data = connection.allocate_address(domain).body
 | 
				
			||||||
          new_attributes = data.reject {|key,value| key == 'requestId'}
 | 
					          new_attributes = data.reject {|key,value| key == 'requestId'}
 | 
				
			||||||
          merge_attributes(new_attributes)
 | 
					          merge_attributes(new_attributes)
 | 
				
			||||||
          if @server
 | 
					          if @server
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,7 +7,7 @@ module Fog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          def end_element(name)
 | 
					          def end_element(name)
 | 
				
			||||||
            case name
 | 
					            case name
 | 
				
			||||||
            when 'publicIp', 'requestId'
 | 
					            when 'publicIp', 'requestId', 'domain', 'allocationId'
 | 
				
			||||||
              @response[name] = value
 | 
					              @response[name] = value
 | 
				
			||||||
            end
 | 
					            end
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ module Fog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          def end_element(name)
 | 
					          def end_element(name)
 | 
				
			||||||
            case name
 | 
					            case name
 | 
				
			||||||
            when 'instanceId', 'publicIp'
 | 
					            when 'instanceId', 'publicIp', 'domain', 'allocationId'
 | 
				
			||||||
              @address[name] = value
 | 
					              @address[name] = value
 | 
				
			||||||
            when 'item'
 | 
					            when 'item'
 | 
				
			||||||
              @response['addressesSet'] << @address
 | 
					              @response['addressesSet'] << @address
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,8 @@ module Fog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Acquire an elastic IP address.
 | 
					        # Acquire an elastic IP address.
 | 
				
			||||||
        #
 | 
					        #
 | 
				
			||||||
 | 
					        # ==== Parameters
 | 
				
			||||||
 | 
					        # * domain<~String> - Type of EIP, either standard or vpc
 | 
				
			||||||
        # ==== Returns
 | 
					        # ==== Returns
 | 
				
			||||||
        # * response<~Excon::Response>:
 | 
					        # * response<~Excon::Response>:
 | 
				
			||||||
        #   * body<~Hash>:
 | 
					        #   * body<~Hash>:
 | 
				
			||||||
| 
						 | 
					@ -14,9 +16,11 @@ module Fog
 | 
				
			||||||
        #     * 'requestId'<~String> - Id of the request
 | 
					        #     * 'requestId'<~String> - Id of the request
 | 
				
			||||||
        #
 | 
					        #
 | 
				
			||||||
        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AllocateAddress.html]
 | 
					        # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-AllocateAddress.html]
 | 
				
			||||||
        def allocate_address
 | 
					        def allocate_address(domain='standard')
 | 
				
			||||||
 | 
					          domain = domain == 'vpc' ? 'vpc' : 'standard'
 | 
				
			||||||
          request(
 | 
					          request(
 | 
				
			||||||
            'Action'  => 'AllocateAddress',
 | 
					            'Action'  => 'AllocateAddress',
 | 
				
			||||||
 | 
					            'Domain'  => domain,
 | 
				
			||||||
            :parser   => Fog::Parsers::Compute::AWS::AllocateAddress.new
 | 
					            :parser   => Fog::Parsers::Compute::AWS::AllocateAddress.new
 | 
				
			||||||
          )
 | 
					          )
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
| 
						 | 
					@ -25,7 +29,7 @@ module Fog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      class Mock
 | 
					      class Mock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def allocate_address
 | 
					        def allocate_address(domain = 'standard')
 | 
				
			||||||
          response = Excon::Response.new
 | 
					          response = Excon::Response.new
 | 
				
			||||||
          if describe_addresses.body['addressesSet'].size < self.data[:limits][:addresses]
 | 
					          if describe_addresses.body['addressesSet'].size < self.data[:limits][:addresses]
 | 
				
			||||||
            response.status = 200
 | 
					            response.status = 200
 | 
				
			||||||
| 
						 | 
					@ -36,6 +40,7 @@ module Fog
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            self.data[:addresses][public_ip] = data
 | 
					            self.data[:addresses][public_ip] = data
 | 
				
			||||||
            response.body = {
 | 
					            response.body = {
 | 
				
			||||||
 | 
					              'domain'    => standard,
 | 
				
			||||||
              'publicIp'  => public_ip,
 | 
					              'publicIp'  => public_ip,
 | 
				
			||||||
              'requestId' => Fog::AWS::Mock.request_id
 | 
					              'requestId' => Fog::AWS::Mock.request_id
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,8 +2,10 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @addresses_format = {
 | 
					  @addresses_format = {
 | 
				
			||||||
    'addressesSet' => [{
 | 
					    'addressesSet' => [{
 | 
				
			||||||
      'instanceId'  => NilClass,
 | 
					      'allocationId' => Fog::Nullable::String,
 | 
				
			||||||
      'publicIp'    => String
 | 
					      'domain'       => String,
 | 
				
			||||||
 | 
					      'instanceId'   => Fog::Nullable::String,
 | 
				
			||||||
 | 
					      'publicIp'     => String
 | 
				
			||||||
    }],
 | 
					    }],
 | 
				
			||||||
    'requestId' => String
 | 
					    'requestId' => String
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -16,7 +18,7 @@ Shindo.tests('Fog::Compute[:aws] | address requests', ['aws']) do
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @public_ip = nil
 | 
					    @public_ip = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tests('#allocate_address').formats({'publicIp' => String, 'requestId' => String}) do
 | 
					    tests('#allocate_address').formats({'domain' => String, 'publicIp' => String, 'requestId' => String}) do
 | 
				
			||||||
      data = Fog::Compute[:aws].allocate_address.body
 | 
					      data = Fog::Compute[:aws].allocate_address.body
 | 
				
			||||||
      @public_ip = data['publicIp']
 | 
					      @public_ip = data['publicIp']
 | 
				
			||||||
      data
 | 
					      data
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue