server/lib/deltacloud/drivers/fgcp/fgcp_driver.rb
# Create a new instance, given an image id
# opts can include an optional name for the instance, hardware profile (hwp_id) and realm_id
Create a new instance, given an image id
opts can include an optional name for the instance, hardware profile (hwp_id) and realm_id
Create a new instance given an image id opts can include an optional name for the instance hardware profile ( hwp_id ) and realm_id
def create_instance(credentials, image_id, opts={})
    name = (opts[:name] && opts[:name].length > 0)? opts[:name] : "server_#{Time.now.to_s}"
    hwp = opts[:hwp_id] || 'economy'
    network_id = opts[:subnet_id] || opts[:realm_id]
    safely do
      client = new_client(credentials)
      if not network_id
        xml = client.list_vsys['vsyss']
        network_id = xml ? xml[0]['vsys'][0]['vsysId'][0] + '-N-DMZ' : nil
      end
      if opts[:instance_count] and opts[:instance_count].to_i > 1
        vservers = Array.new(opts[:instance_count].to_i) { |n|
          {
            'vserverName' => "#{name}_#{n+1}",
            'vserverType' => hwp,
            'diskImageId' => image_id,
            'networkId'   => network_id
          }
        }
        new_vservers = { 'vservers' => { 'vserver' => vservers } }
        vservers_xml = XmlSimple.xml_out(new_vservers,
          'RootName' => 'Request',
          'NoAttr' => true
        )
        xml = client.create_vservers(client.extract_vsys_id(network_id), vservers_xml)
        vserver_ids = xml['vservers'][0]['vserver'].collect { |vserver| vserver['vserverId'][0] }
        instances(credentials, {:realm_id => network_id}).select { |instance|
          vserver_ids.include? instance.id
        }
      else
        xml = client.create_vserver(name, hwp, image_id, network_id)
        instances(credentials, {:id => xml['vserverId'][0]}).first
      end
    end
  end
def create_instance ( credentials , image_id , opts = { } ) name = ( opts [ :name ] && opts [ :name ] . length > 0 ) ? opts [ :name ] : "server_#{Time.now.to_s}" hwp = opts [ :hwp_id ] || 'economy' network_id = opts [ :subnet_id ] || opts [ :realm_id ] safely do client = new_client ( credentials ) if not network_id xml = client . list_vsys [ 'vsyss' ] network_id = xml ? xml [ 0 ] [ 'vsys' ] [ 0 ] [ 'vsysId' ] [ 0 ] + '-N-DMZ' : nil end if opts [ :instance_count ] and opts [ :instance_count ] . to_i > 1 vservers = Array . new ( opts [ :instance_count ] . to_i ) { | n | { 'vserverName' => "#{name}_#{n+1}" , 'vserverType' => hwp , 'diskImageId' => image_id , 'networkId' => network_id } } new_vservers = { 'vservers' => { 'vserver' => vservers } } vservers_xml = XmlSimple . xml_out ( new_vservers , 'RootName' => 'Request' , 'NoAttr' => true ) xml = client . create_vservers ( client . extract_vsys_id ( network_id ) , vservers_xml ) vserver_ids = xml [ 'vservers' ] [ 0 ] [ 'vserver' ] . collect { | vserver | vserver [ 'vserverId' ] [ 0 ] } instances ( credentials , { :realm_id => network_id } ) . select { | instance | vserver_ids . include? instance . id } else xml = client . create_vserver ( name , hwp , image_id , network_id ) instances ( credentials , { :id => xml [ 'vserverId' ] [ 0 ] } ) . first end end end
Create a new instance, given an image id
opts can include an optional name for the instance, hardware profile (hwp_id) and realm_id
Create a new instance given an image id opts can include an optional name for the instance hardware profile ( hwp_id ) and realm_id
# default to 'economy' or obtain latest hardware profiles and pick the lowest spec profile? # use first returned system's DMZ as realm # returns vservers' details using filter # returns vserver details
credentials
<not_specific>
image_id
<not_specific>
opts
<not_specific>