最初版本
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
import paramiko
|
||||
|
||||
pw = os.environ["DEPLOY_PASSWORD"]
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect("20.191.152.26", username="wakka", password=pw, timeout=30)
|
||||
|
||||
script = r"""
|
||||
python3 <<'PY'
|
||||
import json, urllib.request
|
||||
|
||||
def meta(path):
|
||||
req = urllib.request.Request(
|
||||
f"http://169.254.169.254{path}",
|
||||
headers={"Metadata": "true"},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=5) as r:
|
||||
return r.read().decode()
|
||||
|
||||
try:
|
||||
tok = json.loads(meta(
|
||||
"/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F"
|
||||
))
|
||||
print("MI_TOKEN", "yes" if tok.get("access_token") else "no")
|
||||
except Exception as e:
|
||||
print("MI_TOKEN", "no", e)
|
||||
|
||||
inst = json.loads(meta("/metadata/instance?api-version=2021-02-01"))
|
||||
comp = inst["compute"]
|
||||
net = inst["network"]["interface"][0]
|
||||
print("VM", comp["name"])
|
||||
print("RG", comp["resourceGroupName"])
|
||||
print("LOC", comp["location"])
|
||||
print("PUBIP", net["ipv4"]["ipAddress"][0].get("publicIpAddress", ""))
|
||||
PY
|
||||
curl -sI http://127.0.0.1:7777/guest-customer-service | grep -i server
|
||||
"""
|
||||
|
||||
_, o, e = c.exec_command(script, timeout=30)
|
||||
print(o.read().decode())
|
||||
print(e.read().decode())
|
||||
c.close()
|
||||
Reference in New Issue
Block a user