incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962027 - in /incubator/deltacloud/trunk/drivers/rhevm: lib/rhevm_driver.rb scripts/common.ps1 scripts/images.ps1 scripts/instances.ps1 scripts/templateById.ps1 scripts/templates.ps1
Date Thu, 08 Jul 2010 23:17:55 GMT
Author: lutter
Date: Thu Jul  8 23:17:54 2010
New Revision: 962027

URL: http://svn.apache.org/viewvc?rev=962027&view=rev
Log:
Can get a list of images and a simple image

Added:
    incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1
    incubator/deltacloud/trunk/drivers/rhevm/scripts/templateById.ps1
    incubator/deltacloud/trunk/drivers/rhevm/scripts/templates.ps1
Removed:
    incubator/deltacloud/trunk/drivers/rhevm/scripts/images.ps1
Modified:
    incubator/deltacloud/trunk/drivers/rhevm/lib/rhevm_driver.rb
    incubator/deltacloud/trunk/drivers/rhevm/scripts/instances.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=962027&r1=962026&r2=962027&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:17:54 2010
@@ -5,10 +5,14 @@ require 'yaml'
 class RHEVMDriver < DeltaCloud::BaseDriver
 
   SCRIPT_DIR = File.dirname(__FILE__) + '/../scripts'
+  SCRIPT_DIR_ARG = '"' + SCRIPT_DIR + '"'
+  DELIM_BEGIN="<_OUTPUT>"
+  DELIM_END="</_OUTPUT>"
+  POWERSHELL="c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
+  
   # 
   # Flavors
   # 
-
   FLAVORS = [ 
     { 
       :id=>'m1-small',
@@ -41,22 +45,22 @@ class RHEVMDriver < DeltaCloud::BaseDriv
       :architecture=>'x86_64',
     },
   ]
-  
-  DELIM_BEGIN="<_OUTPUT>"
-  DELIM_END="</_OUTPUT>"  
 
   def flavors(credentials, ids=nil)
     return FLAVORS if ( ids.nil? )
     FLAVORS.select{|f| ids.include?(f[:id])}
   end
 
-  # 
-  # Images
-  # 
-  
-  def execute(command, args=[])
-    output = `c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe #{File.join(SCRIPT_DIR,
command)}`
-    result = $?
+  #
+  # Execute a Powershell command, and convert the output
+  # to YAML in order to get back an array of maps.
+  #
+  def execute(credentials, command, args=[])
+    argString = genArgString(credentials, args)
+    outputMaps = {}
+    output = `#{POWERSHELL} -command "&{#{File.join(SCRIPT_DIR, command)} #{argString};
exit $LASTEXITCODE}`
+    exitStatus = $?.exitstatus 
+    puts(output)
     st = output.index(DELIM_BEGIN)
     if (st)
       st += DELIM_BEGIN.length
@@ -64,16 +68,35 @@ class RHEVMDriver < DeltaCloud::BaseDriv
       output = output.slice(st, (ed-st))
       # Lets make it yaml
       output.strip!
-      output = "- \n" + output
-      output.gsub!(/^(\w*)[ ]*:[ ]*([A-Z0-9a-z._ -:]*)/,' \1: "\2"')
-      output.gsub!(/^[ ]*$/,"- ")
+      if (output.length > 0)     
+        outputMaps = YAML.load(self.toYAML(output))            
+      end
     end
-    outputMaps = YAML.load(output)    
     outputMaps 
   end
   
-  def images(credentials, ids_or_owner=nil )
-    templates = execute("images.ps1") 
+  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"')
+    yOutput.gsub!(/^[ ]*$/,"- ")
+    yOutput
+  end
+  
+  def images(credentials, opts=nil )
+    templates = []
+    if (opts.nil?)
+      templates = execute(credentials, "templates.ps1")     
+    else
+      if (opts[:id]) 
+        templates = execute(credentials, "templateById.ps1", [opts[:id]])
+      end
+    end
     images = []
     templates.each do |templ|
       images << template_to_image(templ)

Added: incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1?rev=962027&view=auto
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1 (added)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/common.ps1 Thu Jul  8 23:17:54 2010
@@ -0,0 +1,15 @@
+$DELIM_BEGIN="<_OUTPUT>"
+$DELIM_END="</_OUTPUT>"
+
+function beginOutput {
+    echo $DELIM_BEGIN
+}
+
+function endOutput {
+    echo $DELIM_END
+}
+
+function verifyLogin {
+    param($username, $password, $domain)
+    Login-User $username $password $domain
+}
\ No newline at end of file

Modified: incubator/deltacloud/trunk/drivers/rhevm/scripts/instances.ps1
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/instances.ps1?rev=962027&r1=962026&r2=962027&view=diff
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/instances.ps1 (original)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/instances.ps1 Thu Jul  8 23:17:54 2010
@@ -1 +1 @@
-Login-User VdcUser 12345 qa
\ No newline at end of file
+Login-User VdcUser 123456 demo
\ No newline at end of file

Added: incubator/deltacloud/trunk/drivers/rhevm/scripts/templateById.ps1
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/templateById.ps1?rev=962027&view=auto
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/templateById.ps1 (added)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/templateById.ps1 Thu Jul  8 23:17:54
2010
@@ -0,0 +1,11 @@
+param([string]$scriptsDir,
+        [string]$username,
+        [string]$password,
+        [string]$domain,
+        [string]$id)
+# Get the common functions
+. "$scriptsDir\common.ps1"
+verifyLogin $username $password $domain
+beginOutput
+get-template $id
+endOutput
\ No newline at end of file

Added: incubator/deltacloud/trunk/drivers/rhevm/scripts/templates.ps1
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/drivers/rhevm/scripts/templates.ps1?rev=962027&view=auto
==============================================================================
--- incubator/deltacloud/trunk/drivers/rhevm/scripts/templates.ps1 (added)
+++ incubator/deltacloud/trunk/drivers/rhevm/scripts/templates.ps1 Thu Jul  8 23:17:54 2010
@@ -0,0 +1,10 @@
+param([string]$scriptsDir,
+        [string]$username,
+        [string]$password,
+        [string]$domain)
+# Get the common functions
+. "$scriptsDir\common.ps1"
+verifyLogin $username $password $domain
+beginOutput
+select-template *
+endOutput
\ No newline at end of file



Mime
View raw message