------=_Part_6226104_1412353006.1392849662491
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
----- Original Message -----
From: "Tejesh M" <tejeshmk(a)gmail.com>
To: "users(a)oVirt.org" <users(a)ovirt.org>
Sent: Wednesday, February 19, 2014 3:24:40 PM
Subject: [Users] Fwd: Sample code for setting NIC - CloudInit
Hi,
Can someone share me sample java code for assigning IP address for VM on eth0
through Java SDK via CloudInit ?
Hi Tejesh,
I've attached a sample code that sends the required request (as the output is
demonstrated in debug mode).
Note that the code is jdk-7 compliant.
I haven't configured cloud-init and haven't tested it end-to-end.
Please try to test it on your environment and provide a feedback for it.
Thanks,
Moti
Something Like this but in Java:
<network_configuration>
<nics>
<nic>
<name>eth0</name>
<boot_protocol>STATIC</boot_protocol>
<network>
<ip address="192.168.2.11" netmask="255.255.0.0"
gateway="192.168.2.1" />
</network>
<on_boot>true</on_boot>
</nic>
<nic>
<name>eth1</name>
<boot_protocol>DHCP</boot_protocol>
</nic>
<nic>
<name>eth2</name>
<boot_protocol>NONE</boot_protocol>
<on_boot>true</on_boot>
</nic>
</nics>
<dns>
<servers>
<host>
<address>1.1.2.2</address>
</host>
<host>
<address>1.2.3.4</address>
</host>
</servers>
<search_domains>
<host>
<address>qa.lab</address>
</host>
<host>
<address>
google.com </address>
</host>
</search_domains>
</dns>
</network_configuration>
--
Thanks & Regards
Tejesh
_______________________________________________
Users mailing list
Users(a)ovirt.org
http://lists.ovirt.org/mailman/listinfo/users
------=_Part_6226104_1412353006.1392849662491
Content-Type: text/x-java; name=VmCloudInit.java
Content-Disposition: attachment; filename=VmCloudInit.java
Content-Transfer-Encoding: base64
cGFja2FnZSBvcmcub3ZpcnQudGVzdGRheTsKCmltcG9ydCBqYXZhLmlvLklPRXhjZXB0aW9uOwpp
bXBvcnQgamF2YS51dGlsLkFycmF5czsKaW1wb3J0IGphdmEudXRpbC5MaXN0OwoKaW1wb3J0IG9y
Zy5hcGFjaGUuaHR0cC5jbGllbnQuQ2xpZW50UH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ZXN0OgogKiAgICAgPG5ldHdvcmtfY29uZmlndXJhdGlvbj4K
ICAgICAgICAgPG5pY3M+CiAgICAgICAgICAgPG5pYz4KICAgICAgICAgICAgIDxuYW1lPmV0aDA8
L25hbWU+CiAgICAgICAgICAgICA8Ym9vdF9wcm90b2NvbD5TVEFUSUM8L2Jvb3RfcHJvdG9jb2w+
CiAgICAgICAgICAgICA8bmV0d29yaz4KICAgICAgICAgICAgICAgPGlwIGFkZHJlc3M9IjE5Mi4x
NjguMi4xMSIgbmV0bWFzaz0iMjU1LjI1NS4wLjAiIGdhdGV3YXk9IjE5Mi4xNjguMi4xIiAvPgog
ICAgICAgICAgICAgPC9uZXR3b3JrPgogICAgICAgICAgICAgPG9uX2Jvb3Q+dHJ1ZTwvb25fYm9v
dD4KICAgICAgICAgICA8L25pYz4KICAgICAgICAgICA8bmljPgogICAgICAgICAgICAgPG5hbWU+
ZXRoMTwvbmFtZT4KICAgICAgICAgICAgIDxib290X3Byb3RvY29sPkRIQ1A8L2Jvb3RfcHJvdG9j
b2w+CiAgICAgICAgICAgPC9uaWM+CiAgICAgICAgICAgPG5pYz4KICAgICAgICAgICAgIDxuYW1l
PmV0aDI8L25hbWU+CiAgICAgICAgICAgICA8Ym9vdF9wcm90b2NvbD5OT05FPC9ib290X3Byb3Rv
Y29sPgogICAgICAgICAgICAgPG9uX2Jvb3Q+dHJ1ZTwvb25fYm9vdD4KICAgICAgICAgICA8L25p
Yz4KICAgICAgICAgPC9uaWNzPgogICAgICAgICA8ZG5zPgogICAgICAgICAgIDxzZXJ2ZXJzPgog
ICAgICAgICAgICAgPGhvc3Q+CiAgICAgICAgICAgICAgIDxhZGRyZXNzPjEuMS4yLjI8L2FkZHJl
c3M+CiAgICAgICAgICAgICA8L2hvc3Q+CiAgICAgICAgICAgICA8aG9zdD4KICAgICAgICAgICAg
ICAgPGFkZHJlc3M+MS4yLjMuNDwvYWRkcmVzcz4KICAgICAgICAgICAgIDwvaG9zdD4KICAgICAg
ICAgICA8L3NlcnZlcnM+CiAgICAgICAgICAgPHNlYXJjaF9kb21haW5zPgogICAgICAgICAgICAg
PGhvc3Q+CiAgICAgICAgICAgICAgIDxhZGRyZXNzPnFhLmxhYjwvYWRkcmVzcz4KICAgICAgICAg
ICAgIDwvaG9zdD4KICAgICAgICAgICAgIDxob3N0PgogICAgICAgICAgICAgICA8YWRkcmVzcz5n
b29nbGUuY29tPC9hZGRyZXNzPgogICAgICAgICAgICAgPC9ob3N0PgogICAgICAgICAgIDwvc2Vh
cmNoX2RvbWFpbnM+CiAgICAgICAgIDwvZG5zPgogICAgICAgPC9uZXR3b3JrX2NvbmZpZ3VyYXRp
b24+CiAqCiAqLwpwdWJsaWMgY2xhc3MgVm1DbG91ZEluaXQgewoKICAgIHB1YmxpYyBzdGF0aWMg
dm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBDbGllbnRQcm90b2NvbEV4Y2VwdGlvbiwg
U2VydmVyRXhjZXB0aW9uLAogICAgICAgICAgICBVbnNlY3VyZWRDb25uZWN0aW9uQXR0ZW1wdEVy
cm9yLCBJT0V4Y2VwdGlvbiB7CgogICAgICAgIHRyeSAoQXBpIGFwaSA9IG5ldyBBcGkoImh0dHA6
Ly9sb2NhbGhvc3Q6ODA4MC9hcGkiLAogICAgICAgICAgICAgICAgImFkbWluQGludGVybmFsIiwK
ICAgICAgICAgICAgICAgICIxIiwKICAgICAgICAgICAgICAgIG51bGwsIG51bGwsIG51bGwsIG51
bGwsIG51bGwsIG51bGwsIHRydWUpKXsKCiAgICAgICAgICAgIFZNIHZtID0gYXBpLmdldFZNcygp
LmdldCgidm0xIik7CiAgICAgICAgICAgIE5ldHdvcmtDb25maWd1cmF0aW9uIG5ldHdvcmtDb25m
aWd1cmF0aW9uID0gbmV3IE5ldHdvcmtDb25maWd1cmF0aW9uKCk7CiAgICAgICAgICAgIEROUyBk
bnMgPSBuZXcgRE5TKCk7CiAgICAgICAgICAgIGRucy5zZXRTZXJ2ZXJzKG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JpbmcgYWRkcmVzcywgU3RyaW5nIG5ldG1hc2ss
IFN0cmluZyBnYXRld2F5KSB7CiAgICAgICAgTmV0d29yayBuZXR3b3JrID0gbmV3IE5ldHdvcmso
KTsKICAgICAgICBJUCBpcCA9IG5ldyBJUCgpOwogICAgICAgIGlwLnNldEFkZHJlc3MoYWRkcmVz
cyk7CiAgICAgICAgaXAuc2V0TmV0bWFzayhuZXRtYXNrKTsKICAgICAgICBpcC5zZXRHYXRld2F5
KGdhdGV3YXkpOwogICAgICAgIG5ldHdvcmsuc2V0SXAoaXApOwogICAgICAgIHJldHVybiBuZXR3
b3JrOwogICAgfQoKfQo=
------=_Part_6226104_1412353006.1392849662491--