@@ -15,7 +15,7 @@ class Instance:
15
15
_id : str
16
16
name : str
17
17
hostname : str
18
- _type : str
18
+ instance_type : str
19
19
health : bool
20
20
env : Any
21
21
apiCaller : ApiCaller
@@ -25,17 +25,19 @@ def __init__(
25
25
_id : str ,
26
26
name : str ,
27
27
hostname : str ,
28
- _type : str ,
28
+ instance_type : str ,
29
29
status : str ,
30
30
data : Any = None ,
31
31
apiCaller : Optional [ApiCaller ] = None ,
32
32
) -> None :
33
33
self ._id = _id
34
34
self .name = name
35
35
self .hostname = hostname
36
- self ._type = _type
36
+ self .instance_type = instance_type
37
37
self .health = status == "up" and (
38
- (data .attrs ["State" ]["Health" ]["Status" ] == "healthy" if "Health" in data .attrs ["State" ] else False ) if _type == "container" and data else True
38
+ (data .attrs ["State" ]["Health" ]["Status" ] == "healthy" if "Health" in data .attrs ["State" ] else False )
39
+ if instance_type == "container" and data
40
+ else True
39
41
)
40
42
self .env = data
41
43
self .apiCaller = apiCaller or ApiCaller ()
@@ -45,7 +47,7 @@ def id(self) -> str:
45
47
return self ._id
46
48
47
49
def reload (self ) -> bool :
48
- if self ._type == "local" :
50
+ if self .instance_type == "local" :
49
51
return (
50
52
run (
51
53
[join (sep , "usr" , "sbin" , "nginx" ), "-s" , "reload" ],
@@ -59,7 +61,7 @@ def reload(self) -> bool:
59
61
return self .apiCaller .send_to_apis ("POST" , "/reload" )
60
62
61
63
def start (self ) -> bool :
62
- if self ._type == "local" :
64
+ if self .instance_type == "local" :
63
65
return (
64
66
run (
65
67
[join (sep , "usr" , "sbin" , "nginx" ), "-e" , "/var/log/bunkerweb/error.log" ],
@@ -73,7 +75,7 @@ def start(self) -> bool:
73
75
return self .apiCaller .send_to_apis ("POST" , "/start" )
74
76
75
77
def stop (self ) -> bool :
76
- if self ._type == "local" :
78
+ if self .instance_type == "local" :
77
79
return (
78
80
run (
79
81
[join (sep , "usr" , "sbin" , "nginx" ), "-s" , "stop" ],
@@ -87,7 +89,7 @@ def stop(self) -> bool:
87
89
return self .apiCaller .send_to_apis ("POST" , "/stop" )
88
90
89
91
def restart (self ) -> bool :
90
- if self ._type == "local" :
92
+ if self .instance_type == "local" :
91
93
proc = run (
92
94
[join (sep , "usr" , "sbin" , "nginx" ), "-s" , "stop" ],
93
95
stdin = DEVNULL ,
@@ -368,7 +370,9 @@ def get_bans(self, _id: Optional[int] = None) -> List[dict[str, Any]]:
368
370
return []
369
371
if not resp :
370
372
return []
371
- return instance_bans [instance .name if instance .name != "local" else "127.0.0.1" ].get ("data" , [])
373
+ return instance_bans [(instance .name if instance .instance_type != "pod" else instance .hostname ) if instance .name != "local" else "127.0.0.1" ].get (
374
+ "data" , []
375
+ )
372
376
373
377
bans : List [dict [str , Any ]] = []
374
378
for instance in self .get_instances ():
@@ -378,7 +382,11 @@ def get_bans(self, _id: Optional[int] = None) -> List[dict[str, Any]]:
378
382
continue
379
383
if not resp :
380
384
continue
381
- bans .extend (instance_bans [instance .name if instance .name != "local" else "127.0.0.1" ].get ("data" , []))
385
+ bans .extend (
386
+ instance_bans [(instance .name if instance .instance_type != "pod" else instance .hostname ) if instance .name != "local" else "127.0.0.1" ].get (
387
+ "data" , []
388
+ )
389
+ )
382
390
383
391
bans .sort (key = itemgetter ("exp" ))
384
392
@@ -425,7 +433,12 @@ def get_reports(self, _id: Optional[int] = None) -> List[dict[str, Any]]:
425
433
return []
426
434
if not resp :
427
435
return []
428
- return (instance_reports [instance .name if instance .name != "local" else "127.0.0.1" ].get ("msg" ) or {"requests" : []})["requests" ]
436
+ return (
437
+ instance_reports [(instance .name if instance .instance_type != "pod" else instance .hostname ) if instance .name != "local" else "127.0.0.1" ].get (
438
+ "msg"
439
+ )
440
+ or {"requests" : []}
441
+ )["requests" ]
429
442
430
443
reports : List [dict [str , Any ]] = []
431
444
for instance in self .get_instances ():
@@ -436,7 +449,14 @@ def get_reports(self, _id: Optional[int] = None) -> List[dict[str, Any]]:
436
449
437
450
if not resp :
438
451
continue
439
- reports .extend ((instance_reports [instance .name if instance .name != "local" else "127.0.0.1" ].get ("msg" ) or {"requests" : []})["requests" ])
452
+ reports .extend (
453
+ (
454
+ instance_reports [
455
+ (instance .name if instance .instance_type != "pod" else instance .hostname ) if instance .name != "local" else "127.0.0.1"
456
+ ].get ("msg" )
457
+ or {"requests" : []}
458
+ )["requests" ]
459
+ )
440
460
441
461
reports .sort (key = itemgetter ("date" ), reverse = True )
442
462
@@ -446,7 +466,7 @@ def get_metrics(self, plugin_id: str):
446
466
# Get metrics from all instances
447
467
metrics = {}
448
468
for instance in self .get_instances ():
449
- instance_name = instance .name if instance .name != "local" else "127.0.0.1"
469
+ instance_name = ( instance .name if instance . instance_type != "pod" else instance . hostname ) if instance .name != "local" else "127.0.0.1"
450
470
451
471
try :
452
472
if plugin_id == "redis" :
@@ -505,7 +525,7 @@ def get_ping(self, plugin_id: str):
505
525
# Need at least one instance to get a success ping to return success
506
526
ping = {"status" : "error" }
507
527
for instance in self .get_instances ():
508
- instance_name = instance .name if instance .name != "local" else "127.0.0.1"
528
+ instance_name = ( instance .name if instance . instance_type != "pod" else instance . hostname ) if instance .name != "local" else "127.0.0.1"
509
529
510
530
try :
511
531
resp , ping_data = instance .ping (plugin_id )
@@ -527,7 +547,7 @@ def get_data(self, plugin_endpoint: str):
527
547
data = []
528
548
for instance in self .get_instances ():
529
549
530
- instance_name = instance .name if instance .name != "local" else "127.0.0.1"
550
+ instance_name = ( instance .name if instance . instance_type != "pod" else instance . hostname ) if instance .name != "local" else "127.0.0.1"
531
551
532
552
try :
533
553
resp , instance_data = instance .data (plugin_endpoint )
0 commit comments