Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to link logical-server to physical-server via "servers[]" through API #951

Open
ggs67 opened this issue Nov 8, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@ggs67
Copy link

ggs67 commented Nov 8, 2024

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

@dbarzin dbarzin self-assigned this Nov 8, 2024
@dbarzin
Copy link
Owner

dbarzin commented Nov 11, 2024

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':'[email protected]', '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)

@dbarzin dbarzin added the question Further information is requested label Nov 11, 2024
@ggs67
Copy link
Author

ggs67 commented Nov 12, 2024

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] }

@dbarzin
Copy link
Owner

dbarzin commented Nov 12, 2024 via email

@ggs67
Copy link
Author

ggs67 commented Nov 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants