librelist archives

« back to archive

rbvmomi

rbvmomi

From:
Per Mikaelsson
Date:
2011-11-11 @ 14:26
Hi all,

I am stuck again :( nothing unusual with that :) I am trying to use the
rbvmomi gem to connect to a esxi server and deploy, manipulate vmware
images.
my problem is that I want to put in variables so I can fetch different
images let's look at a working code I have

opt = {:host =>'xxx.xxx.xxx.xxx', :user =>'xxxxxxx', :password
=>'xxxxxxxx', :insecure => true}
 vim = RbVmomi::VIM.connect opt
dc = vim.serviceInstance.find_datacenter {"Labbnet"} or fail "datacenter
not found"
vm = dc.find_vm("FW") or fail "VM not found"

if I change for ex

dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
"datacenter not found"

it will fail

this is the code that I use to set  the variable

flow do
  stack :width => 10 do
  end
  flow :width => 0.15 do
    background red ... white
    para "DataCenter "
  end
  $datacenter = edit_line
end

Happy shoeing evryone

Re: [shoes] rbvmomi

From:
ashbb
Date:
2011-11-11 @ 14:46
Hi Per,

> if I change for ex
> dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
"datacenter not found"
> it will fail
Umm,... Does the above code need '#'? Try out to remove '#'.

If this is not the solution, let us know the error message you'll get.

ashbb

Re: [shoes] rbvmomi

From:
Per Mikaelsson
Date:
2011-11-11 @ 16:47
Hi,

I removed the # so it looks like this {$datacenter.text} but fail again
here is the error

================================================================
[2011-11-11T17:46:19+01:00]$ ruby "I:\ruby\vmware\shoe_clone.rb"
================================================================

I:/ruby/vmware/shoe_clone.rb:69:in `block (3 levels) in <main>': VM not
found
     from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/app.rb:221:in
`block (2 levels) in button'
     from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/main.rb:105:in
`call'
     from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/main.rb:105:in
`main'
     from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/main.rb:105:in
`app'
     from I:/ruby/vmware/shoe_clone.rb:5:in `<main>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/ruby.rb:106:in
`exit': wrong number of arguments (1 for 0) (ArgumentError)
    from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/glib2-1.0.3-x86-mingw32/lib/glib2.rb:32:in
`exit_application'
    from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/main.rb:105:in
`main'
    from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/green_shoes-1.0.322/lib/shoes/main.rb:105:in
`app'
    from I:/ruby/vmware/shoe_clone.rb:5:in `<main>'

/Per


2011/11/11 ashbb <ashbbb@gmail.com>

> Hi Per,
>
>
> > if I change for ex
> > dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
> "datacenter not found"
> > it will fail
> Umm,... Does the above code need '#'? Try out to remove '#'.
>
> If this is not the solution, let us know the error message you'll get.
>
> ashbb
>

Re: [shoes] rbvmomi

From:
J. Kaiden
Date:
2011-11-11 @ 19:26
hi Per,

  well, i don't know anything about the rbvmomi gem, but i looked here -
http://rubydoc.info/github/rlane/rbvmomi/master/frames - quickly, and it
looks to me like you want to use parenthesis () instead of curly brackets
{} ...  so that maybe this:

dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
"datacenter not found"

  should look like this:

dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
"datacenter not found"

  or maybe like this:  (although in this case it shouldn't be necessary to
use "#{}" )

dc = vim.serviceInstance.find_datacenter ("#{$datacenter.text}") or fail
"datacenter not found"

  also, (and you can tell me to mind my own business!) does `datacenter`
need to be a global variable, or could it be a local or instance variable
instead?  globals have a way of gumming up the works sometimes - just my
two (unsolicited) cents :)


Shoes On!

  - j

Re: [shoes] rbvmomi

From:
Per Mikaelsson
Date:
2011-11-11 @ 19:45
Hi Jake,

I probably don't need it as a global variable but I am testing everything
here so it got left.

The suggestion to try you gave is without success :( but your two
(unsolicited) cents is appreciated I will take any suggestions I haven't
tried.

The error raised when I try to change it as you suggested is
I:/ruby/vmware/shoe_clone.rb:68: syntax error, unexpected keyword_or,
expecting keyword_end
...enter ("{$datacenter.text}") or fail "datacenter not found"
...                               ^

shoes on m8's

2011/11/11 J. Kaiden <jakekaiden@gmail.com>

> hi Per,
>
>   well, i don't know anything about the rbvmomi gem, but i looked here -
> http://rubydoc.info/github/rlane/rbvmomi/master/frames - quickly, and it
> looks to me like you want to use parenthesis () instead of curly brackets
> {} ...  so that maybe this:
>
> dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
> "datacenter not found"
>
>   should look like this:
>
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
> "datacenter not found"
>
>   or maybe like this:  (although in this case it shouldn't be necessary to
> use "#{}" )
>
> dc = vim.serviceInstance.find_datacenter ("#{$datacenter.text}") or fail
> "datacenter not found"
>
>   also, (and you can tell me to mind my own business!) does `datacenter`
> need to be a global variable, or could it be a local or instance variable
> instead?  globals have a way of gumming up the works sometimes - just my
> two (unsolicited) cents :)
>
>
> Shoes On!
>
>   - j
>

Re: [shoes] rbvmomi

From:
J. Kaiden
Date:
2011-11-11 @ 19:57
hi Per,

  hmm, judging by the error -

...enter ("{$datacenter.text}") or fail "datacenter not found"
...                               ^

  it looks like maybe you've left off the pound sign (#) before the curly
brackets ({}) enclosing `$datacenter.text`, so the interpreter takes it as
a block and not a variable (and breaks!)

  the "#{}" syntax really isn't necessary, as the $datacenter variable is
not part of any larger string...  i think you could probably just use:

dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
"datacenter not found"

  the #text method returns a String, and that's what you need as an
argument, so it should be just fine...

  the "#{variable}" syntax is useful when you want to include one or more
variables in a larger string, but here shouldn't be necessary.

good luck!
happy shoes'in

  - j



On Fri, Nov 11, 2011 at 8:45 PM, Per Mikaelsson <mr.mikaelsson@gmail.com>wrote:

> Hi Jake,
>
> I probably don't need it as a global variable but I am testing everything
> here so it got left.
>
> The suggestion to try you gave is without success :( but your two
> (unsolicited) cents is appreciated I will take any suggestions I haven't
> tried.
>
> The error raised when I try to change it as you suggested is
> I:/ruby/vmware/shoe_clone.rb:68: syntax error, unexpected keyword_or,
> expecting keyword_end
> ...enter ("{$datacenter.text}") or fail "datacenter not found"
> ...                               ^
>
> shoes on m8's
>
> 2011/11/11 J. Kaiden <jakekaiden@gmail.com>
>
> hi Per,
>>
>>   well, i don't know anything about the rbvmomi gem, but i looked here -
>> http://rubydoc.info/github/rlane/rbvmomi/master/frames - quickly, and it
>> looks to me like you want to use parenthesis () instead of curly brackets
>> {} ...  so that maybe this:
>>
>> dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
>> "datacenter not found"
>>
>>   should look like this:
>>
>> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
>> "datacenter not found"
>>
>>   or maybe like this:  (although in this case it shouldn't be necessary
>> to use "#{}" )
>>
>> dc = vim.serviceInstance.find_datacenter ("#{$datacenter.text}") or fail
>> "datacenter not found"
>>
>>   also, (and you can tell me to mind my own business!) does `datacenter`
>> need to be a global variable, or could it be a local or instance variable
>> instead?  globals have a way of gumming up the works sometimes - just my
>> two (unsolicited) cents :)
>>
>>
>> Shoes On!
>>
>>   - j
>>
>
>

Re: [shoes] rbvmomi

From:
Per Mikaelsson
Date:
2011-11-11 @ 20:07
Hi again and thank you for the help you are giving.

this is what it looks like now
dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
"datacenter not found"
the error I get is
syntax error, unexpected keyword_or, expecting keyword_end
...atacenter ($datacenter.text) or fail "datacenter not found"
...                                                    ^

2011/11/11 J. Kaiden <jakekaiden@gmail.com>

> hi Per,
>
>   hmm, judging by the error -
>
> ...enter ("{$datacenter.text}") or fail "datacenter not found"
> ...                               ^
>
>   it looks like maybe you've left off the pound sign (#) before the curly
> brackets ({}) enclosing `$datacenter.text`, so the interpreter takes it as
> a block and not a variable (and breaks!)
>
>   the "#{}" syntax really isn't necessary, as the $datacenter variable is
> not part of any larger string...  i think you could probably just use:
>
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
> "datacenter not found"
>
>   the #text method returns a String, and that's what you need as an
> argument, so it should be just fine...
>
>   the "#{variable}" syntax is useful when you want to include one or more
> variables in a larger string, but here shouldn't be necessary.
>
> good luck!
> happy shoes'in
>
>   - j
>
>
>
> On Fri, Nov 11, 2011 at 8:45 PM, Per Mikaelsson <mr.mikaelsson@gmail.com>wrote:
>
>> Hi Jake,
>>
>> I probably don't need it as a global variable but I am testing everything
>> here so it got left.
>>
>> The suggestion to try you gave is without success :( but your two
>> (unsolicited) cents is appreciated I will take any suggestions I haven't
>> tried.
>>
>> The error raised when I try to change it as you suggested is
>> I:/ruby/vmware/shoe_clone.rb:68: syntax error, unexpected keyword_or,
>> expecting keyword_end
>> ...enter ("{$datacenter.text}") or fail "datacenter not found"
>> ...                               ^
>>
>> shoes on m8's
>>
>> 2011/11/11 J. Kaiden <jakekaiden@gmail.com>
>>
>> hi Per,
>>>
>>>   well, i don't know anything about the rbvmomi gem, but i looked here -
>>> http://rubydoc.info/github/rlane/rbvmomi/master/frames - quickly, and
>>> it looks to me like you want to use parenthesis () instead of curly
>>> brackets {} ...  so that maybe this:
>>>
>>> dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
>>> "datacenter not found"
>>>
>>>   should look like this:
>>>
>>> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
>>> "datacenter not found"
>>>
>>>   or maybe like this:  (although in this case it shouldn't be necessary
>>> to use "#{}" )
>>>
>>> dc = vim.serviceInstance.find_datacenter ("#{$datacenter.text}") or
>>> fail "datacenter not found"
>>>
>>>   also, (and you can tell me to mind my own business!) does `datacenter`
>>> need to be a global variable, or could it be a local or instance variable
>>> instead?  globals have a way of gumming up the works sometimes - just my
>>> two (unsolicited) cents :)
>>>
>>>
>>> Shoes On!
>>>
>>>   - j
>>>
>>
>>
>

Re: [shoes] rbvmomi

From:
Eric Watson
Date:
2011-11-11 @ 20:57
Great!!!

On Nov 11, 2011, at 2:07 PM, Per Mikaelsson wrote:

> Hi again and thank you for the help you are giving.
> 
> this is what it looks like now
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail 
"datacenter not found"
> the error I get is
> syntax error, unexpected keyword_or, expecting keyword_end
> ...atacenter ($datacenter.text) or fail "datacenter not found"
> ...                                                    ^
> 
> 2011/11/11 J. Kaiden <jakekaiden@gmail.com>
> hi Per,
> 
>   hmm, judging by the error -
> 
> ...enter ("{$datacenter.text}") or fail "datacenter not found"
> ...                               ^
> 
>   it looks like maybe you've left off the pound sign (#) before the 
curly brackets ({}) enclosing `$datacenter.text`, so the interpreter takes
it as a block and not a variable (and breaks!)
> 
>   the "#{}" syntax really isn't necessary, as the $datacenter variable 
is not part of any larger string...  i think you could probably just use:
> 
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail 
"datacenter not found"
> 
>   the #text method returns a String, and that's what you need as an 
argument, so it should be just fine...
> 
>   the "#{variable}" syntax is useful when you want to include one or 
more variables in a larger string, but here shouldn't be necessary.
> 
> good luck!
> happy shoes'in
> 
>   - j
> 
> 
> 
> On Fri, Nov 11, 2011 at 8:45 PM, Per Mikaelsson <mr.mikaelsson@gmail.com> wrote:
> Hi Jake,
> 
> I probably don't need it as a global variable but I am testing 
everything here so it got left.
> 
> The suggestion to try you gave is without success :( but your two 
(unsolicited) cents is appreciated I will take any suggestions I haven't 
tried.
> 
> The error raised when I try to change it as you suggested is 
> I:/ruby/vmware/shoe_clone.rb:68: syntax error, unexpected keyword_or, 
expecting keyword_end
> ...enter ("{$datacenter.text}") or fail "datacenter not found"
> ...                               ^
> 
> shoes on m8's
> 
> 2011/11/11 J. Kaiden <jakekaiden@gmail.com>
> 
> hi Per,
> 
>   well, i don't know anything about the rbvmomi gem, but i looked here -
http://rubydoc.info/github/rlane/rbvmomi/master/frames - quickly, and it 
looks to me like you want to use parenthesis () instead of curly brackets 
{} ...  so that maybe this:
> 
> dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail 
"datacenter not found"
> 
>   should look like this:
> 
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail 
"datacenter not found"
> 
>   or maybe like this:  (although in this case it shouldn't be necessary 
to use "#{}" )
> 
> dc = vim.serviceInstance.find_datacenter ("#{$datacenter.text}") or fail
"datacenter not found"
> 
>   also, (and you can tell me to mind my own business!) does `datacenter`
need to be a global variable, or could it be a local or instance variable 
instead?  globals have a way of gumming up the works sometimes - just my 
two (unsolicited) cents :)
> 
> 
> Shoes On!
> 
>   - j
> 
> 
> 

Re: [shoes] rbvmomi

From:
J. Kaiden
Date:
2011-11-12 @ 06:07
glad to see you got things working -

  shoes on!

  - j



On Fri, Nov 11, 2011 at 9:57 PM, Eric Watson <wasnotrice@gmail.com> wrote:

> Great!!!
>
> On Nov 11, 2011, at 2:07 PM, Per Mikaelsson wrote:
>
> Hi again and thank you for the help you are giving.
>
> this is what it looks like now
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
> "datacenter not found"
> the error I get is
> syntax error, unexpected keyword_or, expecting keyword_end
> ...atacenter ($datacenter.text) or fail "datacenter not found"
> ...                                                    ^
>
> 2011/11/11 J. Kaiden <jakekaiden@gmail.com>
>
>> hi Per,
>>
>>   hmm, judging by the error -
>>
>> ...enter ("{$datacenter.text}") or fail "datacenter not found"
>> ...                               ^
>>
>>   it looks like maybe you've left off the pound sign (#) before the curly
>> brackets ({}) enclosing `$datacenter.text`, so the interpreter takes it as
>> a block and not a variable (and breaks!)
>>
>>   the "#{}" syntax really isn't necessary, as the $datacenter variable is
>> not part of any larger string...  i think you could probably just use:
>>
>> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
>> "datacenter not found"
>>
>>   the #text method returns a String, and that's what you need as an
>> argument, so it should be just fine...
>>
>>   the "#{variable}" syntax is useful when you want to include one or more
>> variables in a larger string, but here shouldn't be necessary.
>>
>> good luck!
>> happy shoes'in
>>
>>   - j
>>
>>
>>
>> On Fri, Nov 11, 2011 at 8:45 PM, Per Mikaelsson <mr.mikaelsson@gmail.com>wrote:
>>
>>> Hi Jake,
>>>
>>> I probably don't need it as a global variable but I am testing
>>> everything here so it got left.
>>>
>>> The suggestion to try you gave is without success :( but your two
>>> (unsolicited) cents is appreciated I will take any suggestions I
>>> haven't tried.
>>>
>>> The error raised when I try to change it as you suggested is
>>> I:/ruby/vmware/shoe_clone.rb:68: syntax error, unexpected keyword_or,
>>> expecting keyword_end
>>> ...enter ("{$datacenter.text}") or fail "datacenter not found"
>>> ...                               ^
>>>
>>> shoes on m8's
>>>
>>> 2011/11/11 J. Kaiden <jakekaiden@gmail.com>
>>>
>>> hi Per,
>>>>
>>>>   well, i don't know anything about the rbvmomi gem, but i looked here
>>>> - http://rubydoc.info/github/rlane/rbvmomi/master/frames - quickly,
>>>> and it looks to me like you want to use parenthesis () instead of curly
>>>> brackets {} ...  so that maybe this:
>>>>
>>>> dc = vim.serviceInstance.find_datacenter #{$datacenter.text} or fail
>>>> "datacenter not found"
>>>>
>>>>   should look like this:
>>>>
>>>> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
>>>> "datacenter not found"
>>>>
>>>>   or maybe like this:  (although in this case it shouldn't be necessary
>>>> to use "#{}" )
>>>>
>>>> dc = vim.serviceInstance.find_datacenter ("#{$datacenter.text}") or
>>>> fail "datacenter not found"
>>>>
>>>>   also, (and you can tell me to mind my own business!) does
>>>> `datacenter` need to be a global variable, or could it be a local or
>>>> instance variable instead?  globals have a way of gumming up the works
>>>> sometimes - just my two (unsolicited) cents :)
>>>>
>>>>
>>>> Shoes On!
>>>>
>>>>   - j
>>>>
>>>
>>>
>>
>
>

Re: [shoes] rbvmomi

From:
Eric Watson
Date:
2011-11-11 @ 20:49
On Nov 11, 2011, at 2:07 PM, Per Mikaelsson wrote:

> Hi again and thank you for the help you are giving.
> 
> this is what it looks like now
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail 
"datacenter not found"
> the error I get is
> syntax error, unexpected keyword_or, expecting keyword_end
> ...atacenter ($datacenter.text) or fail "datacenter not found"
> …                                                    ^


I think you might be having trouble with the interpreter mis-grouping your
arguments, especially with that 'or'. I'd stick to '||' instead. What I do
in situations like this is try to simplify things. For example, try this:

cd = vim.serviceInstance.find_datacenter($datacenter.text)

Then, if that works, try adding the fail, like this:

cd = vim.serviceInstance.find_datacenter($datacenter.text) || 
fail("datacenter not found")

Once you get it working, then maybe try removing some of those 
parentheses. Let us know how it goes!

Eric

Re: [shoes] rbvmomi

From:
Per Mikaelsson
Date:
2011-11-11 @ 20:55
Thank you Eric that was on the spot :)

Now it's happy shoeing again

/Per

2011/11/11 Eric Watson <wasnotrice@gmail.com>

> On Nov 11, 2011, at 2:07 PM, Per Mikaelsson wrote:
>
> Hi again and thank you for the help you are giving.
>
> this is what it looks like now
> dc = vim.serviceInstance.find_datacenter ($datacenter.text) or fail
> "datacenter not found"
> the error I get is
> syntax error, unexpected keyword_or, expecting keyword_end
> ...atacenter ($datacenter.text) or fail "datacenter not found"
> …                                                    ^
>
>
> I think you might be having trouble with the interpreter mis-grouping your
> arguments, especially with that 'or'. I'd stick to '||' instead. What I do
> in situations like this is try to simplify things. For example, try this:
>
> cd = vim.serviceInstance.find_datacenter($datacenter.text)
>
> Then, if that works, try adding the fail, like this:
>
> cd = vim.serviceInstance.find_datacenter($datacenter.text) ||
> fail("datacenter not found")
>
> Once you get it working, then maybe try removing some of those
> parentheses. Let us know how it goes!
>
> Eric
>
>