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
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']))
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')
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
def _post_init(self): if self.service is None and self.SERVICE_CLASS is not None: self.service = self.SERVICE_CLASS(self.config, loglevel=self.log.level) if self.auth is None and self.AUTH_CLASS is not None: # pylint: disable=not-callable self.auth = self.AUTH_CLASS(self.config, loglevel=self.log.level) # pylint: enable=not-callable BaseCommand._post_init(self)
def handle_cli_exception(self, err): if isinstance(err, ServerError): msg = '{0}: {1}'.format(os.path.basename(sys.argv[0]), err.format_for_cli()) print(msg, file=sys.stderr) if self.debug: raise sys.exit(1) else: BaseCommand.handle_cli_exception(self, err)
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()
def handle_cli_exception(self, err): if isinstance(err, ServerError): msg = '{0}: {1}'.format(os.path.basename(sys.argv[0]), err.format_for_cli()) print >> sys.stderr, msg if self.debug: raise sys.exit(1) else: BaseCommand.handle_cli_exception(self, err)
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')
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 __init__(self, service=None, auth=None, **kwargs): self.auth = auth self.service = service # Parts of the HTTP request to be sent to the server. self.method = self.METHOD self.path = None self.headers = {} self.params = {} self.body = '' self.files = {} # HTTP response obtained from the server self.response = None self.__configured = False BaseCommand.__init__(self, **kwargs)
def __init__(self, service=None, auth=None, **kwargs): # Parts of the HTTP request to be sent to the server. self.method = self.METHOD self.path = None self.headers = {} self.params = {} self.body = '' self.files = {} # HTTP response obtained from the server self.response = None self.__configured = False self.__auth = auth self.__service = service BaseCommand.__init__(self, **kwargs)
def _post_init(self): if self.service is None and self.SERVICE_CLASS is not None: self.service = self.SERVICE_CLASS(self.config, loglevel=self.log.level) if self.auth is None: if self.AUTH_CLASS is not None: self.auth = self.AUTH_CLASS(self.config, loglevel=self.log.level) elif self.SERVICE_CLASS.AUTH_CLASS is not None: # Backward compatibility msg = ('BaseService.AUTH_CLASS is deprecated; use ' 'BaseRequest.AUTH_CLASS instead') self.log.warn(msg) warnings.warn(msg, DeprecationWarning) self.auth = self.SERVICE_CLASS.AUTH_CLASS( self.config, loglevel=self.log.level) BaseCommand._post_init(self)
def collect_arg_objs(self): arg_objs = BaseCommand.collect_arg_objs(self) if self.service is not None: arg_objs.extend( aggregate_subclass_fields(self.service.__class__, 'ARGS')) if self.auth is not None: arg_objs.extend( aggregate_subclass_fields(self.auth.__class__, 'ARGS')) return arg_objs
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()
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']))
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']))
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()
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)
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) 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 distribute_args(self): BaseCommand.distribute_args(self) if self.service is not None: self.service.args.update(self.args) if self.auth is not None: self.auth.args.update(self.args)
def configure(self): BaseCommand.configure(self) self.update_config_view()
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))