incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962050 - in /incubator/deltacloud/trunk/drivers/rhevm: lib/rhevm_driver.rb scripts/common.ps1 scripts/startVm.ps1 scripts/stopVm.ps1 scripts/vmById.ps1 scripts/vms.ps1
Date Thu, 08 Jul 2010 23:19:28 GMT
Author: lutter
Date: Thu Jul  8 23:19:27 2010
New Revision: 962050

URL: http://svn.apache.org/viewvc?rev=962050&view=rev
Log:
Start and stop vms.

Added:
    incubator/deltacloud/trunk/drivers/rhevm/scripts/startVm.ps1
      - copied, changed from r962049, incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1
    incubator/deltacloud/trunk/drivers/rhevm/scripts/stopVm.ps1
      - copied, changed from r962049, incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1
    incubator/deltacloud/trunk/drivers/rhevm/scripts/vmById.ps1
      - copied, changed from r962049, incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1
Modified:
    incubator/deltacloud/trunk/drivers/rhevm/lib/rhevm_driver.rb
    incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1
    incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1

Modified: incubator/deltacloud/trunk/drivers/rhevm/lib/rhevm_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/lib/rhevm_driver.rb?rev=962050&r1=962049&r2=962050&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/lib/rhevm_driver.rb (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/lib/rhevm_driver.rb Thu Jul  8 23:19:27 2010
@@ -9,19 +9,19 @@ class RHEVMDriver < DeltaCloud::BaseDriv
   DELIM_BEGIN="<_OUTPUT>"
   DELIM_END="</_OUTPUT>"
   POWERSHELL="c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
-  
-  # 
+
+  #
   # Flavors
-  # 
+  #
   FLAVORS = [
-    Flavor.new({ 
+    Flavor.new({
       :id=>"rhevm",
       :memory=>"Any",
       :storage=>"Any",
       :architecture=>"Any",
     })
   ]
-  
+
   def flavors(credentials, opts=nil)
     return FLAVORS if ( opts.nil? )
     FLAVORS.select{|f| opts[:id] == f.id}
@@ -32,10 +32,11 @@ class RHEVMDriver < DeltaCloud::BaseDriv
   # to YAML in order to get back an array of maps.
   #
   def execute(credentials, command, args=[])
+    args = args.to_a
     argString = genArgString(credentials, args)
     outputMaps = {}
     output = `#{POWERSHELL} -command "&{#{File.join(SCRIPT_DIR, command)} #{argString};
exit $LASTEXITCODE}`
-    exitStatus = $?.exitstatus 
+    exitStatus = $?.exitstatus
     puts(output)
     st = output.index(DELIM_BEGIN)
     if (st)
@@ -44,19 +45,19 @@ class RHEVMDriver < DeltaCloud::BaseDriv
       output = output.slice(st, (ed-st))
       # Lets make it yaml
       output.strip!
-      if (output.length > 0)     
-        outputMaps = YAML.load(self.toYAML(output))            
+      if (output.length > 0)
+        outputMaps = YAML.load(self.toYAML(output))
       end
     end
-    outputMaps 
+    outputMaps
   end
-  
+
   def genArgString(credentials, args)
     commonArgs = [SCRIPT_DIR_ARG, "vdcadmin", "123456", "demo"]
     commonArgs.concat(args)
     commonArgs.join(" ")
   end
-  
+
   def toYAML(output)
     yOutput = "- \n" + output
     yOutput.gsub!(/^(\w*)[ ]*:[ ]*([A-Z0-9a-z._ -:{}]*)/,' \1: "\2"')
@@ -64,19 +65,32 @@ class RHEVMDriver < DeltaCloud::BaseDriv
     puts(yOutput)
     yOutput
   end
-  
-  
+
+  def statify(state)
+    st = state.nil? ? "" : state.upcase()
+    return :running if st == "UP"
+    return :terminated if st == "DOWN"
+    return :pending if st == "POWERING UP"
+  end
+
+  STATE_ACTIONS = {
+    :pending=>[],
+    :running=>[ :stop, :reboot ],
+    :shutting_down=>[],
+    :terminated=>[:start ]
+  }
+
   #
   # Images
   #
-  
+
   def images(credentials, opts=nil )
     templates = []
     if (opts.nil?)
-      templates = execute(credentials, "templates.ps1")     
+      templates = execute(credentials, "templates.ps1")
     else
-      if (opts[:id]) 
-        templates = execute(credentials, "templateById.ps1", [opts[:id]])
+      if (opts[:id])
+        templates = execute(credentials, "templateById.ps1", opts[:id])
       end
     end
     images = []
@@ -85,7 +99,7 @@ class RHEVMDriver < DeltaCloud::BaseDriv
     end
     images
   end
-  
+
   def template_to_image(templ)
     Image.new({
       :id => templ["TemplateId"],
@@ -100,17 +114,17 @@ class RHEVMDriver < DeltaCloud::BaseDriv
     })
   end
 
-  # 
+  #
   # Instances
-  # 
+  #
 
   def instances(credentials, opts=nil)
     vms = []
     if (opts.nil?)
-      vms = execute(credentials, "vms.ps1")     
+      vms = execute(credentials, "vms.ps1")
     else
-      if (opts[:id]) 
-        vms = execute(credentials, "vmsById.ps1", [opts[:id]])
+      if (opts[:id])
+        vms = execute(credentials, "vmById.ps1", opts[:id])
       end
     end
     instances = []
@@ -119,19 +133,30 @@ class RHEVMDriver < DeltaCloud::BaseDriv
     end
     instances
   end
-  
+
   def vm_to_instance(vm)
     Instance.new({
       :id => vm["VmId"],
       :description => vm["Description"],
-      :name => vm["Name"],      
+      :name => vm["Name"],
       :architecture => vm["OperatingSystem"],
       :owner_id => "Jar Jar Binks",
       :image_id => vm["TemplateId"],
-      :state => vm["Status"],
-      :flavor_id => "rhevm",      
+      :state => statify(vm["Status"]),
+      :flavor_id => "rhevm",
+      :actions => STATE_ACTIONS[statify(vm["Status"])]
     })
-  end  
+  end
+
+  def start_instance(credentials, image_id)
+    vm = execute(credentials, "startVm.ps1", image_id)
+    vm_to_instance(vm[0])
+  end
+
+  def stop_instance(credentials, image_id)
+    vm = execute(credentials, "stopVm.ps1", image_id)
+    vm_to_instance(vm[0])
+  end
 
   def create_instance(credentials, image_id, flavor_id)
     check_credentials( credentials )
@@ -143,18 +168,18 @@ class RHEVMDriver < DeltaCloud::BaseDriv
   def delete_instance(credentials, id)
   end
 
-  # 
+  #
   # Storage Volumes
-  # 
+  #
 
   def volumes(credentials, ids=nil)
     volumes = []
     volumes
   end
 
-  # 
+  #
   # Storage Snapshots
-  # 
+  #
 
   def snapshots(credentials, ids=nil)
     snapshots = []

Modified: incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1?rev=962050&r1=962049&r2=962050&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1 (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1 Thu Jul  8 23:19:27 2010
@@ -1,6 +1,6 @@
 $DELIM_BEGIN="<_OUTPUT>"
 $DELIM_END="</_OUTPUT>"
-
+$VM_PROPERTY_LIST="VmId", "Name", "Description", "TemplateId", "Domain", "Status", "OperatingSystem"
 function beginOutput {
     echo $DELIM_BEGIN
 }
@@ -12,4 +12,5 @@ function endOutput {
 function verifyLogin {
     param($username, $password, $domain)
     Login-User $username $password $domain
-}
\ No newline at end of file
+}
+

Copied: incubator/deltacloud/trunk/drivers/rhevm/scripts/startVm.ps1 (from r962049, incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/startVm.ps1?p2=incubator/deltacloud/trunk/drivers/rhevm/scripts/startVm.ps1&p1=incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1&r1=962049&r2=962050&rev=962050&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1 (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/startVm.ps1 Thu Jul  8 23:19:27 2010
@@ -1,11 +1,12 @@
 param([string]$scriptsDir,
         [string]$username,
         [string]$password,
-        [string]$domain)
+        [string]$domain,
+        [string]$id)
 # Get the common functions
 . "$scriptsDir\common.ps1"
 verifyLogin $username $password $domain
 beginOutput
 # The AppliacationList causes the YAML pain, so Omit it
-select-vm * | format-list -Property "VmId", "Name", "Description", "TemplateId", "Domain",
"Status", "OperatingSystem"
+start-vm $id | format-list -Property $VM_PROPERTY_LIST
 endOutput
\ No newline at end of file

Copied: incubator/deltacloud/trunk/drivers/rhevm/scripts/stopVm.ps1 (from r962049, incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/stopVm.ps1?p2=incubator/deltacloud/trunk/drivers/rhevm/scripts/stopVm.ps1&p1=incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1&r1=962049&r2=962050&rev=962050&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1 (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/stopVm.ps1 Thu Jul  8 23:19:27 2010
@@ -1,11 +1,12 @@
 param([string]$scriptsDir,
         [string]$username,
         [string]$password,
-        [string]$domain)
+        [string]$domain,
+        [string]$id)
 # Get the common functions
 . "$scriptsDir\common.ps1"
 verifyLogin $username $password $domain
 beginOutput
 # The AppliacationList causes the YAML pain, so Omit it
-select-vm * | format-list -Property "VmId", "Name", "Description", "TemplateId", "Domain",
"Status", "OperatingSystem"
+stop-vm $id | format-list -Property $VM_PROPERTY_LIST
 endOutput
\ No newline at end of file

Copied: incubator/deltacloud/trunk/drivers/rhevm/scripts/vmById.ps1 (from r962049, incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/vmById.ps1?p2=incubator/deltacloud/trunk/drivers/rhevm/scripts/vmById.ps1&p1=incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1&r1=962049&r2=962050&rev=962050&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1 (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/vmById.ps1 Thu Jul  8 23:19:27 2010
@@ -1,11 +1,12 @@
 param([string]$scriptsDir,
         [string]$username,
         [string]$password,
-        [string]$domain)
+        [string]$domain,
+        [string]$id)        
 # Get the common functions
 . "$scriptsDir\common.ps1"
 verifyLogin $username $password $domain
 beginOutput
 # The AppliacationList causes the YAML pain, so Omit it
-select-vm * | format-list -Property "VmId", "Name", "Description", "TemplateId", "Domain",
"Status", "OperatingSystem"
+get-vm $id | format-list -Property $VM_PROPERTY_LIST
 endOutput
\ No newline at end of file

Modified: incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1?rev=962050&r1=962049&r2=962050&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1 (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/vms.ps1 Thu Jul  8 23:19:27 2010
@@ -7,5 +7,5 @@ param([string]$scriptsDir,
 verifyLogin $username $password $domain
 beginOutput
 # The AppliacationList causes the YAML pain, so Omit it
-select-vm * | format-list -Property "VmId", "Name", "Description", "TemplateId", "Domain",
"Status", "OperatingSystem"
+select-vm * | format-list -Property $VM_PROPERTY_LIST
 endOutput
\ No newline at end of file



Mime
View raw message