Added get environment
This commit is contained in:
Binary file not shown.
33
main.py
33
main.py
@ -71,8 +71,30 @@ async def update_post(id: int, post: Post):
|
|||||||
my_posts[index] = post_dict
|
my_posts[index] = post_dict
|
||||||
return {"data": post_dict}
|
return {"data": post_dict}
|
||||||
|
|
||||||
|
@app.get("/create_env")
|
||||||
|
async def ping_host():
|
||||||
|
# send one packet of data to the host
|
||||||
|
# this is specified by '-c 1' in the argument list
|
||||||
|
outputlist = []
|
||||||
|
# Iterate over all the servers in the list and ping each server
|
||||||
|
# get the output as a string
|
||||||
|
#output = str(os.system(cmd))
|
||||||
|
#cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
||||||
|
cmd = subprocess.run(["cat","list"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
||||||
|
# store the output in the list
|
||||||
|
output = (f"{cmd.stdout}")
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/environment/{id}")
|
||||||
|
async def get_env(id: str):
|
||||||
|
#env = find_post(id)
|
||||||
|
cmd = subprocess.run(["cat list | grep %s" % id],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
|
if cmd.returncode != 0:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Post id {id} not found")
|
||||||
|
else:
|
||||||
|
return {"post_detail": cmd}
|
||||||
|
|
||||||
@app.get("/list")
|
@app.get("/list")
|
||||||
async def ping_host():
|
async def ping_host():
|
||||||
# send one packet of data to the host
|
# send one packet of data to the host
|
||||||
@ -81,7 +103,12 @@ async def ping_host():
|
|||||||
# Iterate over all the servers in the list and ping each server
|
# Iterate over all the servers in the list and ping each server
|
||||||
# get the output as a string
|
# get the output as a string
|
||||||
#output = str(os.system(cmd))
|
#output = str(os.system(cmd))
|
||||||
cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
#cmd = subprocess.run(["/bin/ls", "-al"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True)
|
||||||
|
cmd = subprocess.run(["cat list"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
|
#cmd = subprocess.run(["ls /usr/bin"],stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
# store the output in the list
|
# store the output in the list
|
||||||
output = (f"{cmd.stdout}")
|
#output = (f"{cmd.stdout}")
|
||||||
return output
|
#output1 = (f'{cmd.stdout.decode("utf-8")}')
|
||||||
|
output2 = (f'{cmd.stdout.decode("utf-8").lower()}')
|
||||||
|
print (output2)
|
||||||
|
return output2
|
||||||
Reference in New Issue
Block a user