Beispiel #1
0
 def configure(self):
     BaseCommand.configure(self)
     if self.service is not None:
         self.service.configure()
     if self.auth is not None:
         self.auth.configure()
     self.__configured = True
Beispiel #2
0
    def configure(self):
        BaseCommand.configure(self)
        self.update_config_view()

        #Get optional destination directory...
        dest_file = self.args['destination']
        if not isinstance(dest_file, file) and dest_file != "-":
            dest_file = os.path.expanduser(os.path.abspath(dest_file))
            self.args['destination'] = dest_file

        #Get Mandatory manifest...
        manifest = self.args.get('manifest', None)
        if manifest:
            if not isinstance(manifest, BundleManifest):
                #Read manifest file into manifest obj...
                manifest_path = os.path.expanduser(os.path.abspath(
                    self.args['manifest']))
                if not os.path.exists(manifest_path):
                    raise ArgumentError("Manifest '{0}' does not exist"
                                        .format(self.args['manifest']))
                if not os.path.isfile(manifest_path):
                    raise ArgumentError("Manifest '{0}' is not a file"
                                        .format(self.args['manifest']))
                #Get the mandatory private key...
                if not self.args.get('privatekey'):
                    config_privatekey = self.config.get_user_option(
                        'private-key')
                    if self.args.get('userregion'):
                        self.args['privatekey'] = config_privatekey
                    elif 'EC2_PRIVATE_KEY' in os.environ:
                        self.args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
                    elif config_privatekey:
                        self.args['privatekey'] = config_privatekey
                    else:
                        raise ArgumentError(
                            'missing private key needed to read manifest;'
                            ' please supply one with -k')
                privatekey = self.args['privatekey']
                self.args['privatekey'] = os.path.expanduser(
                    os.path.expandvars(privatekey))
                if not os.path.exists(self.args['privatekey']):
                    raise ArgumentError("private key file '{0}' does not exist"
                                        .format(self.args['privatekey']))
                if not os.path.isfile(self.args['privatekey']):
                    raise ArgumentError("private key file '{0}' is not a file"
                                        .format(self.args['privatekey']))
                #Read manifest into BundleManifest obj...
                manifest = BundleManifest.read_from_file(
                    manifest_path,
                    self.args['privatekey'])
                self.args['manifest'] = manifest
            if not self.args.get('enc_key') and manifest:
                self.args['enc_key'] = manifest.enc_key
            if not self.args.get('enc_iv') and manifest:
                self.args['enc_iv'] = manifest.enc_iv

        if not self.args.get('enc_key') or not self.args.get('enc_iv'):
            raise ArgumentError('Encryption key (-e) and initialization vector'
                                ' (-v) are required if manifest (-m) is not'
                                ' provided')
Beispiel #3
0
    def configure(self):
        BaseCommand.configure(self)
        set_userregion(self.config, self.args.get('userregion'))
        set_userregion(self.config, os.getenv('EUCA_REGION'))

        # Get creds
        add_bundle_creds(self.args, self.config)
        if not self.args.get('cert'):
            raise ArgumentError(
                'missing certificate; please supply one with -c')
        self.log.debug('certificate: %s', self.args['cert'])
        if not self.args.get('privatekey'):
            raise ArgumentError(
                'missing private key; please supply one with -k')
        self.log.debug('private key: %s', self.args['privatekey'])
        if not self.args.get('ec2cert'):
            raise ArgumentError(
                'missing cloud certificate; please supply one with --ec2cert')
        self.log.debug('cloud certificate: %s', self.args['ec2cert'])
        if not self.args.get('user'):
            raise ArgumentError(
                'missing account ID; please supply one with --user')
        self.log.debug('account ID: %s', self.args['user'])

        if (self.args.get('destination') and
            os.path.exists(self.args['destination']) and not
            os.path.isdir(self.args['destination'])):
            raise ArgumentError("argument -d/--destination: '{0}' is not a "
                                "directory".format(self.args['destination']))
Beispiel #4
0
    def configure(self):
        BaseCommand.configure(self)
        set_userregion(self.config, self.args.get('userregion'))
        set_userregion(self.config, os.getenv('EUCA_REGION'))

        # Get creds
        add_bundle_creds(self.args, self.config)
        if not self.args.get('cert'):
            raise ArgumentError(
                'missing certificate; please supply one with -c')
        self.log.debug('certificate: %s', self.args['cert'])
        if not self.args.get('privatekey'):
            raise ArgumentError(
                'missing private key; please supply one with -k')
        self.log.debug('private key: %s', self.args['privatekey'])
        if not self.args.get('ec2cert'):
            raise ArgumentError(
                'missing cloud certificate; please supply one with --ec2cert')
        self.log.debug('cloud certificate: %s', self.args['ec2cert'])
        if not self.args.get('user'):
            raise ArgumentError(
                'missing account ID; please supply one with --user')
        self.log.debug('account ID: %s', self.args['user'])

        if (self.args.get('destination')
                and os.path.exists(self.args['destination'])
                and not os.path.isdir(self.args['destination'])):
            raise ArgumentError("argument -d/--destination: '{0}' is not a "
                                "directory".format(self.args['destination']))
Beispiel #5
0
 def configure(self):
     # TODO:  rename this to setup
     BaseCommand.configure(self)
     if self.service is not None:
         self.service.configure()
     if self.auth is not None:
         self.auth.configure()
     self.__configured = True
Beispiel #6
0
 def configure(self):
     # TODO:  rename this to setup
     BaseCommand.configure(self)
     if self.service is not None:
         self.service.configure()
     if self.auth is not None:
         self.auth.configure()
     self.__configured = True
Beispiel #7
0
    def configure(self):
        substitute_euca_region(self)
        self.update_config_view()

        BaseCommand.configure(self)

        self.configure_bundle_creds()
        self.configure_bundle_properties()
        self.configure_bundle_output()
        self.generate_encryption_keys()
Beispiel #8
0
    def configure(self):
        substitute_euca_region(self)
        self.update_config_view()

        BaseCommand.configure(self)

        self.configure_bundle_creds()
        self.configure_bundle_properties()
        self.configure_bundle_output()
        self.generate_encryption_keys()
Beispiel #9
0
    def configure(self):
        BaseCommand.configure(self)
        self.update_config_view()

        if not self.args.get('source') or self.args['source'] == '-':
            # We dup stdin because the multiprocessing lib closes it
            self.args['source'] = os.fdopen(os.dup(sys.stdin.fileno()))
        elif isinstance(self.args['source'], basestring):
            self.args['source'] = open(self.args['source'])
        # Otherwise, assume it is already a file object

        if not self.args.get('dest') or self.args['dest'] == '-':
            self.args['dest'] = sys.stdout
            self.args['show_progress'] = False
        elif isinstance(self.args['dest'], basestring):
            self.args['dest'] = open(self.args['dest'], 'w')
    def configure(self):
        BaseCommand.configure(self)
        self.update_config_view()

        if not self.args.get('source') or self.args['source'] == '-':
            # We dup stdin because the multiprocessing lib closes it
            self.args['source'] = os.fdopen(os.dup(sys.stdin.fileno()))
        elif isinstance(self.args['source'], six.string_types):
            self.args['source'] = open(self.args['source'])
        # Otherwise, assume it is already a file object

        if not self.args.get('dest') or self.args['dest'] == '-':
            self.args['dest'] = sys.stdout
            self.args['show_progress'] = False
        elif isinstance(self.args['dest'], six.string_types):
            self.args['dest'] = open(self.args['dest'], 'w')
Beispiel #11
0
    def configure(self):
        self.update_config_view()

        BaseCommand.configure(self)

        # Set up access to bootstrap in case we need auto cert fetching.
        #
        # We would normally make short work of this using from_other
        # methods, but since BundleImage doesn't have service or
        # auth classes of its own we get to do this the hard way.
        if not self.args.get('bootstrap_service'):
            service = BootstrapRequest.SERVICE_CLASS(
                config=self.config,
                loglevel=self.log.level,
                url=self.args.get('bootstrap_url'))
            try:
                service.configure()
            except ClientError:
                self.log.debug(
                    'bootstrap service setup failed; auto cert '
                    'fetching will be unavailable',
                    exc_info=True)
            else:
                self.args['bootstrap_service'] = service
        if (not self.args.get('bootstrap_auth')
                and self.args.get('bootstrap_service')):
            auth = BootstrapRequest.AUTH_CLASS(config=self.config,
                                               loglevel=self.log.level,
                                               **self.args)
            try:
                auth.configure()
            except ClientError:
                self.log.debug(
                    'bootstrap auth setup failed; auto cert '
                    'fetching will be unavailable',
                    exc_info=True)
            else:
                self.args['bootstrap_auth'] = auth

        self.configure_bundle_creds()
        self.configure_bundle_properties()
        self.configure_bundle_output()
        self.generate_encryption_keys()
Beispiel #12
0
    def configure(self):
        BaseCommand.configure(self)
        self.update_config_view()

        # The private key could be the user's or the cloud's.  In the config
        # this is a user-level option.
        if not self.args.get('privatekey'):
            config_privatekey = self.config.get_user_option('private-key')
            if self.args.get('userregion'):
                self.args['privatekey'] = config_privatekey
            elif 'EC2_PRIVATE_KEY' in os.environ:
                self.args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
            elif config_privatekey:
                self.args['privatekey'] = config_privatekey
            else:
                raise ArgumentError(
                    'missing private key; please supply one with -k')
        self.args['privatekey'] = os.path.expanduser(
            os.path.expandvars(self.args['privatekey']))
        if not os.path.exists(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' does not exist".format(
                self.args['privatekey']))
        if not os.path.isfile(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' is not a file".format(
                self.args['privatekey']))
        self.log.debug('private key: %s', self.args['privatekey'])

        if not os.path.exists(self.args.get('source', '.')):
            raise ArgumentError("argument -s/--source: directory '{0}' does "
                                "not exist".format(self.args['source']))
        if not os.path.isdir(self.args.get('source', '.')):
            raise ArgumentError("argument -s/--source: '{0}' is not a "
                                "directory".format(self.args['source']))
        if not os.path.exists(self.args.get('destination', '.')):
            raise ArgumentError("argument -d/--destination: directory '{0}' "
                                "does not exist".format(
                                    self.args['destination']))
        if not os.path.isdir(self.args.get('destination', '.')):
            raise ArgumentError("argument -d/--destination: '{0}' is not a "
                                "directory".format(self.args['destination']))
Beispiel #13
0
    def configure(self):
        BaseCommand.configure(self)
        self.update_config_view()

        # The private key could be the user's or the cloud's.  In the config
        # this is a user-level option.
        if not self.args.get('privatekey'):
            config_privatekey = self.config.get_user_option('private-key')
            if self.args.get('userregion'):
                self.args['privatekey'] = config_privatekey
            elif 'EC2_PRIVATE_KEY' in os.environ:
                self.args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
            elif config_privatekey:
                self.args['privatekey'] = config_privatekey
            else:
                raise ArgumentError(
                    'missing private key; please supply one with -k')
        self.args['privatekey'] = os.path.expanduser(os.path.expandvars(
            self.args['privatekey']))
        if not os.path.exists(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' does not exist"
                                .format(self.args['privatekey']))
        if not os.path.isfile(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' is not a file"
                                .format(self.args['privatekey']))
        self.log.debug('private key: %s', self.args['privatekey'])

        if not os.path.exists(self.args.get('source', '.')):
            raise ArgumentError("argument -s/--source: directory '{0}' does "
                                "not exist".format(self.args['source']))
        if not os.path.isdir(self.args.get('source', '.')):
            raise ArgumentError("argument -s/--source: '{0}' is not a "
                                "directory".format(self.args['source']))
        if not os.path.exists(self.args.get('destination', '.')):
            raise ArgumentError("argument -d/--destination: directory '{0}' "
                                "does not exist"
                                .format(self.args['destination']))
        if not os.path.isdir(self.args.get('destination', '.')):
            raise ArgumentError("argument -d/--destination: '{0}' is not a "
                                "directory".format(self.args['destination']))
Beispiel #14
0
    def configure(self):
        self.update_config_view()

        BaseCommand.configure(self)

        # Set up access to bootstrap in case we need auto cert fetching.
        #
        # We would normally make short work of this using from_other
        # methods, but since BundleImage doesn't have service or
        # auth classes of its own we get to do this the hard way.
        if not self.args.get('bootstrap_service'):
            service = BootstrapRequest.SERVICE_CLASS(
                config=self.config, loglevel=self.log.level,
                url=self.args.get('bootstrap_url'))
            try:
                service.configure()
            except ClientError:
                self.log.debug('bootstrap service setup failed; auto cert '
                               'fetching will be unavailable', exc_info=True)
            else:
                self.args['bootstrap_service'] = service
        if (not self.args.get('bootstrap_auth') and
                self.args.get('bootstrap_service')):
            auth = BootstrapRequest.AUTH_CLASS(
                config=self.config, loglevel=self.log.level, **self.args)
            try:
                auth.configure()
            except ClientError:
                self.log.debug('bootstrap auth setup failed; auto cert '
                               'fetching will be unavailable', exc_info=True)
            else:
                self.args['bootstrap_auth'] = auth

        self.configure_bundle_creds()
        self.configure_bundle_properties()
        self.configure_bundle_output()
        self.generate_encryption_keys()
Beispiel #15
0
    def configure(self):
        self.update_config_view()

        BaseCommand.configure(self)

        self.configure_bundle_creds()
        self.configure_bundle_properties()
        self.configure_bundle_output()
        self.generate_encryption_keys()

        if self.args.get('check_cert'):
            # We would normally make short work of this using from_other
            # methods, but since BundleImage doesn't have service or
            # auth classes of its own we get to do this the hard way.
            if not self.args.get('iam_service'):
                self.args['iam_service'] = \
                    IAMRequest.SERVICE_CLASS(
                        config=self.config, loglevel=self.log.level,
                        url=self.args.get('iam_url'))
            if not self.args.get('iam_auth'):
                self.args['iam_auth'] = \
                    IAMRequest.AUTH_CLASS(
                        config=self.config, loglevel=self.log.level,
                        **self.args)
Beispiel #16
0
    def configure(self):
        BaseCommand.configure(self)
        set_userregion(self.config, self.args.get('userregion'))
        set_userregion(self.config, os.getenv('EUCA_REGION'))

        if not self.args.get('privatekey'):
            config_privatekey = self.config.get_user_option('private-key')
            if self.args.get('userregion'):
                self.args['privatekey'] = config_privatekey
            elif 'EC2_PRIVATE_KEY' in os.environ:
                self.args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
            elif config_privatekey:
                self.args['privatekey'] = config_privatekey
            else:
                raise ArgumentError(
                    'missing private key; please supply one with -k')
        self.args['privatekey'] = os.path.expanduser(os.path.expandvars(
            self.args['privatekey']))
        if not os.path.exists(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' does not exist"
                                .format(self.args['privatekey']))
        if not os.path.isfile(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' is not a file"
                                .format(self.args['privatekey']))
Beispiel #17
0
    def configure(self):
        BaseCommand.configure(self)
        set_userregion(self.config, self.args.get('userregion'))
        set_userregion(self.config, os.getenv('EUCA_REGION'))

        if not self.args.get('privatekey'):
            config_privatekey = self.config.get_user_option('private-key')
            if self.args.get('userregion'):
                self.args['privatekey'] = config_privatekey
            elif 'EC2_PRIVATE_KEY' in os.environ:
                self.args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
            elif config_privatekey:
                self.args['privatekey'] = config_privatekey
            else:
                raise ArgumentError(
                    'missing private key; please supply one with -k')
        self.args['privatekey'] = os.path.expanduser(
            os.path.expandvars(self.args['privatekey']))
        if not os.path.exists(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' does not exist".format(
                self.args['privatekey']))
        if not os.path.isfile(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' is not a file".format(
                self.args['privatekey']))
 def configure(self):
     BaseCommand.configure(self)
     self.update_config_view()
Beispiel #19
0
    def configure(self):
        BaseCommand.configure(self)
        self.update_config_view()

        #Get the mandatory private key...
        if not self.args.get('privatekey'):
            config_privatekey = self.config.get_user_option('private-key')
            if self.args.get('userregion'):
                self.args['privatekey'] = config_privatekey
            elif 'EC2_PRIVATE_KEY' in os.environ:
                self.args['privatekey'] = os.getenv('EC2_PRIVATE_KEY')
            elif config_privatekey:
                self.args['privatekey'] = config_privatekey
            else:
                raise ArgumentError(
                    'missing private key; please supply one with -k')
        self.args['privatekey'] = os.path.expanduser(os.path.expandvars(
            self.args['privatekey']))
        if not os.path.exists(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' does not exist"
                                .format(self.args['privatekey']))
        if not os.path.isfile(self.args['privatekey']):
            raise ArgumentError("private key file '{0}' is not a file"
                                .format(self.args['privatekey']))

        #Get optional source directory...
        source = self.args['source']
        if source != "-":
            source = os.path.expanduser(os.path.abspath(source))
            if not os.path.exists(source):
                raise ArgumentError("source directory '{0}' does not exist"
                                    .format(self.args['source']))
            if not os.path.isdir(source):
                raise ArgumentError("source '{0}' is not a directory"
                                    .format(self.args['source']))
        self.args['source'] = source

        #Get optional destination directory...
        dest_dir = self.args['destination']
        if dest_dir != "-":
            dest_dir = os.path.expanduser(os.path.abspath(dest_dir))
            if not os.path.exists(dest_dir):
                raise ArgumentError("destination directory '{0}' does"
                                    " not exist".format(dest_dir))
            if not os.path.isdir(dest_dir):
                raise ArgumentError("destination '{0}' is not a directory"
                                    .format(dest_dir))
        self.args['destination'] = dest_dir

        #Get Mandatory manifest...
        if not isinstance(self.args.get('manifest'), BundleManifest):
            manifest_path = os.path.expanduser(os.path.abspath(
                self.args['manifest']))
            if not os.path.exists(manifest_path):
                raise ArgumentError("Manifest '{0}' does not exist"
                                    .format(self.args['manifest']))
            if not os.path.isfile(manifest_path):
                raise ArgumentError("Manifest '{0}' is not a file"
                                    .format(self.args['manifest']))
                #Read manifest into BundleManifest obj...
            self.args['manifest'] = (BundleManifest.
                                     read_from_file(manifest_path,
                                                    self.args['privatekey']))

        self.args['maxbytes'] = int(self.args.get('maxbytes', 0))