Open ggs67 opened 6 days ago
Here is a sample in python
#!/usr/bin/python3
import requests
vheaders = {}
vheaders['accept'] = 'application/json'
vheaders['content-type'] = 'application/x-www-form-urlencoded'
vheaders['cache-control'] = 'no-cache'
print("Login")
response = requests.post("http://127.0.0.1:8000/api/login",
headers=vheaders,
data= {'email':'admin@admin.com', 'password':'password'} )
print(response.status_code)
vheaders['Authorization'] = "Bearer " + response.json()['access_token']
print("Get physical server 1")
response = requests.get("http://127.0.0.1:8000/api/physical-servers/1", headers=vheaders)
print(response.json())
print(response.status_code)
print("Get logical server 1")
response = requests.get("http://127.0.0.1:8000/api/logical-servers/1", headers=vheaders)
print(response.json())
print(response.status_code)
data=response.json()['data']
data['servers[]'] = [ "1", "2", "3" ]
data['install_date'] = ''
data['update_date'] = ''
print(data)
print("Update logical server 1")
response = requests.put("http://127.0.0.1:8000/api/logical-servers/1",
headers=vheaders,
data=data)
print(response.json())
print(response.status_code)
I did exactly this but in the initial POST (i.e. create). The code suggests to me that this should work as well. Nevertheless I changed my code to attempt an update via PUT after the create:
The PUT to the URL below returns status code 200, but the physical servers remain empty (physical server with id 4 exists)
BTW: I saw that there was a commit related to this so I did update mercator prior to my tests
URL: https://mercator.oursite.net/api/logical-servers/1480
data (some fields edited or masked:
{'id': 1480, 'name': 'xx-1234xxx123', 'description': '<ul><li><b>Role:</b> some text</li>', 'net_services': None, 'configuration': 'Power state: poweredOn', 'created_at': '2024-11-12', 'updated_at': '2024-11-12', 'deleted_at': None, 'operating_system': 'Red Hat Enterprise Linux', 'address_ip': '192.168.xx.xx', 'cpu': 4, 'memory': '8 GB', 'environment': 'Integration', 'disk': 95, 'disk_used': None, 'install_date': None, 'update_date': None, 'attributes': None, 'patching_frequency': None, 'next_update': None, 'cluster_id': 2, 'domain_id': None, 'servers[]': [4] }
I might have fixed a bug in the API. Didoer
Le mar. 12 nov. 2024, 10:56, Gaston Gloesener @.***> a écrit :
I did exactly this but in the initial POST (i.e. create). The code suggests to me that this should work as well. Nevertheless I changed my code to attempt an update via PUT after the create:
The PUT to the URL below returns status code 200, but the physical servers remain empty (physical server with id 4 exists)
URL: https://mercator.oursite.net/api/logical-servers/1480
data (some fields edited or masked:
{'id': 1480, 'name': 'xx-1234xxx123', 'description': '
Role: some text', 'net_services': None, 'configuration': '
- Power state: poweredOn
- Protected : Yes', 'created_at': '2024-11-12', 'updated_at': '2024-11-12', 'deleted_at': None, 'operating_system': 'Red Hat Enterprise Linux', 'address_ip': '192.168.xx.xx', 'cpu': 4, 'memory': '8 GB', 'environment': 'Integration', 'disk': 95, 'disk_used': None, 'install_date': None, 'update_date': None, 'attributes': None, 'patching_frequency': None, 'next_update': None, 'cluster_id': 2, 'domain_id': None, 'servers[]': [4] }
— Reply to this email directly, view it on GitHub https://github.com/dbarzin/mercator/issues/951#issuecomment-2470085436, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKJU4KGR3LLSSFI7JJJWSK32AHGFZAVCNFSM6AAAAABRN224OKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINZQGA4DKNBTGY . You are receiving this because you were assigned.Message ID: @.***>
Thank you. Works now !
You changed the API not to use [] anymore, so the code above needs to be changed to:
data['servers'] = [ "1", "2", "3" ]
and it works as well in POST than in PUT
I use the API to create our assets and try to link logical-servers to physical-servers which is a n-m relation. I do this in accordance with the code through the "servers[]" json attribute. A dd() in the Mercator code shows that the attribute is well arriving in the method and a second test with a dd() inside the "if" clause which checks for "servers[]" confirms that the if actually recognizes the attribute. Nevertheless the link table stays empty and no error returned.
I have verified that the physical server with ID 4 as passed via "servers[]" : [ 4 ] actually exists