Starting reconciler
This commit is contained in:
parent
df186e7d62
commit
ccc7e527f6
@ -99,6 +99,23 @@ class InstanceDeletes(models.Model):
|
||||
raw = models.ForeignKey(RawData, null=True)
|
||||
|
||||
|
||||
class InstanceReconcile(models.Model):
|
||||
row_created = models.DateTimeField(auto_now_add=True)
|
||||
row_updated = models.DateTimeField(auto_now=True)
|
||||
instance = models.CharField(max_length=50, null=True,
|
||||
blank=True, db_index=True)
|
||||
launched_at = models.DecimalField(null=True, max_digits=20,
|
||||
decimal_places=6, db_index=True)
|
||||
deleted_at = models.DecimalField(null=True, max_digits=20,
|
||||
decimal_places=6, db_index=True)
|
||||
instance_type_id = models.CharField(max_length=50,
|
||||
null=True,
|
||||
blank=True,
|
||||
db_index=True)
|
||||
source = models.CharField(max_length=150, null=True,
|
||||
blank=True, db_index=True)
|
||||
|
||||
|
||||
class InstanceExists(models.Model):
|
||||
PENDING = 'pending'
|
||||
VERIFYING = 'verifying'
|
||||
|
67
stacktach/reconciler.py
Normal file
67
stacktach/reconciler.py
Normal file
@ -0,0 +1,67 @@
|
||||
from novaclient.v1_1 import client
|
||||
|
||||
from stacktach import models
|
||||
|
||||
reconciler_config = {
|
||||
'nova':{
|
||||
'DFW':{
|
||||
'username': 'm0lt3n',
|
||||
'project_id': '724740',
|
||||
'api_key': '',
|
||||
'auth_url': 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
'auth_system': 'rackspace',
|
||||
},
|
||||
'ORD':{
|
||||
'username': 'm0lt3n',
|
||||
'project_id': '724740',
|
||||
'api_key': '',
|
||||
'auth_url': 'https://identity.api.rackspacecloud.com/v2.0',
|
||||
'auth_system': 'rackspace',
|
||||
},
|
||||
|
||||
},
|
||||
'region_mapping_loc': '/etc/stacktach/region_mapping.json'
|
||||
}
|
||||
|
||||
region_mapping = {
|
||||
'x': 'DFW'
|
||||
}
|
||||
|
||||
|
||||
class Reconciler(object):
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = reconciler_config
|
||||
self.region_mapping = region_mapping
|
||||
self.nova_clients = {}
|
||||
|
||||
def _get_nova(self, region):
|
||||
if region in self.nova_clients:
|
||||
return self.nova_clients[region]
|
||||
|
||||
region_cfg = self.config['nova'][region]
|
||||
region_auth_system = region_cfg.get('auth_system', 'keystone')
|
||||
|
||||
nova = client.Client(region_cfg['username'], region_cfg['api_key'],
|
||||
region_cfg['project_id'],
|
||||
auth_url=region_cfg['auth_url'],
|
||||
auth_system=region_auth_system)
|
||||
|
||||
self.nova_clients[region] = nova
|
||||
return nova
|
||||
|
||||
def _region_for_launch(self, launch):
|
||||
request = launch.request_id
|
||||
raws = models.RawData.objects.filter(request_id=request)
|
||||
if raws.count() == 0:
|
||||
return False
|
||||
raw = raws[0]
|
||||
return self.region_mapping[str(raw.deployment.name)]
|
||||
|
||||
def missing_exists_for_instance(self, launched_id,
|
||||
period_beginning,
|
||||
period_ending):
|
||||
launch = models.InstanceUsage.objects.get(id=launched_id)
|
||||
region = self._region_for_launch(launch)
|
||||
nova = self._get_nova(region)
|
||||
server = nova.servers.get(launch.instance)
|
Loading…
x
Reference in New Issue
Block a user