Hello all:
As you know, Cobbler stores its data in *.json files. I would like to
be able to import system data into a MySQL database. I've been able
to pull the json data into a dictionary using the simplejson module,
like so:
import simplejson as json
mydata = json.load(open('testbox1.json'))
print mydata
{'comment': '', 'kickstart': '<<inherit>>', 'name_servers_search': [],
'ks_meta': {}, 'kernel_options_post': {}, 'image': '',
'redhat_management_key': '<<inherit>>', 'power_type': 'ipmitool',
'power_user': '', 'kernel_options': {}, 'virt_file_size':
'<<inherit>>', 'mtime': 1291922300.5639579, 'template_files': {},
'gateway': '', 'uid': 'MTI5MTkyNjMwPC41NjkyMDkwOTEuNjYxODc',
'virt_auto_boot': '<<inherit>>', 'virt_cpus': '<<inherit>>',
'hostname': '', 'virt_type': '<<inherit>>', 'mgmt_classes': [],
'power_pass': '', 'netboot_enabled': True, 'ipv6_autoconfiguration':
False, 'profile': 'workstation', 'virt_path': '<<inherit>>',
'interfaces': {'eth0': {'dhcp_tag': '', 'subnet': '', 'ipv6_address':
'', 'virt_bridge': '', 'static_routes': [], 'ipv6_mtu': '',
'ipv6_static_routes': [], 'dns_name': '', 'mtu': '', 'bonding': '',
'static': False, 'bonding_opts': '', 'mac_address':
'08:00:27:2B:65:11', 'ipv6_secondaries': [], 'bonding_master': '',
'ip_address': '', 'ipv6_default_gateway': ''}}, 'power_address': '',
'template_remote_kickstarts': 0, 'name_servers': [],
'ipv6_default_device': '', 'name': 'testbox1', 'owners': ['admin'],
'ctime': 1291922300.5639579, 'virt_ram': '<<inherit>>', 'power_id':
'', 'server': '<<inherit>>', 'redhat_management_server':
'<<inherit>>', 'depth': 2}
So far so good...where I'm stuck is importing all this data into the
MySQL database. I've tried massaging the data in various ways but am
unable to get cursor.execute(sql) to work without errors. I think
it's due to the embedded lists and dictionaries in the data set. I
know this is not strictly related to everyday cobbler usage, but you
are python experts who probably could do this in your sleep... Any
ideas?
thanks
Sean