[ovirt-users] VM run once API required
Juan Hernández
jhernand at redhat.com
Tue Jun 30 11:27:58 UTC 2015
On 06/30/2015 08:16 AM, Chandrahasa S wrote:
> Hi Experts,
>
> We are integrating RHEV(M) with our internal cloud portal using RHEV(M)
> API, we are able to provision Linux VM using API. But IP and Hostname
> not getting reflected on vm first boot. If we boot VM manually using
> run once its working fine. We are not able to find any run once API on
> RHEV end.
>
> Requested your help on this.
>
Assuming that you already installed cloud-init in the VM and that you
want to specify the cloud-init parameters as part of the request to
start the VM, then you will need something like this:
---8<---
!/bin/sh -ex
url="https://engine.example.com/ovirt-engine/api"
user="admin at internal"
password="..."
curl \
--insecure \
--user "${user}:${password}" \
--request POST \
--header "Content-Type: application/xml" \
--header "Accept: application/xml" \
--data '
<action>
<vm>
<initialization>
<cloud_init>
<host>
<address>myhost.example.com</address>
</host>
<network_configuration>
<nics>
<nic>
<name>eth0</name>
<network>
<ip netmask="255.255.255.0" gateway="10.10.10.1"
address="10.10.10.1"/>
</network>
<boot_protocol>static</boot_protocol>
<on_boot>true</on_boot>
</nic>
</nics>
</network_configuration>
</cloud_init>
</initialization>
</vm>
</action>
' \
"${url}/vms/0f3c320-a409-4e9f-918e-3172818d54ed/start
--->8---
If you prefer the Python SDK (which is much better the moment you want
to do something more complicated) then it should be something like this:
---8<---
#!/usr/bin/python
from ovirtsdk import api
from ovirtsdk.xml import params
api = api.API(
url="https://engine.example.com/ovirt-engine/api",
username="admin at internal",
password="...",
insecure=True
)
vm = api.vms.get(name="myvm")
action = params.Action(
vm=params.VM(
initialization=params.Initialization(
cloud_init=params.CloudInit(
host=params.Host(
address="myhost.example.com"
),
network_configuration=params.NetworkConfiguration(
nics=params.Nics(
nic=[
params.NIC(
name="eth0",
boot_protocol="static",
on_boot=True,
network=params.Network(
ip=params.IP(
address="10.10.10.1",
netmask="255.255.255.0",
gateway="10.10.10.1"
)
)
)
]
)
)
)
)
)
)
vm.start(action)
api.disconnect()
--->8---
You can also use the Java SDK, let me know if you need an example of that.
>
> Thanks & Regards
> Chandrahasa S
>
> =====-----=====-----=====
> Notice: The information contained in this e-mail
> message and/or attachments to it may contain
> confidential or privileged information. If you are
> not the intended recipient, any dissemination, use,
> review, distribution, printing or copying of the
> information contained in this e-mail message
> and/or attachments to it are strictly prohibited. If
> you have received this communication in error,
> please notify us by reply e-mail or telephone and
> immediately and permanently delete the message
> and any attachments. Thank you
>
>
>
> _______________________________________________
> Users mailing list
> Users at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/users
>
--
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
More information about the Users
mailing list