def subscription(ctx, action, subscription_id, declaration, account_id_filter): """ command """ # 'update' requires declaration if action == 'update' and declaration is None: raise click.ClickException('The --declaration option is required') # 'show' and 'update require subscription id if action in ['show', 'update'] and subscription_id is None: raise click.ClickException('The --subscription-id option is required') subscription_client = SubscriptionClient(get_mgmt_client()) if action == 'list': kwargs = {} if account_id_filter: kwargs['query_parameters'] = {'account_id': account_id_filter} ctx.log(subscription_client.list(**kwargs)) elif action == 'show': ctx.log(subscription_client.show(name=subscription_id)) elif action == 'update': ctx.log( subscription_client.update( name=subscription_id, config_file=utils_core.convert_to_absolute(declaration))) else: raise click.ClickException( f"Action {action} not implemented for 'subscription' command")
def token_create(ctx, declaration): """ command """ token_client = TokenClient(get_mgmt_client()) ctx.log( token_client.create( config_file=utils_core.convert_to_absolute(declaration)))
def insights_update(ctx, declaration): """ command """ insights_client = InsightsClient(get_mgmt_client()) ctx.log( insights_client.create( config_file=utils_core.convert_to_absolute(declaration)))
def service(ctx, action, component, version, declaration, install_component): """ command """ auth = AuthConfigurationClient().read_auth(constants.AUTHENTICATION_PROVIDERS['BIGIP']) management_kwargs = dict(port=auth['port'], user=auth['user'], password=auth['password']) client = ManagementClient(auth['host'], **management_kwargs) kwargs = {} if version: kwargs['version'] = version extension_client = ExtensionClient(client, component, **kwargs) # intent based - support install in 'service' sub-command # install extension component if requested (and not installed) if install_component and not extension_client.package.is_installed()['installed']: extension_client.package.install() extension_client.service.is_available() try: if action == 'show': ctx.log(extension_client.service.show()) elif action == 'create': ctx.log(_process_create(component, extension_client, declaration)) elif action == 'delete': ctx.log(extension_client.service.delete()) elif action == 'show-info': ctx.log(extension_client.service.show_info()) elif action == 'show-failover': ctx.log(extension_client.service.show_trigger()) elif action == 'trigger-failover': ctx.log(extension_client.service.trigger( config_file=utils_core.convert_to_absolute(declaration))) elif action == 'show-inspect': ctx.log(extension_client.service.show_inspect()) elif action == 'reset': ctx.log(extension_client.service.reset( config_file=utils_core.convert_to_absolute(declaration))) else: raise click.ClickException('Action not implemented') except Exception as error: raise click.ClickException(error)
def reset_service(self, declaration_file): """Reset service Parameters ---------- declaration_file : str the declaration file to use Returns ------- None """ return self._extension_client.service.reset( config_file=utils_core.convert_to_absolute(declaration_file))
def trigger_failover_service(self, declaration_file): """Trigger service Parameters ---------- declaration_file : str the declaration file to use Returns ------- None """ return self._extension_client.service.trigger( config_file=utils_core.convert_to_absolute(declaration_file))
def create_service(self, declaration_file): """Create service Parameters ---------- declaration_file : str the declaration file to use Returns ------- None """ if not self._extension_client.package.is_installed()['installed']: return ("Package is not installed, run command " "'f5 bigip extension <component> install'") return self._extension_client.service.create( config_file=utils_core.convert_to_absolute(declaration_file))
def subscription(ctx, action, subscription_id, declaration): """ Performs actions against a F5 Cloud Services subscription Parameters ---------- action : str which action to perform subscription_id : str which subscription to perform the requested action on declaration : str file name or path to file of declaration to send to F5 Cloud Services Returns ------- str the response for the requested action against the F5 Cloud Services subscription """ # Additional option validation if action == 'update' and declaration is None: raise click.ClickException( 'The --declaration option is required when updating a Cloud Services subscription' ) auth = AuthConfigurationClient().read_auth( constants.AUTHENTICATION_PROVIDERS[ constants.CLOUD_SERVICES_GROUP_NAME]) mgmt_client = ManagementClient(user=auth['user'], password=auth['password'], api_endpoint=auth.pop('api_endpoint', None)) subscription_client = SubscriptionClient(mgmt_client) if action == 'show': ctx.log(subscription_client.show(name=subscription_id)) elif action == 'update': ctx.log( subscription_client.update( name=subscription_id, config_file=utils_core.convert_to_absolute(declaration))) else: raise click.ClickException( f"Action {action} not implemented for 'subscription' command")
def _process_create(component, extension_client, declaration): if not extension_client.package.is_installed()['installed']: return ("Package is not installed, run command " "'f5 bigip extension package install --component %s'" % component) return extension_client.service.create( config_file=utils_core.convert_to_absolute(declaration))
def declare_create(ctx, declaration): """ command """ client = DeclareClient(get_mgmt_client()) ctx.log( client.create(config_file=utils_core.convert_to_absolute(declaration)))
def test_convert_absolute_path(mocker): """ Test absolute path """ mock_getcwd = mocker.patch("f5cli.utils.core.os.getcwd") mock_getcwd.return_value = "/test/current/directory" result = core_utils.convert_to_absolute("fake.txt") assert result == "/test/current/directory/fake.txt"