You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cloudstack.apache.org by Poulpatine <po...@gmail.com> on 2020/09/02 09:51:32 UTC

Pass userdata with CMK

Hi,

I'm trying to pass userdata in cmk command line during virtual machine
deployment but I can't figure how to do that.

Among other tests, I've tried something like that in a very basic shell
script:

#!/bin/bash

cli=cmk
template=7bf01470-e3a5-4f37-b035-023c663c1b48
service=80b47022-a341-446f-a14a-128b85a099d0
zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
keypair=mykey
userdata="$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' user-data)"

$ cli deploy virtualmachine templateid="$template"
serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
user-data="$userdata"

But I still can't figure how to make it.

Do you have any suggestions?

Many thanks.

-- 
\o/ Poulpatine \o/

Re: Pass userdata with CMK

Posted by Vivek Kumar <vi...@indiqus.com.INVALID>.
Hello,

With the help of user data you can push you set of instructions to the VM while deploying VM. So let’s say you want to install any specific packages in the newly deployed VM, So instead of logging to the VM and download it manually you can pass the user-data to the VM while deploying the VM and it will get it done.

There are few prerequisites for user data which can be found in the  ACS document, 

http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.8/virtual_machines/user-data.html#:~:text=CloudStack%20provides%20API%20access%20to,encoding%20to%20a%20deployed%20VM.&text=Deployed%20VMs%20also%20have%20access,user%2Ddata%20formated%20in%20base64. <http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/4.8/virtual_machines/user-data.html#:~:text=CloudStack%20provides%20API%20access%20to,encoding%20to%20a%20deployed%20VM.&text=Deployed%20VMs%20also%20have%20access,user%2Ddata%20formated%20in%20base64.>


So basically once you have installed Cloud-init and other packages mentioned above In link. Then you need to covert you script/data into base64 format and then send via API command.

Let’s a say a script contains -

#! /bin/bash

echo “Hello CloudStack” >> /tmp/userdata.txt 

Now convert above text into the base64 format. - You can use you Linux editor or you can use online tool for.  

https://linuxhint.com/bash_base64_encode_decode/ <https://linuxhint.com/bash_base64_encode_decode/>

Or 

https://www.base64encode.org/ <https://www.base64encode.org/>

Now I have tried to convert and it gave me - ‘IyEgL2Jpbi9iYXNoCgplY2hvIOKAnEhlbGxvIENsb3VkU3RhY2vigJ0gPj4gL3RtcC91c2VyZGF0YS50eHQK’, Now just pass the string while deploying you virtual machine.

i.e 

Cloudmonkey deploy virtualmachine name=x, ….., userdata=IyEgL2Jpbi9iYXNoCgplY2hvIOKAnEhlbGxvIENsb3VkU3RhY2vigJ0gPj4gL3RtcC91c2VyZGF0YS50eHQK

I hope this will clarify your concern.


 
Vivek Kumar
Manager - Cloud & DevOps 
IndiQus Technologies
24*7  O +91 11 4055 1411  |   M +91 7503460090 
www.indiqus.com <http://indiqus.com/>

This message is intended only for the use of the individual or entity to which it is addressed and may contain information that is confidential and/or privileged. If you are not the intended recipient please delete the original message and any copy of it from your computer system. You are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited unless proper authorization has been obtained for such action. If you have received this communication in error, please notify the sender immediately. Although IndiQus attempts to sweep e-mail and attachments for viruses, it does not guarantee that both are virus-free and accepts no liability for any damage sustained as a result of viruses.

> On 02-Sep-2020, at 3:21 PM, Poulpatine <po...@gmail.com> wrote:
> 
> Hi,
> 
> I'm trying to pass userdata in cmk command line during virtual machine
> deployment but I can't figure how to do that.
> 
> Among other tests, I've tried something like that in a very basic shell
> script:
> 
> #!/bin/bash
> 
> cli=cmk
> template=7bf01470-e3a5-4f37-b035-023c663c1b48
> service=80b47022-a341-446f-a14a-128b85a099d0
> zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
> keypair=mykey
> userdata="$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' user-data)"
> 
> $ cli deploy virtualmachine templateid="$template"
> serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
> user-data="$userdata"
> 
> But I still can't figure how to make it.
> 
> Do you have any suggestions?
> 
> Many thanks.
> 
> -- 
> \o/ Poulpatine \o/


Re: Pass userdata with CMK

Posted by Poulpatine <po...@gmail.com>.
Thanks for your help guys. It's working now.

Here is my corrected script:

#!/bin/bash

cli=cmk
template=7bf01470-e3a5-4f37-b035-023c663c1b48
service=80b47022-a341-446f-a14a-128b85a099d0
zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
keypair=mykey
userdata="$(base64 ./user-data)"

$cli deploy virtualmachine templateid="$template"
serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
userdata="$userdata"


Have a nice day.

On Wed, Sep 2, 2020 at 12:15 PM David Jumani <Da...@shapeblue.com>
wrote:

> Hi,
>
> You need to pass the userdata (not user-data) as a base64 encoded string
> (try https://www.base64encode.org/ or the base64 command on Linux).
>
> template=7bf01470-e3a5-4f37-b035-023c663c1b48
> service=80b47022-a341-446f-a14a-128b85a099d0
> zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
> keypair=mykey
> userdata="$(base64 ./user-data)"
>
> cmk deploy virtualmachine templateid="$template"
> serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
> userdata="$userdata"
>
> Thanks,
> David
> ________________________________
> From: Poulpatine <po...@gmail.com>
> Sent: Wednesday, September 2, 2020 3:21 PM
> To: users@cloudstack.apache.org <us...@cloudstack.apache.org>
> Subject: Pass userdata with CMK
>
> Hi,
>
> I'm trying to pass userdata in cmk command line during virtual machine
> deployment but I can't figure how to do that.
>
> Among other tests, I've tried something like that in a very basic shell
> script:
>
> #!/bin/bash
>
> cli=cmk
> template=7bf01470-e3a5-4f37-b035-023c663c1b48
> service=80b47022-a341-446f-a14a-128b85a099d0
> zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
> keypair=mykey
> userdata="$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' user-data)"
>
> $ cli deploy virtualmachine templateid="$template"
> serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
> user-data="$userdata"
>
> But I still can't figure how to make it.
>
> Do you have any suggestions?
>
> Many thanks.
>
> --
> \o/ Poulpatine \o/
>
> David.Jumani@shapeblue.com
> www.shapeblue.com
> 3 London Bridge Street,  3rd floor, News Building, London  SE1 9SGUK
> @shapeblue
>
>
>
>

-- 
\o/ Poulpatine \o/

Re: Pass userdata with CMK

Posted by David Jumani <Da...@shapeblue.com>.
Hi,

You need to pass the userdata (not user-data) as a base64 encoded string (try https://www.base64encode.org/ or the base64 command on Linux).

template=7bf01470-e3a5-4f37-b035-023c663c1b48
service=80b47022-a341-446f-a14a-128b85a099d0
zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
keypair=mykey
userdata="$(base64 ./user-data)"

cmk deploy virtualmachine templateid="$template"
serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
userdata="$userdata"

Thanks,
David
________________________________
From: Poulpatine <po...@gmail.com>
Sent: Wednesday, September 2, 2020 3:21 PM
To: users@cloudstack.apache.org <us...@cloudstack.apache.org>
Subject: Pass userdata with CMK

Hi,

I'm trying to pass userdata in cmk command line during virtual machine
deployment but I can't figure how to do that.

Among other tests, I've tried something like that in a very basic shell
script:

#!/bin/bash

cli=cmk
template=7bf01470-e3a5-4f37-b035-023c663c1b48
service=80b47022-a341-446f-a14a-128b85a099d0
zone=530cb1c3-1c90-4055-816e-3b58fbf9de91
keypair=mykey
userdata="$(sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g' user-data)"

$ cli deploy virtualmachine templateid="$template"
serviceofferingid="$service" zoneid="$zone" keypair="$keypair"
user-data="$userdata"

But I still can't figure how to make it.

Do you have any suggestions?

Many thanks.

--
\o/ Poulpatine \o/

David.Jumani@shapeblue.com 
www.shapeblue.com
3 London Bridge Street,  3rd floor, News Building, London  SE1 9SGUK
@shapeblue