def _gce_key(cred):
    if 'json_key' in cred:
        key = json.loads(cryptotool.decrypt_scalr(app.crypto_key, cred['json_key']))['private_key']
    else:
        key = cryptotool.decrypt_scalr(app.crypto_key, cred['key'])
        # convert pkcs12 to rsa
        out, err, ret_code = helper.call(
            "openssl pkcs12 -nodes -nocerts -passin pass:notasecret | openssl rsa",
            input=binascii.a2b_base64(key),
            shell=True
        )
        key = out.strip()
    return key
Beispiel #2
0
    def check_rrd_files(self):
        if self.app.config['rrd']['rrdcached_sock_path']:
            rrdcached_sock_file = self.app.config['rrd']['rrdcached_sock_path']
        else:
            rrdcached_sock_file = self.app.config['rrd']['rrdcached_sock_path']
        metrics = self.app.config['metrics']
        metrics_map = {
            'cpu': 'CPUSNMP/db.rrd',
            'la': 'LASNMP/db.rrd',
            'mem': 'MEMSNMP/db.rrd',
            'net': 'NETSNMP/db.rrd',
            'io': 'IO/sda1.rrd'
        }
        out_map = {
            'cpu': '10 10 10 10',
            'la': '1.0 1.0 1.0',
            'mem': '1024.0 1024.0 1024.0 U 1024.0 1024.0 1024.0 1024.0',
            'net': '1024 1024',
            'io': '10 10 10 10',
        }
        for server_id, server in lib.world.servers.iteritems():
            x1x2 = helper.x1x2(server['farm_id'])
            path = os.path.join(self.app.config['rrd']['dir'], x1x2,
                                str(server['farm_id']))
            farm_path = os.path.join(path, 'FARM')
            role_path = os.path.join(path, 'FR_%s' % server['farm_roleid'])
            server_path = os.path.join(
                path,
                'INSTANCE_%s_%s' % (server['farm_roleid'], server['index']))
            if server['status'] != 'Running':
                assert not os.path.isdir(server_path)
                continue
            assert os.path.isdir(farm_path), farm_path
            assert os.path.isdir(os.path.join(farm_path, 'SERVERS'))
            assert os.path.isdir(role_path), role_path
            assert os.path.isdir(os.path.join(role_path, 'SERVERS'))
            assert os.path.isdir(server_path), server_path

            for metric in metrics:
                if metric == 'snum':
                    continue
                rrd_db_file = os.path.join(server_path, metrics_map[metric])
                rrdtool.flushcached('--daemon',
                                    'unix:%s' % rrdcached_sock_file,
                                    rrd_db_file)
                stdout, stderr, return_code = helper.call(
                    'rrdtool lastupdate %s' % rrd_db_file)
                assert not return_code
                assert stdout.split('/n')[-1].split(
                    ':')[-1].strip() == out_map[metric]
Beispiel #3
0
def _gce_key(cred):
    if cred.get('json_key'):
        key = json.loads(
            cryptotool.decrypt_scalr(app.crypto_key,
                                     cred['json_key']))['private_key']
    else:
        key = cryptotool.decrypt_scalr(app.crypto_key, cred['key'])
        # convert pkcs12 to rsa
        out, err, ret_code = helper.call(
            "openssl pkcs12 -nodes -nocerts -passin pass:notasecret | openssl rsa",
            input=binascii.a2b_base64(key),
            shell=True)
        key = out.strip()
    return key
Beispiel #4
0
def _gce_conn(cred):
    service_account_name = cred['service_account_name']
    key = cred['key']

    # convert pkcs12 to rsa
    out, err, ret_code = helper.call(
        "openssl pkcs12 -nodes -nocerts -passin pass:notasecret | openssl rsa",
        input=binascii.a2b_base64(key),
        shell=True)
    key = out.strip()

    signed_jwt_assert_cred = SignedJwtAssertionCredentials(
        service_account_name, key, ['https://www.googleapis.com/auth/compute'])
    http = httplib2.Http()
    http = signed_jwt_assert_cred.authorize(http)
    return build('compute', 'v1', http=http), http
Beispiel #5
0
    def check_rrd_files(self):
        if self.app.config['rrd']['rrdcached_sock_path']:
            rrdcached_sock_file = self.app.config['rrd']['rrdcached_sock_path']
        else:
            rrdcached_sock_file = self.app.config['rrd']['rrdcached_sock_path']
        metrics = self.app.config['metrics']
        metrics_map = {
            'cpu': 'CPUSNMP/db.rrd',
            'la': 'LASNMP/db.rrd',
            'mem': 'MEMSNMP/db.rrd',
            'net': 'NETSNMP/db.rrd',
            'io': 'IO/sda1.rrd'
        }
        out_map = {
            'cpu': '10 10 10 10',
            'la': '1.0 1.0 1.0',
            'mem': '1024.0 1024.0 1024.0 U 1024.0 1024.0 1024.0 1024.0',
            'net': '1024 1024',
            'io': '10 10 10 10',
        }
        for server_id, server in lib.world.servers.iteritems():
            x1x2 = helper.x1x2(server['farm_id'])
            path = os.path.join(self.app.config['rrd']['dir'], x1x2, str(server['farm_id']))
            farm_path = os.path.join(path, 'FARM')
            role_path = os.path.join(path, 'FR_%s' % server['farm_roleid'])
            server_path = os.path.join(path, 'INSTANCE_%s_%s' % (server['farm_roleid'], server['index']))
            if server['status'] != 'Running':
                assert not os.path.isdir(server_path)
                continue
            assert os.path.isdir(farm_path), farm_path
            assert os.path.isdir(os.path.join(farm_path, 'SERVERS'))
            assert os.path.isdir(role_path), role_path
            assert os.path.isdir(os.path.join(role_path, 'SERVERS'))
            assert os.path.isdir(server_path), server_path

            for metric in metrics:
                if metric == 'snum':
                    continue
                rrd_db_file = os.path.join(server_path, metrics_map[metric])
                rrdtool.flushcached('--daemon', 'unix:%s' % rrdcached_sock_file, rrd_db_file)
                stdout, stderr, return_code = helper.call('rrdtool lastupdate %s' % rrd_db_file)
                assert not return_code
                assert stdout.split('/n')[-1].split(':')[-1].strip() == out_map[metric]
Beispiel #6
0
def _gce_conn(cred):
    service_account_name = cryptotool.decrypt_scalr(CRYPTO_KEY, cred['service_account_name'])
    key = cryptotool.decrypt_scalr(CRYPTO_KEY, cred['key'])

    # convert pkcs12 to rsa
    out, err = helper.call(
        "openssl pkcs12 -nodes -nocerts -passin pass:notasecret | openssl rsa",
        input=binascii.a2b_base64(key),
        shell=True
    )
    key = out.strip()

    signed_jwt_assert_cred = SignedJwtAssertionCredentials(
        service_account_name,
        key,
        ['https://www.googleapis.com/auth/compute']
    )
    http = httplib2.Http()
    http = signed_jwt_assert_cred.authorize(http)
    return build('compute', 'v1', http=http), http