def _convert_period_to_timestamp(self, period): if period is None: return None try: _ = datetime.datetime.fromtimestamp(int(period)) return int(period) except: pass units = { "s": "seconds", "m": "minutes", "h": "hours", "d": "days", "w": "weeks" } try: count = period[:-1] unit = period[-1] except: raise exceptions.CoriolisException("Failed to parse period") conv_unit = units.get(unit) if conv_unit is None: raise exceptions.CoriolisException("invalid period %s" % period) args = {conv_unit: count} tm = datetime.datetime.utcnow() - datetime.timedelta(**args) return int(tm.timestamp())
def _parse_expiration_date(value): if value is None: return try: return timeutils.normalize_time(timeutils.parse_isotime(value)) except Exception as err: raise exceptions.CoriolisException("Invalid expiration date: %s" % err)
def take_action(self, args): parsed_schedule = _parse_schedule_group_args(args) if not any(parsed_schedule): raise exceptions.CoriolisException( "Please provide at least one value in the Schedule group") exp = _parse_expiration_date(args.expires_at) schedule = self.app.client_manager.coriolis.replica_schedules.create( args.replica, parsed_schedule, args.disabled is False, exp, args.shutdown_instance) return ReplicaScheduleDetailFormatter().get_formatted_entity(schedule)
def take_action(self, args): if args.connection_secret and args.connection: raise exceptions.CoriolisException( "Please specify either --connection or " "--connection-secret, but not both") conn_info = None if args.connection_secret: conn_info = {"secret_ref": args.connection_secret} if args.connection: conn_info = json.loads(args.connection) endpoint = self.app.client_manager.coriolis.endpoints.create( args.name, args.provider, conn_info, args.description) return EndpointDetailFormatter().get_formatted_entity(endpoint)
def download_logs(self, app, to, start_time=None, end_time=None): if app == "": raise exceptions.CoriolisException("missing app_name") headers = self._auth_headers args = { "start_date": self._convert_period_to_timestamp(start_time), "end_date": self._convert_period_to_timestamp(end_time), } resource = "logs/%s/" % app url = self._construct_url(resource, args) with requests.get(url, headers=headers, stream=True) as r: r.raise_for_status() with open(to, 'wb') as fd: for chunk in r.iter_content(chunk_size=8192): if chunk: fd.write(chunk)
def take_action(self, args): if args.connection_secret and args.connection: raise exceptions.CoriolisException( "Please specify either --connection or " "--connection-secret, but not both") conn_info = get_connnection_info_from_args(args, raise_if_none=False) updated_values = {} if args.name is not None: updated_values["name"] = args.name if args.description is not None: updated_values["description"] = args.description if conn_info: updated_values["connection_info"] = conn_info if args.regions: updated_values["mapped_regions"] = args.regions endpoint = self.app.client_manager.coriolis.endpoints.update( args.id, updated_values) return EndpointDetailFormatter().get_formatted_entity(endpoint)
def take_action(self, args): if args.connection_secret and args.connection: raise exceptions.CoriolisException( "Please specify either --connection or " "--connection-secret, but not both") conn_info = get_connnection_info_from_args(args) endpoint = self.app.client_manager.coriolis.endpoints.create( args.name, args.provider, conn_info, args.description, regions=args.regions) if not args.skip_validation: valid, message = ( self.app.client_manager.coriolis.endpoints.validate_connection( endpoint.id)) if not valid: raise exceptions.EndpointConnectionValidationFailed(message) return EndpointDetailFormatter().get_formatted_entity(endpoint)
def take_action(self, args): if args.connection_secret and args.connection: raise exceptions.CoriolisException( "Please specify either --connection or " "--connection-secret, but not both") conn_info = None if args.connection_secret: conn_info = {"secret_ref": args.connection_secret} if args.connection: conn_info = json.loads(args.connection) updated_values = {} if args.name is not None: updated_values["name"] = args.name if args.description is not None: updated_values["description"] = args.description if conn_info: updated_values["connection_info"] = conn_info endpoint = self.app.client_manager.coriolis.endpoints.update( args.id, updated_values) return EndpointDetailFormatter().get_formatted_entity(endpoint)