add remove self instance
parent
eac4b20b62
commit
08d5840c71
15
README.md
15
README.md
|
|
@ -1,11 +1,18 @@
|
||||||
|
|
||||||
|
sudo su
|
||||||
|
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install python3-dev python3-venv
|
add-apt-repository ppa:deadsnakes/ppa
|
||||||
|
|
||||||
python3 -m venv .venv
|
apt-get install python3.13-dev python3.13-venv
|
||||||
|
|
||||||
source ./venv/bin/activate
|
cd /ADO2VMCrawler
|
||||||
|
|
||||||
pip install -r requirements
|
python3.13 -m venv .venv
|
||||||
|
|
||||||
|
source ./.venv/bin/activate
|
||||||
|
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
playwright install-deps
|
playwright install-deps
|
||||||
playwright install
|
playwright install
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
from azure.identity import DefaultAzureCredential
|
||||||
|
from azure.mgmt.compute import ComputeManagementClient
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
import azure.mgmt.compute as compute
|
||||||
|
import uuid
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
#subscription_id = instance_metadata['compute']['subscription_id']
|
||||||
|
|
||||||
|
|
||||||
|
def delete_self_instance():
|
||||||
|
instance_metadata = requests.get("http://169.254.169.254/metadata/instance?api-version=2025-04-07&format=json", headers={"Metadata":"True"}).json()
|
||||||
|
instance_resource_id = instance_metadata['compute']['resourceId']
|
||||||
|
parts = instance_resource_id.split('/')
|
||||||
|
subscription_id = parts[2]
|
||||||
|
resource_group = parts[4]
|
||||||
|
vm_name = parts[8]
|
||||||
|
if vm_name == "ado2-crawler-dev":
|
||||||
|
print("This is dev, don't die")
|
||||||
|
return False
|
||||||
|
|
||||||
|
credential = DefaultAzureCredential()
|
||||||
|
compute_client = ComputeManagementClient(credential, subscription_id)
|
||||||
|
compute_client.virtual_machines.begin_delete(resource_group, vm_name)
|
||||||
|
print("Kill this instance")
|
||||||
|
return True
|
||||||
|
|
||||||
|
delete_self_instance()
|
||||||
8
main.py
8
main.py
|
|
@ -1,8 +1,10 @@
|
||||||
|
import os, json
|
||||||
|
import asyncio
|
||||||
import playwright
|
import playwright
|
||||||
from playwright.async_api import async_playwright
|
from playwright.async_api import async_playwright
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
HOME_PATH = "/home/azureuser"
|
||||||
async def playwright_test():
|
async def playwright_test():
|
||||||
async with async_playwright() as p:
|
async with async_playwright() as p:
|
||||||
browser = await p.chromium.launch()
|
browser = await p.chromium.launch()
|
||||||
|
|
@ -14,3 +16,7 @@ async def playwright_test():
|
||||||
|
|
||||||
|
|
||||||
asyncio.run(playwright_test())
|
asyncio.run(playwright_test())
|
||||||
|
|
||||||
|
if __name__=="__main__":
|
||||||
|
with open(os.path.join(HOME_PATH, "success.txt"), "w") as fp:
|
||||||
|
json.dump("", fp)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,5 @@
|
||||||
playwright
|
playwright
|
||||||
dotenv
|
dotenv
|
||||||
|
azure-identity
|
||||||
|
azure-mgmt-resource
|
||||||
|
azure-mgmt-compute
|
||||||
Loading…
Reference in New Issue