Skip to content

Commit

Permalink
Fixed egi auth pipe. Added apricot_info
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanch3z_Sama committed Jul 23, 2024
1 parent 84161bf commit b1f7c87
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/apricot_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_auth_pipe(self, infrastructure_id):
elif found_infrastructure['type'] == "EC2":
auth_content += f"id = {found_infrastructure['id']}; type = {found_infrastructure['type']}; username = {found_infrastructure['user']}; password = {found_infrastructure['pass']}"
elif found_infrastructure['type'] == "EGI":
auth_content += f"id = {found_infrastructure['id']}; type = {found_infrastructure['type']}; host = {found_infrastructure['host']}; vo = {found_infrastructure['vo']}; token = {found_infrastructure['EGITokan']}"
auth_content += f"id = {found_infrastructure['id']}; type = {found_infrastructure['type']}; host = {found_infrastructure['host']}; vo = {found_infrastructure['vo']}; token = {found_infrastructure['EGIToken']}"
# Write auth-pipe content to a file
with open('auth-pipe', 'w') as auth_file:
auth_file.write(auth_content)
Expand Down Expand Up @@ -236,6 +236,49 @@ def apricot_ls(self, line):

return

@line_magic
def apricot_info(self, line):
if len(line) == 0:
print("Usage: apricot_info infrastructure-id\n")
return "Fail"

# Split the input line to extract the infrastructure ID
inf_id = line.split()[0]

try:
# Create auth-pipe for the specified infrastructure
self.create_auth_pipe(inf_id)
except ValueError as e:
print(e)
return "Failed"

# Construct the command to retrieve log messages
cmd_getinfo = [
"python3",
"/usr/local/bin/im_client.py",
"getinfo",
inf_id,
"-a",
"auth-pipe",
"-r",
"https://im.egi.eu/im",
]

try:
# Run the command, capturing stdout and stderr
result = run(cmd_getinfo, stdout=PIPE, stderr=PIPE, check=True, text=True)
print(result.stdout)
except CalledProcessError as e:
# Handle errors raised by the command
print("Status: fail " + str(e.returncode) + "\n")
print(e.stderr + "\n")
print(e.stdout)
return "Fail"
finally:
# Clean up auth-pipe file
if os.path.exists('auth-pipe'):
os.remove('auth-pipe')

@line_magic
def apricot_vmls(self, line):
if len(line) == 0:
Expand Down Expand Up @@ -551,8 +594,6 @@ def apricot(self, code, cell=None):

return "Done"



def load_ipython_extension(ipython):
"""
Any module file that define a function named `load_ipython_extension`
Expand Down

0 comments on commit b1f7c87

Please sign in to comment.