Re: [smartos-discuss] Scripting question Bash

2018-02-02 Thread Tamás Gérczei
While this might be slightly off, these things can be handled in Ansible
in a fairly elegant manner OOTB now.

T.

On 2018-02-03 00:16, Cody Mello wrote:
> On Fri, Feb 2, 2018 at 11:43 AM, George Linn via smartos-discuss
>  wrote:
>> The following does not work:
>> /usr/sbin/vmadm create -f /opt/json_to_create_vm |  /usr/bin/cut -d" " -f7
>>
>> I can grep and cut output from “vmadm list” but neither cut or grep works on 
>> “vmadm create -f”.
>> Is the issue that “vmadm create -f” creates additional processes and writes 
>> text to the screen that grep and cut process don’t have access to?
> This is because `vmadm create` prints the message to stderr. If you
> want to capture it, you will need to redirect stderr to stdout. Of
> course, if you did this, then you might lose any information about a
> failure to cut, so you'd probably want to beef up your script to first
> save the output, check the exit code, and then extract the uuid from
> the message if vmadm succeeded, or print the message if it failed.
> 
> -  Cody
> 



---
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com


Re: [smartos-discuss] Scripting question Bash

2018-02-02 Thread Joshua M. Clulow
On 2 February 2018 at 11:59, Paul Sture  wrote:
> /usr/sbin/vmadm list -Ho uuid alias=myzonealias

Even better is probably: "vmadm lookup -1 alias=myzonealias"

-- 
Joshua M. Clulow
Engineer @ Joyent
http://blog.sysmgr.org


---
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com


Re: [smartos-discuss] Scripting question Bash

2018-02-02 Thread Paul Sture

On 2 Feb 2018, at 20:43, George Linn via smartos-discuss wrote:

Just out of curiosity, from a bash script the following works as 
expected:
/usr/sbin/vmadm list | /usr/bin/grep myzonealias | /usr/bin/cut -d" " 
-f1


This doesn't answer your question about additional processes, but the 
above command
would return multiple uuids where zones when aliases myzonealias, 
myzonealias1,

aaa-myzonealias-zzz are present.

This is more accurate:

/usr/sbin/vmadm list -Ho uuid alias=myzonealias


---
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com


Re: [smartos-discuss] Scripting question Bash

2018-02-02 Thread George Linn via smartos-discuss
 Got it.  Thank you.
George
On Friday, February 2, 2018, 2:08:06 PM EST, Cody Mello  
wrote:  
 
 In addition to looking it up, you can also set the "uuid" field in the
payload. The VM will be created using that UUID instead of generating
a new one. You can use the uuidgen program to generate a valid UUID
inside your shell script.

On Fri, Feb 2, 2018 at 10:46 AM, Jonathan Perkin  wrote:
> * On 2018-02-02 at 18:24 GMT, George Linn via smartos-discuss wrote:
>
>> I  am trying to figure out how to script some vmadm commands in a bash 
>> script. For a basic scenario, the bash script calls vmadm to create a VM and 
>> that works fine.  However, I am trying to capture the UUID of the newly 
>> created VM.
>> I receive the following message on the screen:
>> "Successfully created VM 0999429a-6b52-edfd-f0b7-997ca26df1fc"
>>
>> Can someone provide an example of how bash can call "vmadm create -f" and 
>> record the UUID if the VM is successfully created?
>
> Rather than parsing the output which shouldn't be considered stable,
> you might want to try the approach of performing a lookup after the
> zone has been created based on the alias you used.
>
> So, for example, after creating a zone with the 'myzonealias' alias
> (catchy I know!):
>
>  $ vmadm create <<-EOF
>  >  ..
>  >  "alias": "myzonealias",
>  >  ..
>  > EOF
> 
> You can use 'vmadm lookup' to retrive the UUID:
> 
> $ myzoneuuid=$(vmadm lookup -1 alias=myzonealias)
> 
> As long as you don't have duplicate aliases (which would probably be a
> bad idea in the first place anyway), this should work fine.
> 
> --
> Jonathan Perkin  -  Joyent, Inc.  -  www.joyent.com
> 
 
 



---
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com


Re: [smartos-discuss] Scripting question Bash

2018-02-02 Thread Cody Mello
In addition to looking it up, you can also set the "uuid" field in the
payload. The VM will be created using that UUID instead of generating
a new one. You can use the uuidgen program to generate a valid UUID
inside your shell script.

On Fri, Feb 2, 2018 at 10:46 AM, Jonathan Perkin  wrote:
> * On 2018-02-02 at 18:24 GMT, George Linn via smartos-discuss wrote:
>
>> I  am trying to figure out how to script some vmadm commands in a bash 
>> script. For a basic scenario, the bash script calls vmadm to create a VM and 
>> that works fine.  However, I am trying to capture the UUID of the newly 
>> created VM.
>> I receive the following message on the screen:
>> "Successfully created VM 0999429a-6b52-edfd-f0b7-997ca26df1fc"
>>
>> Can someone provide an example of how bash can call "vmadm create -f" and 
>> record the UUID if the VM is successfully created?
>
> Rather than parsing the output which shouldn't be considered stable,
> you might want to try the approach of performing a lookup after the
> zone has been created based on the alias you used.
>
> So, for example, after creating a zone with the 'myzonealias' alias
> (catchy I know!):
>
>   $ vmadm create <<-EOF
>   >   ..
>   >   "alias": "myzonealias",
>   >   ..
>   > EOF
> 
> You can use 'vmadm lookup' to retrive the UUID:
> 
> $ myzoneuuid=$(vmadm lookup -1 alias=myzonealias)
> 
> As long as you don't have duplicate aliases (which would probably be a
> bad idea in the first place anyway), this should work fine.
> 
> --
> Jonathan Perkin  -  Joyent, Inc.  -  www.joyent.com
> 


---
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com


Re: [smartos-discuss] Scripting question Bash

2018-02-02 Thread Jonathan Perkin
* On 2018-02-02 at 18:24 GMT, George Linn via smartos-discuss wrote:

> I  am trying to figure out how to script some vmadm commands in a bash 
> script. For a basic scenario, the bash script calls vmadm to create a VM and 
> that works fine.  However, I am trying to capture the UUID of the newly 
> created VM.
> I receive the following message on the screen:
> "Successfully created VM 0999429a-6b52-edfd-f0b7-997ca26df1fc"
> 
> Can someone provide an example of how bash can call "vmadm create -f" and 
> record the UUID if the VM is successfully created?

Rather than parsing the output which shouldn't be considered stable,
you might want to try the approach of performing a lookup after the
zone has been created based on the alias you used.

So, for example, after creating a zone with the 'myzonealias' alias
(catchy I know!):

  $ vmadm create <<-EOF
  >   ..
  >   "alias": "myzonealias",
  >   ..
  > EOF

You can use 'vmadm lookup' to retrive the UUID:

  $ myzoneuuid=$(vmadm lookup -1 alias=myzonealias)

As long as you don't have duplicate aliases (which would probably be a
bad idea in the first place anyway), this should work fine.

-- 
Jonathan Perkin  -  Joyent, Inc.  -  www.joyent.com


---
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com