Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing ripe_create() on issue #1 #2

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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