Exemple #1
0
 def __iterate_instances(self, index, parent, json_instances):
     for j_instance in json_instances:
         for i in range(j_instance['instances']):
             self.__increase_counter()
             ins = Instance(self.counter, j_instance, parent)
             ins.set_canonical_uris(
                 self.uf.create_canonical_instance(ins))  # Aquí
             if ins.className not in self.classes:
                 self.classes[
                     ins.className] = self.uf.create_canonical_entity(
                         ins.className)
             for p in ins.properties:
                 if p not in self.properties:
                     self.properties[p] = self.uf.create_canonical_property(
                         p)
             self.instances.append(ins)
             self.instancesMap[ins.id] = ins
             # print(ins)
             if parent is not None:
                 parent.add_child(ins)
             if 'child' in j_instance:
                 self.__iterate_instances(self.counter, ins,
                                          j_instance['child'])
Exemple #2
0
def query_instance(client, host):

    if Helper.is_an_ip_address(host):
        filters = [Const.require_filter_template_ip(host)]
    else:
        filters = [Const.require_filter_template_hostname(host)]

    response = client.describe_instances(Filters=filters)

    # Retrieve instances
    for r in response['Reservations']:

        for i in r['Instances']:

            return Instance.load(i)

    # Raise exception if an instance not found
    raise Exception(
        Const.EXCEPTION_NOT_FOUND_INSTANCE.format(filters[0]['Values'][0]))
Exemple #3
0
from server.aws import (get_instances_details, get_all_regions,
                        get_untagged_instances, attach_tag_to_instances,
                        get_instances_daily_cost, get_instances_monthly_cost)
from models.instance import Instance
from models.ssh_keys import SSHKeys
from models.user import User, BlacklistToken
from models.cost_explorer import CostExplorer
from settings import db

admin_bp = Blueprint('admin', __name__, url_prefix='/admin')
region_name = os.getenv('REGION_NAME')

# creating user obj
user_obj = User()
instance_obj = Instance()
ssh_key_obj = SSHKeys()
ce_obj = CostExplorer()


@admin_bp.route('/instances', methods=['GET'])
def get_admin():
    update_thread = threading.Thread(target=make_aws_call, args=())
    update_thread.start()
    return get_instances()


@admin_bp.route('/ssh-keys')
def get_ssh_keys():
    keys_list, all_keys_list = ssh_key_obj.get_ssh_keys_from_db()
    return render_template('ssh-keys.html',
Exemple #4
0
import os
import sys

sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
from models.instance import Instance
from settings import db
from sqlalchemy import func
from datetime import datetime, timedelta
from sqlalchemy.schema import PrimaryKeyConstraint


ins_obj = Instance()


class CostExplorer(db.Model):
    __tablename__ = 'cost_explorer'

    ce_instance_id = db.Column(db.String())
    ce_date = db.Column(db.String(), nullable=True)
    ce_instance_name = db.Column(db.String(), nullable=True)
    ce_month = db.Column(db.String())
    ce_instance_daily_bill = db.Column(db.Float())
    __table_args__ = (
        PrimaryKeyConstraint('ce_instance_id', 'ce_date'),
        {},
    )

    def add_daily_bill(self, instance_id, current_month, today_date, daily_bill):
        ids = ins_obj.get_instances_ids()
        if instance_id in ids:
            self.ce_instance_id = instance_id