-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaim.py
More file actions
91 lines (77 loc) · 2.82 KB
/
claim.py
File metadata and controls
91 lines (77 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import oci
import time
import requests
# --- Settings OCI ---
CONFIG_PROFILE = "DEFAULT"
COMPARTMENT_ID = "ocid1.compartment.oc1..aaaaaaa..."
SUBNET_ID = "ocid1.subnet.oc1.eu-frankfurt-1..."
IMAGE_ID = "ocid1.image.oc1.eu-frankfurt-1..."
SSH_PUBLIC_KEY = "ssh-rsa AAAAB3..."
# --- Settings TELEGRAM ---
TELEGRAM_TOKEN = "bot_token"
TELEGRAM_CHAT_ID = "chat_id"
AD_NAMES = [
"qrHR:EU-FRANKFURT-1-AD-1",
"qrHR:EU-FRANKFURT-1-AD-2",
"qrHR:EU-FRANKFURT-1-AD-3"
]
SHAPE = "VM.Standard.A1.Flex"
SHAPE_CONFIG = {"ocpus": 4, "memory_in_gbs": 24}
def send_telegram_msg(message):
"""Send messages in the Telegram"""
url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"
payload = {"chat_id": TELEGRAM_CHAT_ID, "text": message, "parse_mode": "HTML"}
try:
requests.post(url, json=payload)
except Exception as e:
print(f"Error send messages in Telegram: {e}")
def create_instance(compute_client, ad_name):
print(f"[*] Try crea in {ad_name}...")
launch_details = oci.core.models.LaunchInstanceDetails(
compartment_id=COMPARTMENT_ID,
availability_domain=ad_name,
shape=SHAPE,
shape_config=oci.core.models.LaunchInstanceShapeConfigDetails(**SHAPE_CONFIG),
display_name="Auto-ARM-Instance",
image_id=IMAGE_ID,
create_vnic_details=oci.core.models.CreateVnicDetails(subnet_id=SUBNET_ID),
metadata={"ssh_authorized_keys": SSH_PUBLIC_KEY}
)
try:
response = compute_client.launch_instance(launch_details)
success_msg = f"✅ <b>Succes</b>\nInstans creation in Fra!\nAD: {ad_name}\nID: <code>{response.data.id}</code>"
print(f"[!] {success_msg}")
send_telegram_msg(success_msg)
return True
except oci.exceptions.ServiceError as e:
# Error 500 Out of capacity
if e.status == 500 or "Out of capacity" in e.message:
print(f"[-] No servers in {ad_name}")
elif e.status == 429:
print("[-] Too many request. Pause 30s...")
time.sleep(30)
else:
print(f"[!] Error API: {e.message}")
return False
def main():
# Check requests for Telegram
try:
import requests
except ImportError:
print("Error: install requests (pip install requests)")
return
config = oci.config.from_file(profile_name=CONFIG_PROFILE)
compute_client = oci.core.ComputeClient(config)
print("🚀 Script run. Relax, wait the msg in Telegram.")
send_telegram_msg("🤖 Script search ARM-instans runn!")
attempt = 1
while True:
for ad in AD_NAMES:
if create_instance(compute_client, ad):
return
time.sleep(2)
# Checeker time (60 sec)
time.sleep(60)
attempt += 1
if __name__ == "__main__":
main()