コード例 #1
0
def main():
    parser = base_parser(description=(
        "Tools for adding/viewing uuids on environments in preparation "
        "for migration from account_number_name to uuid."))

    subparsers = parser.add_subparsers()

    # Parser for listing all environments.
    show_parser = subparsers.add_parser('list', help="List environments.")
    show_parser.add_argument('--sort',
                             '-s',
                             help='Sort by uuid|account_number and name',
                             choices=['uuid', 'name'],
                             default='name')
    show_parser.add_argument('--missing', action='store_true', default=False)
    show_parser.set_defaults(func=list_all)

    # Parser for show one environment
    get_parser = subparsers.add_parser('show', help="Show one environment.")
    get_parser.add_argument('--uuid', type=str, help="uuid of environment.")
    get_parser.add_argument('--account-number',
                            type=str,
                            help="account_number of the environment.")
    get_parser.add_argument('--name',
                            type=str,
                            help="Name of the environment.")
    get_parser.set_defaults(func=show_one)

    # Parser for setting a single uuid
    set_uuid_parser = subparsers.add_parser(
        'set-uuid',
        help=("Set uuid on an environment. "
              "Locate environment by account number and name."))
    set_uuid_parser.add_argument('--account-number',
                                 type=str,
                                 help="account_number of the environment.")
    set_uuid_parser.add_argument('--name',
                                 type=str,
                                 help="Name of the environment.")
    set_uuid_parser.add_argument('uuid', type=str)
    set_uuid_parser.set_defaults(func=set_one_uuid)

    # Parser for setting multiple uuids.
    set_uuids_parser = subparsers.add_parser(
        'set-uuids',
        help=("Set uuids for multiple environments. "
              "Mapping is provided via a yaml file."))
    set_uuids_parser.add_argument(
        'filename', type=str, help="Location to yaml file containing mapping.")
    set_uuids_parser.add_argument('--list',
                                  action="store_true",
                                  default=False,
                                  help="Examine yaml contents.")
    set_uuids_parser.set_defaults(func=set_uuids_from_yaml)

    # Run subcommand
    args = parser.parse_args()
    args.func(args)
コード例 #2
0
def main():
    parser = base_parser(
        description="Set up neo4j constraints for cloud snitch entities.")
    parser.parse_args()
    driver = GraphDatabase.driver(settings.NEO4J_URI,
                                  auth=(settings.NEO4J_USERNAME,
                                        settings.NEO4J_PASSWORD))
    template = 'CREATE CONSTRAINT ON (n:{label}) ASSERT n.{prop} IS UNIQUE'
    with driver.session() as session:
        with session.begin_transaction() as tx:
            for _model in _models:
                tx.run(
                    template.format(label=_model.label,
                                    prop=_model.identity_property))
    driver.close()
コード例 #3
0
def main():
    # Parse args.
    parser = base_parser(
        description='Removes stale run data that have already synced.')
    parser.parse_args()

    start = time.time()
    foundruns = runs.find_runs()
    cleaned = 0
    for run in foundruns:
        if run.synced is not None:
            logger.info("Cleaning {}".format(run.path))
            shutil.rmtree(run.path)
            cleaned += 1
    logger.info("Cleaned {} runs in {:.3f} seconds".format(
        cleaned,
        time.time() - start))
コード例 #4
0
from cloud_snitch.snitchers.pip import PipSnitcher
from cloud_snitch.snitchers.uservars import UservarsSnitcher
from cloud_snitch.snitchers.configuredinterface import \
    ConfiguredInterfaceSnitcher

from cloud_snitch import runs
from cloud_snitch import utils
from cloud_snitch.cli_common import base_parser
from cloud_snitch.driver import DriverContext
from cloud_snitch.exc import RunContainsOldDataError
from cloud_snitch.models import EnvironmentEntity
from cloud_snitch.lock import lock_environment

logger = logging.getLogger(__name__)

parser = base_parser(description="Ingest collected snitch data to neo4j.")
parser.add_argument('path', help='Path or archived collection run.')
parser.add_argument(
    '--key', help='Base64 encoded 256 bit AES key. For testing/debug only.')


def check_run_time(driver, run):
    """Prevent a run from updating an environment.

    Protects an environment with newer data from a run with older data.

    :param driver: Neo4J database driver instance
    :type driver: neo4j.v1.GraphDatabase.driver
    :param run: Date run instance
    :type run: cloud_snitch.runs.Run
    """
コード例 #5
0
"""Quick module for generating fake data from real data."""
import logging
import pprint

from cloud_snitch import settings
from cloud_snitch.cli_common import base_parser
from cloud_snitch.cli_common import confirm_env_action
from cloud_snitch.cli_common import find_environment
from cloud_snitch.lock import lock_environment
from cloud_snitch.models import registry
from neo4j.v1 import GraphDatabase

logger = logging.getLogger(__name__)

parser = base_parser(description="Remove environment data.")

parser.add_argument('uuid',
                    type=str,
                    help='UUID of the customer environment to remove.')

parser.add_argument('-s',
                    '--skip',
                    action='store_true',
                    help='Skip interactive confirmation.')


def delete_until_zero(session, match, params=None, limit=2000):
    """Delete chunks of matches until no matches.

    Deletes in chunks of limit.
コード例 #6
0
"""Quick module for terminating relationships for an environment."""
import logging
import time

from cloud_snitch import settings
from cloud_snitch import utils
from cloud_snitch.cli_common import base_parser
from cloud_snitch.cli_common import confirm_env_action
from cloud_snitch.cli_common import find_environment
from cloud_snitch.lock import lock_environment
from neo4j.v1 import GraphDatabase

logger = logging.getLogger(__name__)

parser = base_parser(description=(
    "Terminate an environment. Mark ending time on all relationships "
    "stemming from the environment."))

parser.add_argument('uuid', type=str, help='UUID of environment to terminate.')

parser.add_argument('-s',
                    '--skip',
                    action='store_true',
                    help='Skip interactive confirmation.')

parser.add_argument('--time',
                    type=int,
                    help="Optional timestamp in ms. Defaults to utc now.",
                    default=utils.milliseconds_now())

parser.add_argument(
コード例 #7
0
 def test_base_parser(self):
     """Test behaviour of default options."""
     parser = base_parser(description='test_description')
     self.assertEqual(parser.description, 'test_description')
     with self.assertRaises(SystemExit):
         parser.parse_args(['-v'])
コード例 #8
0
        labels.append(klass.label)
        if registry.state_properties(model_name):
            labels.append(klass.state_label)

    for label in labels:
        cipher = 'MATCH (n:{}) RETURN COUNT(*) as `total`'.format(label)
        with driver.session() as session:
            with session.begin_transaction() as tx:
                res = tx.run(cipher).single()
                counts[label] = res['total']
    return counts


if __name__ == '__main__':
    parser = base_parser(
        description=("Migration script to convert to environment uuids. "
                     "All environments must have uuids."))

    parser.add_argument('--limit',
                        type=int,
                        default=2000,
                        help="Number of rows to consider at a time.")

    parser.add_argument('--cipher-only',
                        action="store_true",
                        default=False,
                        help="Print only the cipher for migration.")

    args = parser.parse_args()
    # Check that all environments have uuids before migrating
    if not validate_environments():