<div dir="ltr"><div><div>I see you didn't approve the fact that API calls an API, i see that it's a necessity especially for handling the multi host and multi node in case we install proxmox in different datacenters.<br></div>Thank you for your answer, i care about the answer, not the act of being direct or not.<br></div>Anycase, can you explain me more this<br>"Be sure to respect the licence from the (PHP) API binding you're<br>
using, avoiding legal trouble is always good, I guess"<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 13 February 2016 at 12:36, Thomas Lamprecht <span dir="ltr"><<a href="mailto:t.lamprecht@proxmox.com" target="_blank">t.lamprecht@proxmox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA256<br>
<br>
Hi,<br>
<span class=""><br>
Al 13.02.2016 a 11:38 Mohamed Sadok Ben Jazia ha scritto:<br>
> Hello, to describe my purpose, i'm supposed to create a commercial<br>
> plateform for providing IAAS and PAAS using proxmox. For this<br>
> step, i'm planning to develop a full API for third pary users, the<br>
> development will be done in PHP as start. The API will contain 3<br>
> main parts (clustering and managing hosts and nodes, Actions on<br>
> CT's and VM's, Authorisations handling)<br>
<br>
</span>A ReST API to another ReST API, interesting. :)<br>
Be sure to respect the licence from the (PHP) API binding you're<br>
using, avoiding legal trouble is always good, I guess.<br>
<span class=""><br>
> The issue i'm facing here happens when i run simultaneous API call<br>
> to create CT's on the same host because i'm using call-to-nextid()<br>
> that returns the same id. I think semaphores or mutex are not a<br>
> good options because once not well implemented, i will have<br>
> deadlocks which is worst than simple error.<br>
<br>
</span>Can you please describe to me what I my proposed implementation can<br>
result in a deadlock? AFAIK, solutions which are using only one (!)<br>
lock are deadlock safe per definition, there is no possibility to<br>
cause a deadlock in this case and if you're using more locks only be<br>
sure to acquire and release them all (!) in the same order and your<br>
good to go. You normally only get deadlocks when at least two<br>
resources (i.e. locks) are wanted and multiple consumers (i.e.<br>
processes/API callers) are running.<br>
<br>
See <a href="https://en.wikipedia.org/wiki/Deadlock" rel="noreferrer" target="_blank">https://en.wikipedia.org/wiki/Deadlock</a><br>
<span class=""><br>
> I simply think to implement call-to-nextid() myself and get a list<br>
> of used id's and add a random number for security but it's not a<br>
> perfect choice.<br>
><br>
<br>
</span>That's not "added security", further you also will come into<br>
collisions with this approach as random is random.<br>
<br>
<br>
I'm hoping you don't take this answer as an insult/attack as I'm quite<br>
direct, I only want to set a few things straight and help you to<br>
understand why I proposed such a solution.<br>
<br>
I'm thinking also about making a patch which adds another parameter to<br>
the create Container and Virtual Machine API calls, which results in<br>
auto selecting a free VMID when creating one and returning that when<br>
finished.<br>
This seems as an usable "feature" for other use cases then yours also,<br>
but no promise yet, we have to look if it fits in our concept.<br>
<br>
cheers,<br>
Thomas<br>
<span class=""><br>
> On 13 February 2016 at 10:07, Thomas Lamprecht<br>
</span><div><div class="h5">> <<a href="mailto:t.lamprecht@proxmox.com">t.lamprecht@proxmox.com</a> <mailto:<a href="mailto:t.lamprecht@proxmox.com">t.lamprecht@proxmox.com</a>>> wrote:<br>
><br>
> Hi,<br>
><br>
> can you show a (simple) example how you do it? Are you making next<br>
> id calls from all over the cluster (in parallel)?<br>
><br>
> If you're doing it in serial like:<br>
><br>
> new_vmid = call-to-nextid(); create-ct(new_vmid)<br>
><br>
> you're fine, doing parallel calls you get race conditions and<br>
> atomicity violations.<br>
><br>
> Solving that could be done in several ways:<br>
><br>
> * Locking from your side (with semaphore, mutex, ...)<br>
><br>
><br>
> LOCK(CREATE)<br>
><br>
> new_vmid = call-to-nextid(); create-ct(new_vmid)<br>
><br>
> UNLOCK(CREATE)<br>
><br>
><br>
> this is a pit of an overkill though, as you only need to lock until<br>
> the container config is created in:<br>
><br>
> /etc/pve/nodes/<yournode>/lxc/<neew_vmid>.conf<br>
><br>
> Ther should be also the possibility to force create a CT, AFAIK,<br>
> then you could do the following:<br>
><br>
> LOCK(CREATE)<br>
><br>
> new_vmid = call-to-nextid();<br>
><br>
> // create the cfg file before calling pct create touch<br>
> /etc/pve/nodes/<yournode>/lxc/<new_vmid>.conf<br>
><br>
> UNLOCK(CREATE)<br>
><br>
> create-ct(new_vmid, force=true)<br>
><br>
><br>
> The locked context here would be magnitudes shorter and thus<br>
> everything more responsive, BUT I didn't tested that sod it could<br>
> be that I'm miss a check we do, will quickly test it on Monday.<br>
><br>
> Third way would be to hold a possible free list "bitmap" of VMIDs<br>
> in your program which you use to determine the next free. This<br>
> would be synced with the real one from time to time, not that nice<br>
> but a possibility.<br>
><br>
> Out of interest, in what language do you make this? And what's the<br>
> goal, if I may ask?<br>
><br>
> cheers, Thomas<br>
><br>
><br>
> On 10.02.2016 10:08, Mohamed Sadok Ben Jazia wrote:<br>
>> Hello list, I'm creating LXC container using the API on proxmox<br>
>> 4.1 I use get("/cluster/nextid") to get the next free id to use.<br>
>> The issue i encountered is when i do simultaneous number of API<br>
>> calls I get proxmox trying to create containers with the same ID<br>
>> which<br>
> gave me<br>
>> this error<br>
>><br>
>> trying to aquire lock...TASK ERROR: can't lock file<br>
>> '/run/lock/lxc/pve-config-147.lock' - got timeout<br>
>><br>
>> are there a standard way to deal with this?<br>
>><br>
>><br>
>> _______________________________________________ pve-user mailing<br>
</div></div>>> list <a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a> <mailto:<a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a>><br>
<span class="">>> <a href="http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user" rel="noreferrer" target="_blank">http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user</a><br>
>><br>
><br>
> _______________________________________________ pve-user mailing<br>
</span>> list <a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a> <mailto:<a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a>><br>
<span class="">> <a href="http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user" rel="noreferrer" target="_blank">http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user</a><br>
><br>
><br>
><br>
><br>
> _______________________________________________ pve-user mailing<br>
> list <a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a><br>
> <a href="http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user" rel="noreferrer" target="_blank">http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user</a><br>
><br>
</span>-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v2<br>
<br>
iQIcBAEBCAAGBQJWvxUvAAoJEATlfMwh0PH8/oQQANBW5OW1RBOtuBrGaqn1yhsx<br>
Xlc0aRs063jSLcQlGzMAGMkE1RLtR6TQkObSUBTa5g3H/rmWCXbo1vV9IfPZ4Qmu<br>
osyqxRBiTO7QwALu4UmZhTmoGruHBOzwQNed9F37jRXO3xKYTgiO6zpjJGaDouci<br>
tc8AWsawvvSZ9t3YggE3JJwMH+AmSiZTsyqlTCIQ72ojxIIxYX09vKG6OHf/Xes8<br>
Rx5WPbjXZGs9O/upwlNuPKpOYI0dQr5ldPGHDwBn5XNTwTtcn5KYJLMXgbKH93O4<br>
OAiEtaom0diVFF/Xef4emjfVGtOF3deesJh+IhcT1dJLnk52zfULFQw3t6UJzrRk<br>
GACvt+/O5vvJ5yWmnRawcFCpiAA1Yji9KObImx/rC6muPd2Jmzqhq14041lhmR8u<br>
+w3lKrktRjaHRGCGFI4OKOlBdzbFBteptBfeqGxM1Wz6WEppKzAI5kbg+MClqi3R<br>
kDluwK7mfKQuZYLnf4Qef2oXJ4Yqi2zkomR8e40xz7sTftf8QDovORVekvakkLxm<br>
a/WglVhfOWs2UPa1HRUjwnY/dM/pxN+fbnd4rFJmfIWbYWsYjrGG0b5ddeWIL3x2<br>
Ho0kk6Aik3o7T37syyW52RXJ61A9NyebN2j5jsmZ2khsWysVS/VjN9Uivec8St7a<br>
dM9W6CLmudGvV8kZvK7Y<br>
=HC9T<br>
-----END PGP SIGNATURE-----<br>
<br>_______________________________________________<br>
pve-user mailing list<br>
<a href="mailto:pve-user@pve.proxmox.com">pve-user@pve.proxmox.com</a><br>
<a href="http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user" rel="noreferrer" target="_blank">http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-user</a><br>
<br></blockquote></div><br></div>