Permalink
Browse files

Reworked Ruby class heirarchy.. Properties now work well

  • Loading branch information...
1 parent 8f6d785 commit 0651b4bf912236d33be4231e132c342be96652c1 Sean Bradly committed Feb 28, 2009
Showing with 612 additions and 341 deletions.
  1. +39 −0 README
  2. +11 −5 vm.h → functions.h
  3. +4 −4 guest.c
  4. +36 −35 host.c
  5. +0 −4 host.h
  6. +166 −118 vixapi.c
  7. +32 −36 vm.c
  8. +324 −139 vmware.rb
View
@@ -2,3 +2,42 @@ vixR - A (new&improved) Ruby bridge to the VMware VIX API - 2009, Sean Bradly
This project and all files it includes are released under the BSD license.
+--------------------------------------------------------------------------------
+| Compiling / Installing
+--------------------------------------------------------------------------------
+ruby ./extconf.rb --with-vixapi-include=/usr/include/vmware-vix
+make
+make install
+
+--------------------------------------------------------------------------------
+| Developing
+--------------------------------------------------------------------------------
+
+Ruby API
+
+module VixAPI
+ def raw_C_vixapi_method_wrapper
+ end
+end
+
+module VixR
+
+ self.connect()
+ end
+
+ class Host # As returned by VixR.connect
+ end
+
+ class VM
+ end
+
+ class GuestOS < VM
+ end
+
+ class Property
+ end
+
+ class Snapshot
+ end
+
+end
View
@@ -1,14 +1,20 @@
-/* VM Power Functions */
+/* Auth/Session routines */
+VALUE _connect(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
+VALUE _disconnect(VALUE, VALUE);
+
+VALUE _open_vmx(VALUE, VALUE, VALUE);
+
+/* VM functions */
VALUE _power_on(VALUE, VALUE, VALUE);
VALUE _power_off(VALUE, VALUE, VALUE);
-VALUE _reset(VALUE, VALUE, VALUE);
VALUE _pause(VALUE, VALUE);
VALUE _suspend(VALUE, VALUE);
VALUE _unpause(VALUE, VALUE);
-
-/* Misc VM Functions */
+VALUE _reset(VALUE, VALUE, VALUE);
VALUE _delete(VALUE, VALUE, VALUE);
+VALUE _upgrade_vhardware(VALUE, VALUE);
VALUE _read_var(VALUE, VALUE, VALUE, VALUE);
VALUE _write_var(VALUE, VALUE, VALUE, VALUE, VALUE);
-VALUE _upgrade_vhardware(VALUE, VALUE);
+/* Misc functions */
+VALUE _getproperty(VALUE, VALUE, VALUE);
View
@@ -107,7 +107,7 @@ _create_temp_file_in_guest(VALUE self, VALUE rvm)
VixError err;
char *tempfilepath;
- job = Vix_VM_CreateTempFileInGuest(vm, 0, VIX_INVALID_HANDLE, NULL, NULL);
+ job = VixVM_CreateTempFileInGuest(vm, 0, VIX_INVALID_HANDLE, NULL, NULL);
err = VixJob_Wait(job, VIX_PROPERTY_JOB_RESULT_ITEM_NAME, &tempfilepath, VIX_PROPERTY_NONE);
if(VIX_FAILED(err))
@@ -131,7 +131,7 @@ _delete_directory_in_guest(VALUE self, VALUE rvm, VALUE rpath)
char *path = StringValueCStr(rpath);
- job = Vix_VM_DeleteDirectoryInGuest(vm, path, 0, NULL, NULL);
+ job = VixVM_DeleteDirectoryInGuest(vm, path, 0, NULL, NULL);
err = VixJob_Wait(job, VIX_PROPERTY_NONE);
if(VIX_FAILED(err))
@@ -155,7 +155,7 @@ _delete_file_in_guest(VALUE self, VALUE rvm, VALUE rpath)
char *path = StringValueCStr(rpath);
- job = Vix_VM_DeleteFileInGuest(vm, path, NULL, NULL);
+ job = VixVM_DeleteFileInGuest(vm, path, NULL, NULL);
err = VixJob_Wait(job, VIX_PROPERTY_NONE);
if(VIX_FAILED(err))
@@ -179,7 +179,7 @@ _directory_exists_in_guest(VALUE self, VALUE rvm, VALUE rpath)
char *path = StringValueCStr(rpath);
- job = Vix_VM_DirectoryExistsInGuest(vm, path, NULL, NULL);
+ job = VixVM_DirectoryExistsInGuest(vm, path, NULL, NULL);
err = VixJob_Wait(job, VIX_PROPERTY_NONE);
if(VIX_FAILED(err))
View
@@ -1,86 +1,87 @@
#include <stdio.h>
#include <string.h>
#include <ruby.h>
-#include "vix.h"
+#include <vix.h>
-#include "host.h"
+#include "functions.h"
/* _connect(user,pass,type): async connect */
VALUE
-_connect(int hosttype, const char *hostname, int port, const char *user, const char *pass)
+_connect(VALUE self, VALUE rhosttype, VALUE rhostname, VALUE rport, VALUE ruser, VALUE rpass)
{
VixHandle job = 0;
VixHandle session = VIX_INVALID_HANDLE;
VixError err;
- fprintf(stderr,"calling connect(ht:%d,host:%s,port:%d,user:%s,pass.length:%d);\n",hosttype,hostname,port,user,(pass)?strlen(pass):0);
+ char *hostname,*pass,*user,str[200];
+ int hosttype,port;
+
+ hosttype = NUM2INT(rhosttype);
+ hostname = (rhostname!=Qnil)?StringValueCStr(rhostname):NULL;
+ port = (rport!=Qnil)?NUM2INT(rport):0;
+ user = (ruser!=Qnil)?StringValueCStr(ruser):NULL;
+ pass = (rpass!=Qnil)?StringValueCStr(rpass):NULL;
+
+ //fprintf(stderr,"calling connect(ht:%d,host:%s,port:%d,user:%s,pass.length:%d);\n",hosttype,hostname,port,user,(pass)?strlen(pass):0);
/* Start the async connect */
job = VixHost_Connect(VIX_API_VERSION,
- hosttype,hostname,port,user,pass,
- /*VIX_HOSTOPTION_USE_EVENT_PUMP,*/ 0, VIX_INVALID_HANDLE, NULL,NULL
- );
+ hosttype,hostname,port,user,pass,
+ /*VIX_HOSTOPTION_USE_EVENT_PUMP,*/
+ 0, VIX_INVALID_HANDLE, NULL,NULL);
/* Wait on connect */
err = VixJob_Wait(job, VIX_PROPERTY_JOB_RESULT_HANDLE, &session, VIX_PROPERTY_NONE);
Vix_ReleaseHandle(job);
- if(VIX_FAILED(err))
+ if(VIX_FAILED(err) || session == VIX_INVALID_HANDLE)
{
- fprintf(stderr,"Failed to connect to vmware host machine\n");
+ fprintf(stderr,"Failed to connect to vmware host machine: %s\n",
+ Vix_GetErrorText(err,NULL));
return Qnil;
}
- fprintf(stderr,"hostHandle is %d\n",session);
-
- /* @session */
- return INT2NUM(session);
+ sprintf(str,"VixAPI::Handle.new(%d)",session);
+ return rb_eval_string(str);
}
VALUE
-_connect_server(VALUE self, VALUE rhosttype, VALUE rhostname, VALUE rport, VALUE ruser, VALUE rpass)
+_disconnect(VALUE self, VALUE rhandle)
{
- char *hostname = StringValueCStr(rhostname);
- int hosttype = NUM2INT(rhosttype);
- int port = NUM2INT(rport);
- char *user = StringValueCStr(ruser);
- char *pass = StringValueCStr(rpass);
-
- return _connect(hosttype,hostname,port,user,pass);
+ VixHandle host = NUM2INT(rhandle);
+ VixHost_Disconnect(host);
+ return Qtrue;
}
-VALUE
-_connect_wkstn(VALUE self)
-{
- return _connect(VIX_SERVICEPROVIDER_VMWARE_WORKSTATION, NULL, 0, NULL, NULL);
-}
+
VALUE
-_vmx_open(VALUE self,VALUE rsession, VALUE rpath)
+_open_vmx(VALUE self,VALUE rhosthandle, VALUE rpath)
{
- char *path = StringValueCStr(rpath);
- int session = NUM2INT(rsession);
-
+ VixHandle host = NUM2INT(rb_iv_get(rhosthandle,"@handle"));
VixHandle job;
VixHandle vm = VIX_INVALID_HANDLE;
VixError err;
+ char *path = StringValueCStr(rpath);
+ char str[200];
- fprintf(stderr,"calling vmx_open(%d,\"%s\");\n",session,path);
+ // fprintf(stderr,"calling vmx_open(%d,\"%s\");\n",session,path);
- job = VixVM_Open(session,path,NULL,NULL);
+ job = VixVM_Open(host,path,NULL,NULL);
err = VixJob_Wait(job, VIX_PROPERTY_JOB_RESULT_HANDLE, &vm, VIX_PROPERTY_NONE);
Vix_ReleaseHandle(job);
if(VIX_FAILED(err))
{
- fprintf(stderr,"Failed open vmx file %s: \n",path, Vix_GetErrorText(err,NULL));
+ fprintf(stderr,"Failed open vmx file (@%s): %s\n",path, Vix_GetErrorText(err,NULL));
return Qnil;
}
- fprintf(stderr,"VM handle is %d\n",vm);
+ // fprintf(stderr,"VM handle is %d\n",vm);
- return INT2NUM(vm);
+ sprintf(str,"VixAPI::Handle.new(%d)",(int)vm);
+ return rb_eval_string(str);
}
View
@@ -1,4 +0,0 @@
-VALUE _connect(int, const char *, int, const char *, const char *);
-VALUE _connect_server(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
-VALUE _connect_wkstn(VALUE);
-VALUE _vmx_open(VALUE, VALUE, VALUE);
Oops, something went wrong.

0 comments on commit 0651b4b

Please sign in to comment.