azure_cdn: use subgroups, attempt 2
This commit is contained in:
parent
b59d334689
commit
95a39f759a
2 changed files with 18 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
@ -8,6 +9,20 @@ from app.terraform import BaseAutomation
|
||||||
|
|
||||||
|
|
||||||
class ProxyAutomation(BaseAutomation):
|
class ProxyAutomation(BaseAutomation):
|
||||||
|
def get_subgroups(self):
|
||||||
|
conn = db.engine.connect()
|
||||||
|
result = conn.execute("""
|
||||||
|
SELECT origin.group_id, proxy.psg, COUNT(proxy.id) FROM proxy, origin
|
||||||
|
WHERE proxy.origin_id = origin.id
|
||||||
|
AND proxy.destroyed IS NULL
|
||||||
|
AND proxy.provider = :provider
|
||||||
|
GROUP BY origin.group_id, proxy.psg;
|
||||||
|
""", provider=self.provider)
|
||||||
|
subgroups = defaultdict(lambda: defaultdict(lambda: 0))
|
||||||
|
for row in result:
|
||||||
|
subgroups[row[0]][row[1]] = row[2]
|
||||||
|
return subgroups
|
||||||
|
|
||||||
def create_missing_proxies(self):
|
def create_missing_proxies(self):
|
||||||
origins = Origin.query.all()
|
origins = Origin.query.all()
|
||||||
for origin in origins:
|
for origin in origins:
|
||||||
|
@ -44,6 +59,7 @@ class ProxyAutomation(BaseAutomation):
|
||||||
Proxy.provider == self.provider,
|
Proxy.provider == self.provider,
|
||||||
Proxy.destroyed == None
|
Proxy.destroyed == None
|
||||||
).all(),
|
).all(),
|
||||||
|
subgroups = self.get_subgroups(),
|
||||||
global_namespace=app.config['GLOBAL_NAMESPACE'],
|
global_namespace=app.config['GLOBAL_NAMESPACE'],
|
||||||
bypass_token=app.config['BYPASS_TOKEN'],
|
bypass_token=app.config['BYPASS_TOKEN'],
|
||||||
**{
|
**{
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
from azure.identity import ClientSecretCredential
|
from azure.identity import ClientSecretCredential
|
||||||
from azure.mgmt.alertsmanagement import AlertsManagementClient
|
from azure.mgmt.alertsmanagement import AlertsManagementClient
|
||||||
|
@ -11,7 +10,7 @@ from app import app
|
||||||
from app.alarms import get_proxy_alarm
|
from app.alarms import get_proxy_alarm
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.models.base import Group
|
from app.models.base import Group
|
||||||
from app.models.mirrors import Proxy, Origin
|
from app.models.mirrors import Proxy
|
||||||
from app.models.alarms import AlarmState
|
from app.models.alarms import AlarmState
|
||||||
from app.terraform.proxy import ProxyAutomation
|
from app.terraform.proxy import ProxyAutomation
|
||||||
|
|
||||||
|
@ -168,23 +167,9 @@ class ProxyAzureCdnAutomation(ProxyAutomation):
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_subgroup_counts(self):
|
|
||||||
conn = db.engine.connect()
|
|
||||||
result = conn.execute("""
|
|
||||||
SELECT origin.group_id, proxy.psg, COUNT(proxy.id) FROM proxy, origin
|
|
||||||
WHERE proxy.origin_id = origin.id
|
|
||||||
AND proxy.destroyed IS NULL
|
|
||||||
AND proxy.provider = 'azure_cdn'
|
|
||||||
GROUP BY origin.group_id, proxy.psg;
|
|
||||||
""")
|
|
||||||
subgroups = defaultdict(lambda: defaultdict(lambda: 0))
|
|
||||||
for row in result:
|
|
||||||
subgroups[row[0]][row[1]] = row[2]
|
|
||||||
return subgroups
|
|
||||||
|
|
||||||
def create_missing_proxies(self):
|
def create_missing_proxies(self):
|
||||||
groups = Group.query.all()
|
groups = Group.query.all()
|
||||||
subgroups = self.get_subgroup_counts()
|
subgroups = self.get_subgroups()
|
||||||
for group in groups:
|
for group in groups:
|
||||||
subgroup = 0
|
subgroup = 0
|
||||||
for origin in group.origins:
|
for origin in group.origins:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue