On Sat, Sep 29, 2012 at 7:07 PM, Jakov Sosic <jsosic(a)srce.hr> wrote:
Hi.
I'm trying to import output of cobbler commands to Ruby in some
structured way...
I'm interested in 'interfaces', so for example:
# cobbler system dumpvars --name=koji.srce.hr | grep interfaces
interfaces : {'eth0': {'ipv6_address': '',
'interface_type': '',
'static': False, 'owner': 'vm-node001', 'enable_gpxe':
0,
'bonding_master': '', 'gateway': '10.5.100.5',
'subnet': '',
'management': False, 'interface_master': '', 'hostname':
'vm-node001',
'filename': '/pxelinux.0', 'bridge_opts': '',
'mac_address':
'00:50:56:b0:00:26', 'netboot_enabled': False, 'distro':
{'comment': '',
'kernel': '/distros/CentOS-6.3-x86_64/images/pxeboot/vmlinuz',
'uid':
'MTM0ODc0NzE1Ni4zODk1MjAzNDkuNTcyMg', 'kernel_options_post': {},
'redhat_management_key': '<<inherit>>',
'kernel_options': {},
'redhat_management_server': '<<inherit>>', 'initrd':
'/distros/CentOS-6.3-x86_64/images/pxeboot/initrd.img', 'mtime':
1348747156.380496, 'template_files': {}, 'ks_meta': {},
'boot_files':
{}, 'breed': 'redhat', 'os_version': 'generic26',
'mgmt_classes': [],
'fetchable_files': {}, 'tree_build_time': 0, 'arch':
'x86_64', 'name':
'CentOS-6.3-x86_64', 'owners': ['admin'], 'ctime':
1348747156.380496,
'source_repos': [], 'depth': 0}, 'virt_bridge': '',
'bonding': '',
'bonding_opts': '', 'ipv6_mtu': '', 'ip_address':
'1.1.1.1', 'dhcp_tag':
'', 'name': 'vm-node001', 'static_routes': [],
'ipv6_static_routes': [],
'dns_name': 'vm-node001', 'netmask': '', 'mtu':
'', 'ipv6_secondaries':
[], 'next_server': '1.1.1.1', 'ipv6_default_gateway':
''}}
Any ideas how to parse it easily without braking my neck trying to
dismantle it by regexps? Is this maybe JSON or something similar?
It is JSON, so just parse it as such. Alternatively, you could use a
ruby XMLRPC library to connect to cobblerd directly and get the
objects via the API, rather than shell out to the command line.