I'm doing a proof of concept using CMDBuild in our deployment pipeline. Basically I want our Ansible Tower to pull detail from CMDbuild and create cloud infrastructure in AWS and then apply application software.
I've got a basic python script that will pull relevant detail from CMDBuild.
I'm having trouble with the insert/Update part - Any assistance would be much appreciated - don't laugh at my attempt:
cmdbuild_url = "http://MYSERVERURL/cmdbuild/services/rest/v2/classes/" + id + "/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
inputdata = {'AMIID': u'AL Redhat Front-End/Web Server (v0.1) (ami-99999999)',
'AZ': 120,
'AdditionalRequirements': u'BLABALBLA',
'Description': u'AL Linux box for ELK',
'IAMRole': None,
'InstanceID': u'i-0c99999999999999e',
'SubnetID': u'subnet-996c8def',
'VPCID': u'vpc-73c4f716'}
r = requests.put(cmdbuild_url, data=json(inputdata), headers=headers)
Try to use post method instead of put method to create a new card.
Put method in CMDBuild rest webservices is used to modify data and must be called in card instance path.
CMDBuild Team
Previously Grant wrote:
I'm doing a proof of concept using CMDBuild in our deployment pipeline. Basically I want our Ansible Tower to pull detail from CMDbuild and create cloud infrastructure in AWS and then apply application software.
I've got a basic python script that will pull relevant detail from CMDBuild.
I'm having trouble with the insert/Update part - Any assistance would be much appreciated - don't laugh at my attempt:
cmdbuild_url = "http://MYSERVERURL/cmdbuild/services/rest/v2/classes/" + id + "/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
inputdata = {'AMIID': u'AL Redhat Front-End/Web Server (v0.1) (ami-99999999)',
'AZ': 120,
'AdditionalRequirements': u'BLABALBLA',
'Description': u'AL Linux box for ELK',
'IAMRole': None,
'InstanceID': u'i-0c99999999999999e',
'SubnetID': u'subnet-996c8def',
'VPCID': u'vpc-73c4f716'}
r = requests.put(cmdbuild_url, data=json(inputdata), headers=headers)
Thanks for your reply
I tried this and now getting a 500 error ( see below >>>>)
Can you please look at my header tags. Is this how you pass in json?
I'm sure I'm missing something basic. Also where can I find the logs to see what internal error is?
Thanks for your help :-)
>>>>
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
inputdata = {'AMIID': u'AL Redhat Front-End/Web Server (v0.1) (ami-99999999)',
'AZ': 120,
'AdditionalRequirements': u'BLABALBLA',
'Code': u'FCP-AL-WEB-RND02',
'Description': u'AL Linux box for ELK',
'IAMRole': None,
'InstanceID': u'i-0c99999999999999e',
'InstanceType': 55,
'Name': u'FCP-AL-WEB-RooD02',
'Notes': None,
'OperatingSystem': 194,
'OwnerID': u'185243059250',
'PrivateIP': u'10.10.339.22',
'PublicIP': None,
'RootDevice': u'/dev/sda1',
'SubnetID': u'subnet-996c8def',
'VPCID': u'vpc-73c4f716'}
r = requests.post(cmdbuild_url, inputdata, headers=headers)
print(r)
Previously Tecnoteca wrote:
Try to use post method instead of put method to create a new card.
Put method in CMDBuild rest webservices is used to modify data and must be called in card instance path.
CMDBuild Team
Previously Grant wrote:
I'm doing a proof of concept using CMDBuild in our deployment pipeline. Basically I want our Ansible Tower to pull detail from CMDbuild and create cloud infrastructure in AWS and then apply application software.
I've got a basic python script that will pull relevant detail from CMDBuild.
I'm having trouble with the insert/Update part - Any assistance would be much appreciated - don't laugh at my attempt:
cmdbuild_url = "http://MYSERVERURL/cmdbuild/services/rest/v2/classes/" + id + "/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
inputdata = {'AMIID': u'AL Redhat Front-End/Web Server (v0.1) (ami-99999999)',
'AZ': 120,
'AdditionalRequirements': u'BLABALBLA',
'Description': u'AL Linux box for ELK',
'IAMRole': None,
'InstanceID': u'i-0c99999999999999e',
'SubnetID': u'subnet-996c8def',
'VPCID': u'vpc-73c4f716'}
r = requests.put(cmdbuild_url, data=json(inputdata), headers=headers
Thank you for the reply
I have tried this with not much success. I've got this now and I get a 200 response yet nothing is inserted into the DB on the card:
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
inputdata = {'cardId': -1,
'className': 'AWSServer',
'Code': '2314234',
'Description': '12341234',
'Name': '12341234',
'InstanceID': '12341234',
'InstanceType': 51,
'AZ':None,
'OwnerID':None,
'VPCID':None,
'SubnetID':None,
'IAMRole':None,
'AMIID':None,
'PrivateIP':None,
'PublicIP':None,
'RootDevice':None,
'AdditionalRequirements':None,
'OperatingSystem':None}
r = requests.post(cmdbuild_url, inputdata, headers=headers)
print(r)
I can't see any simple examples of get/update/insert. The documentation is a little sparse.
Your help is much appreciate :-)
Previously Tecnoteca wrote:
Try to use post method instead of put method to create a new card.
Put method in CMDBuild rest webservices is used to modify data and must be called in card instance path.
CMDBuild Team
Previously Grant wrote:
I'm doing a proof of concept using CMDBuild in our deployment pipeline. Basically I want our Ansible Tower to pull detail from CMDbuild and create cloud infrastructure in AWS and then apply application software.
I've got a basic python script that will pull relevant detail from CMDBuild.
I'm having trouble with the insert/Update part - Any assistance would be much appreciated - don't laugh at my attempt:
cmdbuild_url = "http://MYSERVERURL/cmdbuild/services/rest/v2/classes/" + id + "/cards"
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
inputdata = {'AMIID': u'AL Redhat Front-End/Web Server (v0.1) (ami-99999999)',
'AZ': 120,
'AdditionalRequirements': u'BLABALBLA',
'Description': u'AL Linux box for ELK',
'IAMRole': None,
'InstanceID': u'i-0c99999999999999e',
'SubnetID': u'subnet-996c8def',
'VPCID': u'vpc-73c4f716'}
r = requests.put(cmdbuild_url, data=json(inputdata), headers=headers)
OK - I have success 
This was down to the way I wrapped the json data:
data = {'AMIID': 'amif484', 'AZ': 120, 'AdditionalRequirements': 'Configure WINRM for Ans', 'Code': '434FCPALWEBN02', 'Description': 'sdfsdfsdfsdfsdfsdu', 'IAMRole': None, 'InstanceID': 'i049347a98af506541', 'InstanceType': 55, 'Name': 'FCPALWEBWN02', 'Notes': None, 'OperatingSystem': 192, 'OwnerID': '185243059250', 'PrivateIP': '10103312', 'PublicIP': None, 'RootDevice': 'devsda1', 'SubnetID': 'subnet996c8def', 'VPCID': 'vpc73c4f716'}
headers = {'Content-type': 'application/json', 'Accept': '*/*', 'CMDBuild-Authorization': sessionid }
r = requests.post(cmdbuild_url, data=json.dumps(data), headers=headers)
print (r)
>> Returns 200 and new record is inserted
Thanks for the help