Skip to content

Commit

Permalink
Fixing ripe_create() function mentioned on issue #1 . Also modified e…
Browse files Browse the repository at this point in the history
…val_write_answer() for providing more hints when dryrun fails
  • Loading branch information
tvasilopo committed Jul 7, 2020
1 parent 08c5c9e commit a55a021
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions ripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import yaml


def ripe_create(db, pwd, json_output, key, type, dryrun):
def ripe_create(db, pwd, json_output, key, type, dryrun, object_entries):
"""
Create non-existing RIPE object
"""
Expand All @@ -23,7 +23,7 @@ def ripe_create(db, pwd, json_output, key, type, dryrun):
"Accept": "application/json; charset=utf-8"
}
r=requests.post(url, data=json_output, headers=headers)

#print (r.text)
eval_write_answer(r.status_code, r.text, dryrun)


Expand Down Expand Up @@ -161,9 +161,15 @@ def eval_write_answer(status_code, text, dryrun):
"""
if dryrun:
try:
print(" RIPE answer: %s" % json.loads(text)['errormessages']['errormessage'][0]['text'])
exists = json.loads(text)['errormessages']['errormessage'][0]['text']
except:
print(" RIPE answer: %s" % text)
else:
info = json.loads(text)['errormessages']['errormessage']
for item in info:
print (item['text'])
if 'args' in item:
print (item['args'][0]['value'])

else:
if status_code == 200:
Expand Down Expand Up @@ -256,7 +262,8 @@ def ripe_normalize(ripe_obj):
for key in yml_objects.keys():
type = yml_objects[key][0].keys()[0]
name = key
print(key)
print('')
print(type,key)
ripe_object = ripe_get(args.db, type, name, yml_objects[key])
answer = eval_search(ripe_object, type, name)
if answer == 0:
Expand All @@ -275,9 +282,9 @@ def ripe_normalize(ripe_obj):
ripe_update(args.db, pwd, json_output, key, type, args.dryrun, yml_objects[key])

if answer == 1:
print(" Object does not exists in the RIPE database")
print("Object does not exists in the RIPE database")
json_output = yaml_to_json(yml_objects[key])
ripe_create(args.db, pwd, json_output, key, type, args.dryrun)
ripe_create(args.db, pwd, json_output, key, type, args.dryrun, yml_objects[key])


if args.search:
Expand Down

0 comments on commit a55a021

Please sign in to comment.