def create(self): """Saves a new "apps" table entry in the database for the app represented by this App-object. """ if self.enabled is None: self.enabled = False client.get_autoscaler() \ .import_app(self.app_id, app_id=self.app_id, app_name=self.app_name, space_id=self.space_id, time_created=util.unix_time(), enabled=self.enabled)\ .assert_no_error() return self
def redirect_http_to_https(): xfp = request.headers.get('x-forwarded-proto', None) if request.url.startswith( 'http://') and 'https' != xfp and xfp is not None: url = request.url.replace('http://', 'https://', 1) return redirect(url, code=301) if request.path in routes_whitelist: return if request.path.startswith(('/static/js/', '/static/css/', '/socket.io/')): return cli = client.get_autoscaler() session_token = request.args.get('t', None) if session_token: resp = cli.verify_user_session(session_token) if resp.has_error: print(resp._response_text) return redirect('/signin') resp = redirect(request.path) resp.set_cookie('session', session_token, secure=True) return make_response(resp) if not helpers.is_logged_in(): return redirect('/signin')
def list_my_apps(cls): """Lists all apps imported into the database. Returns: App """ apps = client.get_autoscaler().get_apps().result return _wrap(apps, cls)
def list_available_apps(cls): """Lists all apps in the current org / space that are _not_ imported into the database. Returns: App """ apps = client.get_autoscaler().get_available_apps().result return _wrap(apps, cls)
def get_current_stats(self, **kwargs): """Gets the _list_ of Cloud Foundry performance metrics for each "instance" in the deployment for this app _directly_ from the Cloud Foundry API. Returns: list[AppStats] """ stats = client.get_autoscaler() \ .get_app_stats_current(self.app_id, **kwargs).result return _wrap(stats, AppStats)
def find_by_id(cls, app_id, **kwargs): """Looks up the app object from the "apps" table in the database. Does _not_ load from Cloud Foundry. Args: app_id (str) Returns: App """ app = client.get_autoscaler().get_app(app_id, **kwargs).result return App(app)
def scale(self, **kwargs): """Scales the app according to the provided values. All specified values of `memory`, `disk`, or `num_instances` will be updated. If no values are specified, then the autoscaling algorithm will be used to scale the app. Note that the app _will_ be restarted if `memory` or `disk` change. Keyword Args: memory (int): Units are MB disk (int): Units are MB num_instances (int) """ return client.get_autoscaler().scale_app(self.app_id, **kwargs).result
def _load_app_view_details(app): scaling_num_instances = config.get_scaling_num_instances(app) autoscaler_name = request.form.get('autoscaler') scaling_config = client.get_autoscaler()\ .get_scaling_config_html(app.app_id, autoscaler=autoscaler_name).data return dict(title=app.app_name, app=app, scaling_num_instances=scaling_num_instances, scaling_memory=config.scaling_memory, scaling_disk=config.scaling_disk, autoscaler_name=autoscaler_name, scaling_config=scaling_config)
def get_history_stats(self, **kwargs): """Gets recently saved stats for this app from the database _not_ the Cloud Foundry API. Similar to `get_cf_stats`. Keyword Args: time_interval (int): the number of seconds before now to query for stats. """ stats = client.get_autoscaler() \ .get_app_stats_history( self.app_id, **kwargs).result return _wrap(stats, AppStats)
def save_enabled(self, enabled=None): """Saves into the database whether this app is enabled for autoscaling or not. """ self._assert_app_id() if isinstance(enabled, bool): cli = client.get_autoscaler() if enabled: resp = cli.enable_app(self.app_id) else: resp = cli.disable_app(self.app_id) resp.assert_no_error() return self
def update_cf(self, **kwargs): """Updates the Cloud Foundry API with the properties in the `params` dict. See the Cloud Foundry API for valid parameter keys and values. "params" are passed _directly_ to the Cloud Foundry API. Keyword Args: dict Returns: dict """ return client.get_autoscaler() \ .update_app(self.app_id, **kwargs) \ .assert_no_error()
def remove(self): """Removes this app entry from the "apps" table in the database. Does nothing else. """ return client.get_autoscaler() \ .delete_app(self.app_id).result
def view_config(): """Displays a brief summary of the configuration data for this autoscaler. """ cf_config = client.get_autoscaler().get_space_config().result return render_template('config.html', config=config, cf_config=cf_config)
def save_app(app): form = {key: val for key, val in request.form.items()} cli = client.get_autoscaler() return cli.update_app(app.app_id, **form).result
def scale_app(app_id): cli = client.get_autoscaler() return cli.scale_app(app_id, **form_as_dict()).result
def import_app(app_id): cli = client.get_autoscaler() return cli.import_app(app_id).result
def get_history(app_id, **kwargs): stats = client.get_autoscaler()\ .get_app_stats_history(app_id, **kwargs).result return _wrap(stats, AppStats)
def register_with_api(): client.get_autoscaler().register_app_with_space().assert_no_error()