Пример #1
0
    def deploy(self, args, **extra_args):
        """Deploy a docker container to a specific container ship (host)

        :param args:
        :type args:
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(
                logger.error(
                    "args should of an instance of argparse.Namespace"))

        # create new freight forwarder
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder to dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'deploy', args.data_center, args.environment, args.service)

        # deploy containers.
        bill_of_lading = freight_forwarder.deploy_containers(
            commercial_invoice, args.tag, args.env)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Пример #2
0
    def deploy(self, args, **extra_args):
        """Deploy a docker container to a specific container ship (host)

        :param args:
        :type args:
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(logger.error("args should of an instance of argparse.Namespace"))

        # create new freight forwarder
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder to dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'deploy',
            args.data_center,
            args.environment,
            args.service
        )

        # deploy containers.
        bill_of_lading = freight_forwarder.deploy_containers(commercial_invoice, args.tag, args.env)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Пример #3
0
    def __init__(self, sub_parser):
        logger.setup_logging('cli')
        if not isinstance(sub_parser, argparse._SubParsersAction):
            raise logger.error(Exception("parser should of an instance of argparse._SubParsersAction"))

        # Set up export parser and pass Export class to function call.
        self._parser = sub_parser.add_parser('info')
        self._parser.set_defaults(func=self._info)
Пример #4
0
    def _export(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(
                logger.error(
                    "args should of an instance of argparse.Namespace"))

        # Warn the consumer about unsafe Docker Practices
        if args.no_validation:
            logger.warning(
                "#######################################################\n"
                "Validation has been disabled for this export operation.\n"
                "This is an unsafe operation and does not verify the "
                "run time nature of the container.\n"
                "Any docker image created in this manner will not "
                "be verified to start. Do not ship broken code.\n"
                "#######################################################\n",
                extra={'formatter': 'cli-warning'})

            # Require the consumer to verify their actions
            if not args.y:
                validation_input = six.moves.input(
                    "Please type \'yes\' to export the container without validation: "
                )

                if not (isinstance(validation_input, six.string_types) and
                        ('yes' == validation_input)):
                    raise ValueError(
                        "Incorrect type defined. Required value: yes")

        # create new freight forwarder to create a commercial_invoice and export goods.
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'export',
            args.data_center,
            args.environment,
            args.service,
            tagging_scheme=not args.no_tagging_scheme)

        # create commercial_invoice
        bill_of_lading = freight_forwarder.export(
            commercial_invoice,
            clean=args.clean,
            configs=args.configs,
            tags=args.tag,
            test=args.test,
            use_cache=args.use_cache,
            validate=not args.no_validation)

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Пример #5
0
    def _info(self, args, **extra_args):
        """Print freight forwarder info to the user.
        """
        if not isinstance(args, argparse.Namespace):
            raise logger.error(Exception("args should of an instance of argparse.Namespace"))

        logger.info("Freight Forwarder: {0}".format(VERSION))
        logger.info("docker-py: {0}".format(docker_py_version))
        logger.info("Docker Api: {0}".format(DOCKER_API_VERSION))
        logger.info("{0} version: {1}".format(platform.python_implementation(), platform.python_version()))
Пример #6
0
    def __init__(self, sub_parser):
        logger.setup_logging('cli')
        if not isinstance(sub_parser, argparse._SubParsersAction):
            raise Exception(logger.error("parser should of an instance of argparse._SubParsersAction"))

        # Set up export parser and pass Export class to function call.
        self._parser = sub_parser.add_parser('export')
        CliMixin.__init__(self)
        self._build_arguments()
        self._parser.set_defaults(func=self._export)
Пример #7
0
    def _export(self, args, **extra_args):
        """
        Export is the entry point for exporting docker images.
        """
        if not isinstance(args, argparse.Namespace):
            raise TypeError(logger.error("args should of an instance of argparse.Namespace"))

        # Warn the consumer about unsafe Docker Practices
        if args.no_validation:
            logger.warning("#######################################################\n"
                           "Validation has been disabled for this export operation.\n"
                           "This is an unsafe operation and does not verify the "
                           "run time nature of the container.\n"
                           "Any docker image created in this manner will not "
                           "be verified to start. Do not ship broken code.\n"
                           "#######################################################\n",
                           extra={'formatter': 'cli-warning'})

            # Require the consumer to verify their actions
            if not args.y:
                validation_input = six.moves.input("Please type \'yes\' to export the container without validation: ")

                if not (isinstance(validation_input, six.string_types) and ('yes' == validation_input)):
                    raise ValueError("Incorrect type defined. Required value: yes")

        # create new freight forwarder to create a commercial_invoice and export goods.
        freight_forwarder = FreightForwarder()

        # create commercial invoice this is the contact given to freight forwarder dispatch containers and images
        commercial_invoice = freight_forwarder.commercial_invoice(
            'export',
            args.data_center,
            args.environment,
            args.service,
            tagging_scheme=not args.no_tagging_scheme
        )

        # create commercial_invoice
        bill_of_lading = freight_forwarder.export(
            commercial_invoice,
            attach=args.attach,
            clean=args.clean,
            configs=args.configs,
            tags=args.tag,
            test=args.test,
            use_cache=args.use_cache,
            validate=not args.no_validation
        )

        # pretty lame... Need to work on return values through to app to make them consistent.
        exit_code = 0 if bill_of_lading else 1

        if exit_code != 0:
            exit(exit_code)
Пример #8
0
    def __init__(self, sub_parser):
        """Constructor for Docker Command class."""
        logger.setup_logging('cli')
        if not isinstance(sub_parser, argparse._SubParsersAction):
            raise TypeError(logger.error("parser should of an instance of argparse._SubParsersAction"))

        # Set up deploy parser and pass deploy function to defaults.
        self._parser = sub_parser.add_parser('deploy')
        CliMixin.__init__(self)
        self._build_arguments()
        self._parser.set_defaults(func=self.deploy)
Пример #9
0
    def __init__(self, sub_parser):
        logger.setup_logging('cli')
        if not isinstance(sub_parser, argparse._SubParsersAction):
            raise Exception(
                logger.error(
                    "parser should of an instance of argparse._SubParsersAction"
                ))

        # Set up export parser and pass Export class to function call.
        self._parser = sub_parser.add_parser('export')
        CliMixin.__init__(self)
        self._build_arguments()
        self._parser.set_defaults(func=self._export)
Пример #10
0
    def __init__(self, sub_parser):
        """Constructor for Docker Command class."""
        logger.setup_logging('cli')
        if not isinstance(sub_parser, argparse._SubParsersAction):
            raise TypeError(
                logger.error(
                    "parser should of an instance of argparse._SubParsersAction"
                ))

        # Set up deploy parser and pass deploy function to defaults.
        self._parser = sub_parser.add_parser('deploy')
        CliMixin.__init__(self)
        self._build_arguments()
        self._parser.set_defaults(func=self.deploy)
Пример #11
0
def _create_registries(registries_meta):
    """
    """
    registries = {'docker_hub': Registry()}

    if registries_meta is None:
        logger.warning("There were no registries defined. Defaulting to Docker hub.")
        return registries
    elif isinstance(registries_meta, dict):
        registries.update({alias: Registry(**registry) for alias, registry in six.iteritems(registries_meta)})
    else:
        raise TypeError(logger.error("registries must be a dict"))

    if 'default' not in registries:
        logger.warning("There was not default registry defined. Default will be Docker hub.")

    return registries
Пример #12
0
def _create_registries(registries_meta):
    """
    """
    registries = {'docker_hub': Registry()}

    if registries_meta is None:
        logger.warning(
            "There were no registries defined. Defaulting to Docker hub.")
        return registries
    elif isinstance(registries_meta, dict):
        registries.update({
            alias: Registry(**registry)
            for alias, registry in six.iteritems(registries_meta)
        })
    else:
        raise TypeError(logger.error("registries must be a dict"))

    if 'default' not in registries:
        logger.warning(
            "There was not default registry defined. Default will be Docker hub."
        )

    return registries
Пример #13
0
    def source_tag(self, value):
        if not isinstance(value, six.string_types):
            raise TypeError(logger.error("source_tag must be a string."))

        self._source_tag = value
Пример #14
0
    def source_tag(self, value):
        if not isinstance(value, six.string_types):
            raise TypeError(logger.error("source_tag must be a string."))

        self._source_tag = value