def do_event_show(cc, args={}):
    '''Show a event log.'''
    try:
        log = cc.event_log.get(args.event_log)
    except exc_common.HTTPNotFound:
        raise exc.CommandError('Event log not found: %s' % args.event_log)
    else:
        _display_event(log)
Beispiel #2
0
def do_alarm_show(cc, args={}):
    '''Show an active alarm.'''
    try:
        fault = cc.alarm.get(args.alarm)
    except exc_common.HTTPNotFound:
        raise exc.CommandError('Alarm not found: %s' % args.alarm)
    else:
        _display_fault(fault)
Beispiel #3
0
 def do_help(self, args):
     """Display help about this program or one of its subcommands."""
     if getattr(args, 'command', None):
         if args.command in self.subcommands:
             self.subcommands[args.command].print_help()
         else:
             raise exc.CommandError("'%s' is not a valid subcommand" %
                                    args.command)
     else:
         self.parser.print_help()
Beispiel #4
0
    def main(self, argv):
        # Parse args once to find version
        parser = self.get_base_parser()
        (options, args) = parser.parse_known_args(argv)
        self._setup_debugging(options.debug)

        # build available subcommands based on version
        api_version = options.fm_api_version
        subcommand_parser = self.get_subcommand_parser(api_version)
        self.parser = subcommand_parser

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line
        if options.help or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        if not (args.os_auth_token and args.fm_url):
            if not args.os_username:
                raise exc.CommandError("You must provide a username via "
                                       "either --os-username or via "
                                       "env[OS_USERNAME]")

            if not args.os_password:
                raise exc.CommandError("You must provide a password via "
                                       "either --os-password or via "
                                       "env[OS_PASSWORD]")

            if not (args.os_project_id or args.os_project_name):
                raise exc.CommandError("You must provide a project name via "
                                       "either --os-project-name or via "
                                       "env[OS_PROJECT_NAME]")

            if not args.os_auth_url:
                raise exc.CommandError("You must provide an auth url via "
                                       "either --os-auth-url or via "
                                       "env[OS_AUTH_URL]")

            if not args.os_region_name:
                raise exc.CommandError("You must provide an region name via "
                                       "either --os-region-name or via "
                                       "env[OS_REGION_NAME]")

        client_args = ('os_auth_token', 'fm_url', 'os_username', 'os_password',
                       'os_auth_url', 'os_project_id', 'os_project_name',
                       'os_tenant_id', 'os_tenant_name', 'os_region_name',
                       'os_user_domain_id', 'os_user_domain_name',
                       'os_project_domain_id', 'os_project_domain_name',
                       'os_service_type', 'os_endpoint_type', 'timeout')
        kwargs = {}
        for key in client_args:
            client_key = key.replace("os_", "", 1)
            kwargs[client_key] = getattr(args, key)

        client = fmclient.client.get_client(api_version, **kwargs)

        try:
            args.func(client, args)
        except exc.Unauthorized:
            raise exc.CommandError("Invalid Identity credentials.")
Beispiel #5
0
def do_alarm_delete(cc, args={}):
    '''Delete an active alarm.'''
    try:
        cc.alarm.delete(args.alarm)
    except exc_common.HTTPNotFound:
        raise exc.CommandError('Alarm not found: %s' % args.alarm)