예제 #1
0
def lb(resource_id):
    item = db.get_item(models.LoadBalancer, resource_id=resource_id)
    for sg in item.get('security_groups', []):
        sg['ingress_rules'] = db.get_item(
            models.SecurityGroup,
            resource_id=sg['resource_id'])['ingress_rules']
    return item
예제 #2
0
def instance(resource_id):
    item = db.get_item(models.Instance, resource_id=resource_id)
    # for all the interfaces get the security group rules
    for intf in item['network_interfaces']:
        for sg in intf['security_groups']:
            sg_details = db.get_item(models.SecurityGroup, resource_id=sg['resource_id'])
            sg['ingress_rules'] = sg_details['ingress_rules']
            sg['egress_rules'] = sg_details['egress_rules']
    return item
예제 #3
0
def attacktheboss():
    data = request.json
    api_key = data["key"]
    valid = db.confirm_key(api_key)
    if (valid) :
        useremail = data["email"]
        user_inventory = json.loads(db.get_userinventory(useremail, api_key))
        user = json.loads(db.get_user(useremail))
        itemname = ""
        if(user_inventory["pulverizinglaser"]['value'] == "True") :
            itemname = "pulverizing laser"
        elif(user_inventory["meltinglaser"]['value'] == "True") :
            itemname = "melting laser"
        elif(user_inventory["damaginglaser"]['value'] == "True") :
            itemname = "damaging laser"
        totaldamage = 0
        if(itemname != "") :
            iteminfo = json.loads(db.get_item(itemname))
            totaldamage = int(user["curdmg"] + iteminfo["dmginc"])
        else :
            totaldamage = int(user["curdmg"])
        currentboss["currenthealth"] -= totaldamage
        db.give_money(useremail, 10000, api_key)
        return jsonify({"health" : currentboss["health"], "currenthealth" : currentboss["currenthealth"], "name": currentboss["name"], "balance" : 10000}), 200
    else :
        return jsonify({"message" : "no key provided"}), 400
예제 #4
0
파일: main.py 프로젝트: Oruche/RecoReco
def train(intelligence_id):
    # intelligence_idに対応するモデルをDBから検索
    item = db.get_item(intelligence_id)

    # モデルをストレージからダウンロード
    filename = './model_tmp/downloads/' + item.modelkey
    storage.download_model(filename, item.modelkey)


    # 学習ハイパーパラメータをロード
    # 画像をダウンロード
    #train_image, train_label = data.load_mock_image()
    train_image, train_label = train_data.prepare(labels=item.labels,
                                                  count=item.data_counts,
                                                  image_size=item.image_size,
                                                  color=item.color,
                                                  shuffle=True,
                                                  flatten=True)

    # train
    savename = './model_tmp/saved/' + item.modelkey
    training.execute_train(train_image, train_label, item, loadname=filename, savename=savename)

    # ストレージに保存
    storage.save_model(savename, item.modelkey)

    # DBに保存
    db.put_item(item)
예제 #5
0
def get_network_interfaces(rsp_interfaces_list):
    interfaces = []
    for intf in rsp_interfaces_list:
        subnet_details = db.get_item(models.Subnet,
                                     resource_id=intf['SubnetId'])
        sg_info = []
        for sg in intf['Groups']:
            sg_info.append({
                'name': sg['GroupName'],
                'resource_id': sg['GroupId']
            })
        interfaces.append({
            'resource_id':
            intf['NetworkInterfaceId'],
            'mac':
            intf['MacAddress'],
            'private_ip':
            intf['PrivateIpAddress'],
            'public_ip':
            intf.get('Association', {}).get('PublicIp', ''),
            'subnet': {
                'resource_id': intf['SubnetId'],
                'name': subnet_details.get('name', '')
            },
            'src_dst_check':
            intf['SourceDestCheck'],
            'security_groups':
            sg_info,
        })
    return interfaces
예제 #6
0
def validate_tag():
	"""keep reading for nfc tag item, validate, send it back to the ui"""
	# set add_tag to True to keep reading from tag
	global add_tag
	add_tag = True

	while add_tag:
		try:
			# check for a tag reading
			# FIXME - sim
			tag = tag_reader.sim_read()

			# check if the item exists in the database
			item = db.get_item(tag)
			resp = {
				'index': item.get('index'),
				'name': item.get('name'),
				'tag': tag,
				'description': item.get('description'),
				'cost': item.get('cost')
			}
			# send a response back to the ui client on `cart_response` channel
			socketio.emit('cart_response', resp, namespace='/cart')
		except Exception as e:
			# if a reading fails, we can't really do anything other than passing
			# this and letting the customer tap the card again
			pass
		else:
			pass
		finally:
			pass
예제 #7
0
def tgw_attachment(resource_id):
    item = db.get_item(models.TgwAttachment, resource_id=resource_id)
    # get the routes for the route table if any
    rtable = item.get('route_table_id', None)
    if not rtable:
        return item
    routes = aws_resources.tgw_attachment.get_tgw_routes(
        item['region'], item['account_id'], rtable)
    item['tgw_routes'] = routes
    vpc_side_routes = {}
    for subnet in item['subnets']:
        routes = db.get_item(models.RouteTable,
                             region=item['region'],
                             resource_id=subnet['route_table_id'])
        vpc_side_routes[subnet['name']] = routes['routes']
    item['vpc_routes'] = vpc_side_routes
    return item
예제 #8
0
def getcooldown():
    data = request.json
    api_key = data["key"]
    valid = db.confirm_key(api_key)
    if(valid) :
        email = data["email"]
        user = json.loads(db.get_user(email))
        uid = user['id']
        a = json.loads(db.get_userinventory(uid))
        if(a.liquidnitrogen) :
            b = json.loads(db.get_item("liquid nitrogen"))
            return b['cooldowntime']
        elif(a.watercooling) :
            b = json.loads(db.get_item("water cooling"))
            return b['cooldowntime']
        elif(a.icepack) :
            b = json.loads(db.get_item("ice pack"))
            return b['cooldowntime']
def delete_item():
    item_id = int(input("Item ID: "))
    item = db.get_item(item_id)
    choice = input("Are you sure you want to delete '" + 
                   item.name + "'? (y/n): ")
    if choice == "y":
        db.delete_item(item_id)
        print("'" + item.name + "' was deleted from database.\n")
    else:
        print("'" + item.name + "' was NOT deleted from database.\n")        
예제 #10
0
def cancel_the_job():
    with db.lock('the_job_lock'):
        scheduled = get_item('the_job')
        logger.info('Trying to cancel job {}'.format(scheduled))
        logger.info('All jobs {}'.format(scheduler.get_jobs()))
        if scheduled in scheduler:
            logger.info('Calling scheduler.cancel()')
            scheduler.cancel(scheduled)
        else:
            logger.info('Unable to find job to cancel')
    logger.info('Released lock after cancelling')
예제 #11
0
파일: job.py 프로젝트: lola-end-alz/minder
def cancel_the_job():
    with db.lock('the_job_lock'):
        scheduled = get_item('the_job')
        logger.info('Trying to cancel job {}'.format(scheduled))
        logger.info('All jobs {}'.format(scheduler.get_jobs()))
        if scheduled in scheduler:
            logger.info('Calling scheduler.cancel()')
            scheduler.cancel(scheduled)
        else:
            logger.info('Unable to find job to cancel')
    logger.info('Released lock after cancelling')
예제 #12
0
def unload_item(item_id):
    print("Выгрузка товара с id ", item_id, '!')
    # Собираем нужные нам данные из БД
    item = db.get_item(item_id)
    stowage = db.get_stowage(item[0].stowage_id)
    destination = stowage[0].json
    # Сообщаем манипулятору о желании выгрузить товар
    res = manipulator.unload(destination)
    # Если манипулятор ответил ОК, отмечаем выдачу у себя в БД
    if res['status'] == "ok":
        print("Выгрузка успешна")
        db.unload_item_from_stowage(item_id)
    else:
        print("Выгрузка прошла с ошибками!")
예제 #13
0
파일: app.py 프로젝트: lola-end-alz/minder
def minder():
    data = json.loads(request.data)
    logger.info(data)

    try:
        launch, toggle, item, question = _parse_request(data['request'])
        if launch:
            speech_output = 'welcome to minder! what can i do for you today?'
            card_output = 'user launched minder'
            reprompt_message = 'what can i do for you today?'
            response = _get_echo_response(speech_output,
                                          card_output,
                                          reprompt_message,
                                          end_session=False)
        else:
            if question:
                saved_toggle = get_item(item)
                if not saved_toggle:
                    saved_toggle = 'off'
                speech_output = 'hello, the {} is {}'.format(
                    item, saved_toggle)
                card_output = 'user asked if {} is {}. we responded with {}'.format(
                    item, saved_toggle, speech_output)
                reprompt_message = ''
            else:
                speech_output = 'you\'ve turned {} the {}'.format(toggle, item)
                card_output = 'user turned {} the {}'.format(toggle, item)
                reprompt_message = ''

                if toggle == 'on':
                    schedule_the_job(item)

                if toggle == 'off':
                    logger.info('Attempting to cancel job')
                    cancel_the_job()

                set_item(item, toggle)
                send_sms(Config.PROVIDER_PHONE_NUMBER, card_output)

            response = _get_echo_response(speech_output, card_output,
                                          reprompt_message)
    except Exception as e:
        logger.error(e)
        speech_output = 'sorry, i didn\'t understand that. please try again'
        card_output = 'couldn\'t understand command from user'
        reprompt_message = 'reprompt message. how does this work?'
        response = _get_echo_response(speech_output, card_output,
                                      reprompt_message)

    return jsonify(response)
예제 #14
0
def sync(account_number, region, vpc_id='', security_group_id=''):
    cur_date = datetime.datetime.utcnow()
    client, account_id = get_boto3_resource('ec2', region,
                                            account_number=account_number)
    logging.info('Syncing Security Groups %s %s %s',
                 account_id, region, vpc_id)
    query = []
    if vpc_id:
        query.append({'Name': 'vpc-id', 'Values': [vpc_id]})
    if security_group_id:
        query.append({'Name': 'group-id', 'Values': [security_group_id]})
    added = 0
    for page in client.get_paginator('describe_security_groups').paginate(Filters=query):
        logging.info('Got page with item count %s',
                     len(page['SecurityGroups']))
        page_items = []
        for item in page['SecurityGroups']:
            if 'Tags' not in item:
                item['Tags'] = []
            info = {
                'date_added': cur_date,
                'region': region,
                'account_id': item['OwnerId'],
                'resource_id': item['GroupId'],
                'name': item['GroupName'],
                'tags': normalize_tags_list(item['Tags']),
                'vpc_id': item['VpcId'],
                'vpc_name': db.get_item(models.Vpc, resource_id=item['VpcId'])['name'],
                'ingress_rules': get_rules(item['IpPermissions'], "source"),
                'egress_rules': get_rules(item['IpPermissionsEgress'], "destination"),
            }
            add_tags_as_keys(info, item['Tags'])
            page_items.append(info)
            added += 1
        db.replace_items(models.SecurityGroup, page_items)
    logging.info('Addition done')
    del_query = {
        'region': region,
        'account_id': str(account_id),
        'date_added__ne': cur_date,
    }
    if vpc_id:
        del_query['vpc_id'] = vpc_id
    if security_group_id:
        del_query['resource_id'] = security_group_id
    deleted = db.delete_items(models.SecurityGroup, **del_query)
    logging.info('Delete done')
    rsp = {'added': added, 'deleted': deleted}
    logging.info(rsp)
    return rsp
예제 #15
0
def get_instances(lb_item, listener):
    data = []
    for inst in lb_item['Instances']:
        inst_info = db.get_item(models.Instance,
                                resource_id=inst['InstanceId'])
        if not inst_info:
            inst_info = {}
        data.append({
            'resource_id': inst['InstanceId'],
            'name': inst_info.get('name', ''),
            'az': inst_info.get('az', ''),
            'target_port': listener['InstancePort'],
            'target_protocol': listener['InstanceProtocol'],
        })
    return data
예제 #16
0
파일: app.py 프로젝트: lola-end-alz/minder
def create_event():
    credentials = client.OAuth2Credentials.from_json(get_item('credentials'))
    http_auth = credentials.authorize(httplib2.Http())
    calendar_service = discovery.build('calendar', 'v3', http_auth)
    start = datetime.utcnow() + timedelta(minutes=5)
    end = start + timedelta(minutes=5)
    response = calendar_service.events().insert(
        calendarId='primary',
        body={
            'description': 'testing',
            'start': {'dateTime': start.isoformat() + 'Z'},
            'end': {'dateTime': end.isoformat() + 'Z'}
        }
    ).execute()
    return jsonify(status='ok', events=response.get('items'))
예제 #17
0
파일: app.py 프로젝트: lola-end-alz/minder
def calendar():
    credentials = get_item('credentials')
    if not credentials:
        return flask.redirect(flask.url_for('oauth2_callback'))

    credentials = client.OAuth2Credentials.from_json(credentials)

    if credentials.access_token_expired:
        return flask.redirect(flask.url_for('oauth2_callback'))
    else:
        http_auth = credentials.authorize(httplib2.Http())
        calendar_service = discovery.build('calendar', 'v3', http_auth)
        response = calendar_service.events().list(calendarId='primary').execute()

        return jsonify(status='ok', events=response.get('items'))
예제 #18
0
파일: app.py 프로젝트: lola-end-alz/minder
def calendar():
    credentials = get_item('credentials')
    if not credentials:
        return flask.redirect(flask.url_for('oauth2_callback'))

    credentials = client.OAuth2Credentials.from_json(credentials)

    if credentials.access_token_expired:
        return flask.redirect(flask.url_for('oauth2_callback'))
    else:
        http_auth = credentials.authorize(httplib2.Http())
        calendar_service = discovery.build('calendar', 'v3', http_auth)
        response = calendar_service.events().list(
            calendarId='primary').execute()

        return jsonify(status='ok', events=response.get('items'))
예제 #19
0
파일: app.py 프로젝트: lola-end-alz/minder
def minder():
    data = json.loads(request.data)
    logger.info(data)

    try:
        launch, toggle, item, question = _parse_request(data['request'])
        if launch:
            speech_output = 'welcome to minder! what can i do for you today?'
            card_output = 'user launched minder'
            reprompt_message = 'what can i do for you today?'
            response = _get_echo_response(speech_output, card_output, reprompt_message, end_session=False)
        else:
            if question:
                saved_toggle = get_item(item)
                if not saved_toggle:
                    saved_toggle = 'off'
                speech_output = 'hello, the {} is {}'.format(item, saved_toggle)
                card_output = 'user asked if {} is {}. we responded with {}'.format(item, saved_toggle, speech_output)
                reprompt_message = ''
            else:
                speech_output = 'you\'ve turned {} the {}'.format(toggle, item)
                card_output = 'user turned {} the {}'.format(toggle, item)
                reprompt_message = ''

                if toggle == 'on':
                    schedule_the_job(item)

                if toggle == 'off':
                    logger.info('Attempting to cancel job')
                    cancel_the_job()

                set_item(item, toggle)
                send_sms(Config.PROVIDER_PHONE_NUMBER, card_output)

            response = _get_echo_response(speech_output, card_output, reprompt_message)
    except Exception as e:
        logger.error(e)
        speech_output = 'sorry, i didn\'t understand that. please try again'
        card_output = 'couldn\'t understand command from user'
        reprompt_message = 'reprompt message. how does this work?'
        response = _get_echo_response(speech_output, card_output, reprompt_message)

    return jsonify(response)
예제 #20
0
파일: app.py 프로젝트: lola-end-alz/minder
def create_event():
    credentials = client.OAuth2Credentials.from_json(get_item('credentials'))
    http_auth = credentials.authorize(httplib2.Http())
    calendar_service = discovery.build('calendar', 'v3', http_auth)
    start = datetime.utcnow() + timedelta(minutes=5)
    end = start + timedelta(minutes=5)
    response = calendar_service.events().insert(calendarId='primary',
                                                body={
                                                    'description': 'testing',
                                                    'start': {
                                                        'dateTime':
                                                        start.isoformat() + 'Z'
                                                    },
                                                    'end': {
                                                        'dateTime':
                                                        end.isoformat() + 'Z'
                                                    }
                                                }).execute()
    return jsonify(status='ok', events=response.get('items'))
예제 #21
0
def get_targets(client, target_arn, target_groups_list=None):
    data = []
    tgt_group = [
        i for i in target_groups_list if i['TargetGroupArn'] == target_arn
    ][0]
    for tgt in client.describe_target_health(
            TargetGroupArn=target_arn)['TargetHealthDescriptions']:
        item = {
            'resource_id':
            tgt['Target']['Id'],
            'name':
            db.get_item(models.Instance,
                        resource_id=tgt['Target']['Id']).get('name', ''),
            'target_port':
            tgt['Target']['Port'],
            'target_protocol':
            tgt_group['Protocol'],
        }
        data.append(item)
    return data
예제 #22
0
파일: crawl.py 프로젝트: maskiran/aws-vpc
def crawl(account, region, resource, resource_id):
    if resource == 'vpc':
        args = {
            'region': region,
            'account_number': account,
            'vpc_id': resource_id,
            'state': 'queued'
        }
        vpc_name = db.get_item(models.Vpc, resource_id=resource_id).get('name')
        args['vpc_name'] = vpc_name
        models.VpcSyncTask(**args).save()
        return 'sync task scheduled'
    if resource == 'security-group':
        return aws_resources.security_group.sync(account,
                                                 region,
                                                 security_group_id=resource_id)
    if resource == 'subnet':
        return aws_resources.subnet.sync(account,
                                         region,
                                         subnet_id=resource_id)
    if resource == 'route-table':
        return aws_resources.route_table.sync(account,
                                              region,
                                              route_table_id=resource_id)
    if resource == 'instance':
        return aws_resources.instance.sync(account,
                                           region,
                                           instance_id=resource_id)
    if resource == 'elastic-lb':
        return aws_resources.elastic_lb.sync(account,
                                             region,
                                             lb_name=resource_id)
    if resource == 'classic-lb':
        return aws_resources.classic_lb.sync(account,
                                             region,
                                             lb_name=resource_id)
    if resource == 'tgw-attachment':
        return aws_resources.tgw_attachment.sync(account,
                                                 region,
                                                 attachment_id=resource_id)
예제 #23
0
def sync(account_number, region, vpc_id='', lb_name=''):
    cur_date = datetime.datetime.utcnow()
    client, account_id = get_boto3_resource('elb',
                                            region,
                                            account_number=account_number)
    logging.info('Syncing Classic Load Balancers %s %s %s', account_id, region,
                 vpc_id)
    lb_names = []
    if lb_name:
        lb_names.append(lb_name)
    added = 0
    for page in client.get_paginator('describe_load_balancers').paginate(
            LoadBalancerNames=lb_names, PaginationConfig={'PageSize': 20}):
        logging.info('Got page with item count %s',
                     len(page['LoadBalancerDescriptions']))
        page_items = []
        for item in page['LoadBalancerDescriptions']:
            if vpc_id and item['VPCId'] != vpc_id:
                continue
            info = {
                'date_added':
                cur_date,
                'region':
                region,
                'account_id':
                account_id,
                'resource_id':
                item['LoadBalancerName'],
                'vpc_id':
                item['VPCId'],
                'vpc_name':
                db.get_item(models.Vpc, vpc_id=item['VPCId'])['name'],
                'name':
                item['LoadBalancerName'],
                'type':
                'classic',
                'scheme':
                item['Scheme'],
                'created_time':
                item['CreatedTime'],
                'subnets': [{
                    'resource_id':
                    subnet,
                    'name':
                    db.get_item(models.Subnet,
                                resource_id=subnet).get('name', '')
                } for subnet in item['Subnets']],
                'security_groups': [{
                    'resource_id':
                    sg,
                    'name':
                    db.get_item(models.SecurityGroup,
                                resource_id=sg).get('name', '')
                } for sg in item['SecurityGroups']],
                'dns':
                item['DNSName'],
                'listeners':
                get_listeners(item)
            }
            page_items.append(info)
            added += 1
        get_lb_tags(client, page_items)
        db.replace_items(models.LoadBalancer, page_items)
    logging.info('Addition done')
    del_query = {
        'region': region,
        'account_id': str(account_id),
        'date_added__ne': cur_date,
        'type': 'classic'
    }
    if vpc_id:
        del_query['vpc_id'] = vpc_id
    if lb_name:
        del_query['resource_id'] = lb_name
    deleted = db.delete_items(models.LoadBalancer, **del_query)
    logging.info('Delete done')
    rsp = {'added': added, 'deleted': deleted}
    logging.info(rsp)
    return rsp
예제 #24
0
def route_table(resource_id):
    item = db.get_item(models.RouteTable, resource_id=resource_id)
    return item
예제 #25
0
파일: task.py 프로젝트: maskiran/aws-vpc
def crawlingtask(account, region, vpc_id):
    return db.get_item(models.VpcSyncTask,
                       account_number=account,
                       region=region,
                       vpc_id=vpc_id,
                       state__in=['queued', 'running'])
예제 #26
0
파일: task.py 프로젝트: maskiran/aws-vpc
def task(taskid):
    return db.get_item(models.VpcSyncTask, id=taskid)
예제 #27
0
def security_group(resource_id):
    item = db.get_item(models.SecurityGroup, resource_id=resource_id)
    return item
예제 #28
0
def sync(account_number, region, vpc_id='', instance_id=''):
    cur_date = datetime.datetime.utcnow()
    client, account_id = get_boto3_resource('ec2',
                                            region,
                                            account_number=account_number)
    logging.info('Syncing Instances %s %s %s', account_id, region, vpc_id)
    query = []
    if vpc_id:
        query.append({'Name': 'vpc-id', 'Values': [vpc_id]})
    if instance_id:
        query.append({'Name': 'instance-id', 'Values': [instance_id]})
    iam, _ = get_boto3_resource('iam', region, account_number=account_number)
    added = 0
    for page in client.get_paginator('describe_instances').paginate(
            Filters=query):
        logging.info('Got page with reservation count %s',
                     len(page['Reservations']))
        page_items = []
        for reservation in page['Reservations']:
            for item in reservation['Instances']:
                if item['State']['Name'] == "terminated":
                    continue
                if 'Tags' not in item:
                    item['Tags'] = []
                info = {
                    'date_added':
                    cur_date,
                    'region':
                    region,
                    'account_id':
                    reservation['OwnerId'],
                    'resource_id':
                    item['InstanceId'],
                    'name':
                    get_name_tag(item['Tags']),
                    'tags':
                    normalize_tags_list(item['Tags']),
                    'instance_type':
                    item['InstanceType'],
                    'launch_time':
                    item['LaunchTime'],
                    'key_name':
                    item.get('KeyName', ''),
                    'vpc_id':
                    item['VpcId'],
                    'vpc_name':
                    db.get_item(models.Vpc,
                                resource_id=item['VpcId']).get('name', ''),
                    'iam_instance_profile_arn':
                    item.get('IamInstanceProfile', {}).get('Arn', ''),
                    'iam_instance_profile_name':
                    item.get('IamInstanceProfile', {}).get('Arn',
                                                           '').split('/')[-1],
                    'network_interfaces':
                    get_network_interfaces(item['NetworkInterfaces']),
                    'az':
                    item['Placement']['AvailabilityZone'],
                    'state':
                    item['State']['Name'],
                }
                set_iam_role(info, iam)
                add_tags_as_keys(info, item['Tags'])
                page_items.append(info)
                added += 1
        db.replace_items(models.Instance, page_items)
    logging.info('Addition done')
    del_query = {
        'region': region,
        'account_id': str(account_id),
        'date_added__ne': cur_date,
    }
    if vpc_id:
        del_query['vpc_id'] = vpc_id
    if instance_id:
        del_query['resource_id'] = instance_id
    deleted = db.delete_items(models.Instance, **del_query)
    logging.info('Delete done')
    rsp = {'added': added, 'deleted': deleted}
    logging.info(rsp)
    return rsp
예제 #29
0
def sync(account_number, region, vpc_id='', route_table_id=''):
    cur_date = datetime.datetime.utcnow()
    client, account_id = get_boto3_resource('ec2',
                                            region,
                                            account_number=account_number)
    logging.info('Syncing Route tables %s %s %s %s', account_id, region,
                 vpc_id, route_table_id)
    query = []
    if vpc_id:
        query.append({'Name': 'vpc-id', 'Values': [vpc_id]})
    if route_table_id:
        query.append({'Name': 'route-table-id', 'Values': [route_table_id]})
    added = 0
    for page in client.get_paginator('describe_route_tables').paginate(
            Filters=query):
        logging.info('Got page with item count %s', len(page['RouteTables']))
        page_items = []
        for item in page['RouteTables']:
            if 'Tags' not in item:
                item['Tags'] = []
            info = {
                'date_added':
                cur_date,
                'region':
                region,
                'account_id':
                item['OwnerId'],
                'resource_id':
                item['RouteTableId'],
                'name':
                get_name_tag(item['Tags'], item['RouteTableId']),
                'tags':
                normalize_tags_list(item['Tags']),
                'vpc_id':
                item['VpcId'],
                'vpc_name':
                db.get_item(models.Vpc,
                            resource_id=item['VpcId']).get('name', ''),
                'subnets': [
                    assoc['SubnetId'] for assoc in item['Associations']
                    if not assoc['Main']
                ],
                'routes':
                get_routes(item['Routes']),
                'main':
                is_main_rtable(item)
            }
            add_tags_as_keys(info, item['Tags'])
            page_items.append(info)
            added += 1
        db.replace_items(models.RouteTable, page_items)
    logging.info('Addition done')
    del_query = {
        'region': region,
        'account_id': str(account_id),
        'date_added__ne': cur_date,
    }
    if vpc_id:
        del_query['vpc_id'] = vpc_id
    if route_table_id:
        del_query['resource_id'] = route_table_id

    deleted = db.delete_items(models.RouteTable, **del_query)
    logging.info('Delete done')
    rsp = {'added': added, 'deleted': deleted}
    logging.info(rsp)
    return rsp
예제 #30
0
import wowhead_scrape, sys, pickle, db

tsm_data = pickle.load(open(sys.argv[1], "rb"))
for item_id in tsm_data:
    if db.get_item(item_id) is None:
        print("Scanning item " + item_id)
        item = wowhead_scrape.scrape_item(item_id)
        print(item)
        db.insert_item(item)
        print('Done')
        sys.stdout.flush()
예제 #31
0
파일: subnet.py 프로젝트: maskiran/aws-vpc
def sync(account_number, region, vpc_id='', subnet_id=''):
    cur_date = datetime.datetime.utcnow()
    client, account_id = get_boto3_resource('ec2',
                                            region,
                                            account_number=account_number)
    logging.info('Syncing Subnets %s %s %s', account_id, region, vpc_id)
    query = []
    if vpc_id:
        query.append({'Name': 'vpc-id', 'Values': [vpc_id]})
    if subnet_id:
        query.append({'Name': 'subnet-id', 'Values': [subnet_id]})
    added = 0
    for page in client.get_paginator('describe_subnets').paginate(
            Filters=query):
        logging.info('Got page with item count %s', len(page['Subnets']))
        page_items = []
        for item in page['Subnets']:
            if 'Tags' not in item:
                item['Tags'] = []
            info = {
                'date_added':
                cur_date,
                'region':
                region,
                'account_id':
                item['OwnerId'],
                'resource_id':
                item['SubnetId'],
                'name':
                get_name_tag(item['Tags'], item['SubnetId']),
                'tags':
                normalize_tags_list(item['Tags']),
                'vpc_id':
                item['VpcId'],
                'vpc_name':
                db.get_item(models.Vpc,
                            resource_id=item['VpcId']).get('name', ''),
                'cidr':
                item['CidrBlock'],
                'az':
                item['AvailabilityZone'],
                'arn':
                item['SubnetArn'],
                'route_table':
                get_route_table(region, item['VpcId'], item['SubnetId'])
            }
            add_tags_as_keys(info, item['Tags'])
            page_items.append(info)
            added += 1
        db.replace_items(models.Subnet, page_items)
    logging.info('Addition done')
    del_query = {
        'region': region,
        'account_id': str(account_id),
        'date_added__ne': cur_date,
    }
    if vpc_id:
        del_query['vpc_id'] = vpc_id
    if subnet_id:
        del_query['resource_id'] = subnet_id
    deleted = db.delete_items(models.Subnet, **del_query)
    logging.info('Delete done')
    rsp = {'added': added, 'deleted': deleted}
    logging.info(rsp)
    return rsp
예제 #32
0
def vpc(resource_id):
    item = db.get_item(models.Vpc, resource_id=resource_id)
    return item
예제 #33
0
파일: subnet.py 프로젝트: maskiran/aws-vpc
def subnet(resource_id):
    item = db.get_item(models.Subnet, resource_id=resource_id)
    routes = db.get_item(models.RouteTable,
                         resource_id=item['route_table']['resource_id'])
    item['routes'] = routes['routes']
    return item
예제 #34
0
import sys
sys.path.append('src')

import db
import _db_common

#########
# TEST

assert(db.get_item('_test',k0='VTWONHZP')==None)
test_item0 = db.new_item('_test',k0='VTWONHZP')
assert(db.get_item('_test',k0='VTWONHZP')!=None)

assert(db.rm_item('_test',k0='VTWONHZP'))
assert(db.get_item('_test',k0='VTWONHZP')==None)

assert(db.get_item('_test',k0='SDAWPRLI')==None)
test_item0 = db.new_item('_test',k0='SDAWPRLI')
assert(db.get_item('_test',k0='SDAWPRLI')!=None)

assert(db.rm_item('_test',test_item0['UUIDD']))
assert(db.get_item('_test',k0='SDAWPRLI')==None)

assert(db.get_item('_test',k0='EFAEHDNF')==None)
test_item0 = db.new_item('_test',k0='EFAEHDNF')
assert(db.get_item('_test',k0='EFAEHDNF')!=None)

assert(not db.rm_item('_test',test_item0['UUIDD'],k0='LAYQGIGY'))
assert(db.get_item('_test',k0='EFAEHDNF')!=None)

assert(db.rm_item('_test',test_item0['UUIDD'],k0='EFAEHDNF'))