Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 4b137326f38b5adf1f9ffd3dbbb48a7b > files > 122

deltacloud-core-doc-0.4.0-4.fc15.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>launch_instance (CondorCloud::DefaultExecutor)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre><span class="ruby-comment cmt"># File lib/deltacloud/drivers/condor/condor_client.rb, line 122</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">launch_instance</span>(<span class="ruby-identifier">image</span>, <span class="ruby-identifier">hardware_profile</span>, <span class="ruby-identifier">opts</span>={})
      <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Image object must be not nil&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">image</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;HardwareProfile object must be not nil&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">hardware_profile</span>
      <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:name</span>] <span class="ruby-operator">||=</span> <span class="ruby-node">&quot;i-#{Time.now.to_i}&quot;</span>

      <span class="ruby-comment cmt"># This needs to be determined by the mac/ip translation stuff.</span>
      <span class="ruby-comment cmt"># We need to call into it and have it return these variables, or at least the MAC if not the IP.</span>
      <span class="ruby-identifier">mac_addr</span> = <span class="ruby-ivar">@ip_agent</span>.<span class="ruby-identifier">find_free_mac</span>
      <span class="ruby-identifier">ip_addr</span> = <span class="ruby-ivar">@ip_agent</span>.<span class="ruby-identifier">find_ip_by_mac</span>(<span class="ruby-identifier">mac_addr</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">mac_addr</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">mac_addr</span>.<span class="ruby-identifier">empty?</span>

      <span class="ruby-identifier">libvirt_xml</span> = <span class="ruby-node">&quot;+VM_XML=\&quot;&lt;domain type='kvm'&gt;
        &lt;name&gt;{NAME}&lt;/name&gt;
        &lt;memory&gt;#{hardware_profile.memory.value.to_i * 1024}&lt;/memory&gt;
        &lt;vcpu&gt;#{hardware_profile.cpu.value}&lt;/vcpu&gt;
        &lt;os&gt;
          &lt;type arch='x86_64'&gt;hvm&lt;/type&gt;
          &lt;boot dev='hd'/&gt;
          &lt;smbios mode='sysinfo'/&gt;
        &lt;/os&gt;
        &lt;sysinfo type='smbios'&gt;
          &lt;system&gt;
            &lt;entry name='manufacturer'&gt;#{opts[:config_server_address]}&lt;/entry&gt;
            &lt;entry name='product'&gt;#{opts[:uuid]}&lt;/entry&gt;
            &lt;entry name='serial'&gt;#{opts[:otp]}&lt;/entry&gt;
          &lt;/system&gt;
        &lt;/sysinfo&gt;
        &lt;features&gt;
          &lt;acpi/&gt;&lt;apic/&gt;&lt;pae/&gt;
        &lt;/features&gt;
        &lt;clock offset='utc'/&gt;
        &lt;on_poweroff&gt;destroy&lt;/on_poweroff&gt;
        &lt;on_reboot&gt;restart&lt;/on_reboot&gt;
        &lt;on_crash&gt;restart&lt;/on_crash&gt;
        &lt;devices&gt;
          &lt;disk type='file' device='disk'&gt;
            &lt;source file='{DISK}'/&gt;
            &lt;target dev='vda' bus='virtio'/&gt;
            &lt;driver name='qemu' type='qcow2'/&gt;
          &lt;/disk&gt;
          &lt;interface type='bridge'&gt;
            #{&quot;&lt;mac address='&quot; + mac_addr + &quot;'/&gt;&quot; if mac_addr &amp;&amp; !mac_addr.empty?}
            &lt;source bridge='#{@config[:default_bridge]}'/&gt;
          &lt;/interface&gt;
          &lt;graphics type='vnc' port='#{@config[:vnc_listen_port]}' autoport='yes' keymap='en-us' listen='#{@config[:vnc_listen_ip]}'/&gt;
        &lt;/devices&gt;
      &lt;/domain&gt;\&quot;&quot;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/(\s{2,})/</span>, <span class="ruby-value str">' '</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\&gt;\s\&lt;/</span>, <span class="ruby-value str">'&gt;&lt;'</span>)

      <span class="ruby-comment cmt"># I use the 2&gt;&amp;1 to get stderr and stdout together because popen3 does not support</span>
      <span class="ruby-comment cmt"># the ability to get the exit value of the command in ruby 1.8.</span>
      <span class="ruby-identifier">pipe</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">popen</span>(<span class="ruby-node">&quot;#{CONDOR_SUBMIT_CMD} 2&gt;&amp;1&quot;</span>, <span class="ruby-value str">&quot;w+&quot;</span>)
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;universe=vm&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;vm_type=kvm&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;vm_memory=#{hardware_profile.memory.value}&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;request_cpus=#{hardware_profile.cpu.value}&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;vm_disk=#{image.description}:null:null&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;executable=#{image.description}&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;vm_macaddr=#{mac_addr}&quot;</span>

      <span class="ruby-comment cmt"># Only set the ip if it is available, and this should depend on the IP mapping used.</span>
      <span class="ruby-comment cmt"># With the fixed mapping method we know the IP address right away before we start the</span>
      <span class="ruby-comment cmt"># instance, so fill it in here.  If it is not set I think we should set it to an empty</span>
      <span class="ruby-comment cmt"># string and we'll fill it in later using a condor tool to update the job.</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;+vm_ipaddr=\&quot;#{ip_addr}\&quot;&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">'+HookKeyword=&quot;CLOUD&quot;'</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;+Cmd=\&quot;#{opts[:name]}\&quot;&quot;</span>
      <span class="ruby-comment cmt"># Really the image should not be a full path to begin with I think..</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;+cloud_image=\&quot;#{File.basename(image.description)}\&quot;&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">libvirt_xml</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;queue&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">puts</span> <span class="ruby-value str">&quot;&quot;</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">close_write</span>
      <span class="ruby-identifier">out</span> = <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">read</span>
      <span class="ruby-identifier">pipe</span>.<span class="ruby-identifier">close</span>

      <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$?</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
        <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Error starting VM in condor_submit: #{out}&quot;</span>
      <span class="ruby-keyword kw">end</span>

      <span class="ruby-identifier">bare_xml</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>(<span class="ruby-node">`#{CONDOR_Q_CMD} -xml`</span>)
      <span class="ruby-identifier">parse_condor_q_output</span>(<span class="ruby-identifier">bare_xml</span>, <span class="ruby-identifier">:name</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:name</span>])
    <span class="ruby-keyword kw">end</span></pre>
</body>
</html>