server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
# allocates (and enables) new ip in specified vsys/network
allocates (and enables) new ip in specified vsys/network
allocates ( and enables ) new ip in specified vsys / network
def create_address(credentials, opts={})
    safely do
      client = new_client(credentials)
      opts ||= {}
      if opts[:realm_id]
        opts[:realm_id] = client.extract_vsys_id(opts[:realm_id])
      else
        xml = client.list_vsys['vsyss']
        opts[:realm_id] = xml[0]['vsys'][0]['vsysId'][0] if xml
      end
      old_ips = []
      xml = client.list_public_ips(opts[:realm_id])['publicips']
      old_ips = xml[0]['publicip'].collect { |ip| ip['address'][0]} if xml and xml[0]['publicip']
      client.allocate_public_ip(opts[:realm_id])
      id = 'PENDING-xxx.xxx.xxx.xxx'
      sleep(8)
      10.times {
        sleep(5)
        xml = client.list_public_ips(opts[:realm_id])['publicips']
        if xml and xml[0]['publicip'] and xml[0]['publicip'].size > old_ips.size
          new_ips = xml[0]['publicip'].collect { |ip| ip['address'][0]}
          new_ip = (new_ips - old_ips).first
          client.attach_public_ip(opts[:realm_id], new_ip)
          id = new_ip
          break
        end
      }
      Address.new(:id => id)
    end
  end
def create_address ( credentials , opts = { } ) safely do client = new_client ( credentials ) opts ||= { } if opts [ :realm_id ] opts [ :realm_id ] = client . extract_vsys_id ( opts [ :realm_id ] ) else xml = client . list_vsys [ 'vsyss' ] opts [ :realm_id ] = xml [ 0 ] [ 'vsys' ] [ 0 ] [ 'vsysId' ] [ 0 ] if xml end old_ips = [ ] xml = client . list_public_ips ( opts [ :realm_id ] ) [ 'publicips' ] old_ips = xml [ 0 ] [ 'publicip' ] . collect { | ip | ip [ 'address' ] [ 0 ] } if xml and xml [ 0 ] [ 'publicip' ] client . allocate_public_ip ( opts [ :realm_id ] ) id = 'PENDING-xxx.xxx.xxx.xxx' sleep ( 8 ) 10 . times { sleep ( 5 ) xml = client . list_public_ips ( opts [ :realm_id ] ) [ 'publicips' ] if xml and xml [ 0 ] [ 'publicip' ] and xml [ 0 ] [ 'publicip' ] . size > old_ips . size new_ips = xml [ 0 ] [ 'publicip' ] . collect { | ip | ip [ 'address' ] [ 0 ] } new_ip = ( new_ips - old_ips ) . first client . attach_public_ip ( opts [ :realm_id ] , new_ip ) id = new_ip break end } Address . new ( :id => id ) end end
allocates (and enables) new ip in specified vsys/network
allocates ( and enables ) new ip in specified vsys / network
# just in case a network realm was passed in # get first vsys # new address not returned immediately: # Seems to take 15-30s. to appear in list, so poll for a while # prepare dummy id in case new ip does not appear soon. # enable IP address
credentials
<not_specific>
opts
<not_specific>