These are chat archives for allegro/ralph

6th
Jul 2017
Pete
@kasim1r
Jul 06 2017 13:25
Hi folks, I'm currently creating a sync between a cloud platform and our Ralph3 system. I created an API user for that purpose, and that user can successfully log in and do stuff, except for this:
Error in New-RalphCall with
   URL:    https://ralph.my.domain/api/virtual-servers/301
   Method: DELETE
   Body:   
The remote server returned an error: (401) Unauthorized.
   Respns: {"detail":"Authentication credentials were not provided."}
New-RalphCall is the name of my Powershell function.
Am I doing this the wrong way? Is there another way to delete a VM like in this case?
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:28
@kasim1r does your client send appropriate authentication headers?
Pete
@kasim1r
Jul 06 2017 13:29
$RalphApiKey = "8f3612d6b0dd0007b8c464914c90fad6fa5f53d0" $Headers = @{ "Authorization" = "Token $($RalphApiKey)" "Content-Type" = "application/json" }
ups. well, these are my headers
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:31
That key is that user's key isn't it?
Pete
@kasim1r
Jul 06 2017 13:32
yes, the user name is "ralph-api"
was not needed to be submitted, though
only the key
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:32
yup
let me check one thing quickly please
Pete
@kasim1r
Jul 06 2017 13:33
ok. as stated, everyhting else works alright: creating things, modifying things, just not delete :)
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:34
With the same API key?
Pete
@kasim1r
Jul 06 2017 13:34
yes, it's the only one I have
use it for all things I do against the Ralph API
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:35
Well, that's the thing I wanted to check actually, but you can do it as well. Could you please check that user has permissions to delete virtual servers?
Pete
@kasim1r
Jul 06 2017 13:36
he has the super user option activated
image.png
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:44
@kasim1r have you tried sending DELETE requests to other endpoints?
Pete
@kasim1r
Jul 06 2017 13:45
no, not yet, becuase the delete method is only called in very special cases. here: VM has been redeployed -> delete VM name object, create new VM
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:46
Could you please do that? -- It would definitely help to localize the issue
Pete
@kasim1r
Jul 06 2017 13:50
hm, trying. will take a while.
could the reason be that the virtual server object has children (IP addresses, ethernets, processor)?
Roman Prykhodchenko
@romcheg
Jul 06 2017 13:51
I'm actually trying to reproduce this scenario now
Although I would expect a different responce code :)
Roman Prykhodchenko
@romcheg
Jul 06 2017 14:03
So I have tried deleting a virtual server in the latest ralph and it returned 204 as expexted
@kasim1r could you please try adding a trailing / in the end of the URL and check if it still returns 401?
Pete
@kasim1r
Jul 06 2017 14:27
a colleague has deleted the VM manually.... need to script a test VM
facepalm
Pete
@kasim1r
Jul 06 2017 14:39
OK, adding a trailing slash did the trick!
thanks a lot @romcheg
can you tell me if children are also deleted?
Roman Prykhodchenko
@romcheg
Jul 06 2017 14:40
@kasim1r I would really appreciate, if you tried deleting a server without a trailing slash again and filed a bug, if you get a 401 instead of 304. Could you do that?
Pete
@kasim1r
Jul 06 2017 14:41
on github?
Roman Prykhodchenko
@romcheg
Jul 06 2017 14:41
sure
Pete
@kasim1r
Jul 06 2017 14:46
why do you think it should be a 304?
403 or 404 would be ok
Roman Prykhodchenko
@romcheg
Jul 06 2017 14:47
Django redirects urls with no trailing slashes
so the 304 would clearly notify API consumers they should try re-sending their request to the different URL
Pete
@kasim1r
Jul 06 2017 14:49
allegro/ralph#3119
but I should always have a trailing slash, also when changing or creating objects?
Roman Prykhodchenko
@romcheg
Jul 06 2017 15:00
If it works without the slash -- then you can leave it as it is
However, our django settings return 304s for that
So your HTTP client probable handles that