我正在尝试更新"主机记录名称",为了实现相同的目标,我正在使用infoblox-client,但是我遇到了一个障碍,因为我无法修改/更新主机记录。我已经通过 REST API 尝试了相同的方法,并且能够根据需要修改名称,但通过 infoblox-client m 有点卡住了。
以下是我尝试更新记录的步骤:
opts = {'host': '192.168.1.10', 'username': 'admin', 'password': 'admin'}
conn = connector.Connector(opts)
my_ip = objects.IP.create(ip='192.168.1.25')
#to create new host record with parameters
record = objects.HostRecord.create(conn, view='my_dns_view', name='my_host_record.my_zone.com', ip=my_ip)
#to modify m trying following but no luck:
#1_both of below snippet adds a new name to record instead of upodating the same
-> result = objects.HostRecord.create(conn, view='my_dns_view', name='new_name.my_zone.com', ip=my_ip, check_if_exists=True, update_if_exists=True)
-> result = objects.ARecordBase.create(conn, ip='192.168.102.14', name='some-new_name.ansible.com', view='default', update_if_exists=True)
#2_I have gone through infoblox-client test case(test_update_fields_on_create) which I have following steps to modify record:
a_record = [{'_ref': 'record:previously_created_record', 'ip': '192.168.1.52', 'name': 'other_name'}]
#this gives me error for host,username missing.
conn = connector.Connector(a_record)
#this results to None which ultimately blocks me
res = conn.get_object('record:host',a_record)
我能够解决问题,与创建和更新混在一起。
因此,对于任何面临类似问题的人来说,这里的编码解决方案是:
opts = {'host': '192.168.1.10', 'username': 'admin', 'password': 'admin'}
conn = connector.Connector(opts)
my_ip = objects.IP.create(ip='192.168.1.25')
#to create new host record with parameters
record = objects.HostRecord.create(conn, view='my_dns_view', name='host_record.my_zone.com', ip=my_ip)
#to update the name, directly use update_object:
testConn = conn.update_object(record._ref, {'name': 'new_name_host_record.my_zone.com'})
简单。。我刚才在灌木丛里打来跳去..