Esempio n. 1
0
 def test_get_separate(self, mock_getenv):
     mock_getenv.side_effect = self.FAKE_ENV2.get
     host, port, user, pass_, path, tls = client.get_auth_from_env()
     self.assertEqual('192.168.1.2', host)
     self.assertEqual(6443, port)
     self.assertEqual('user', user)
     self.assertEqual('pass', pass_)
     self.assertFalse(tls)
Esempio n. 2
0
 def test_get_auth_combined_tls(self, mock_getenv):
     tls_env = dict(self.FAKE_ENV1)
     tls_env['MFI'] = tls_env['MFI'].replace('http://', 'https://')
     mock_getenv.side_effect = tls_env.get
     host, port, user, pass_, path, tls = client.get_auth_from_env()
     self.assertEqual('192.168.1.1', host)
     self.assertEqual(6443, port)
     self.assertEqual('user', user)
     self.assertEqual('pass', pass_)
     self.assertTrue(tls)
Esempio n. 3
0
    def main(self):
        try:
            requests.packages.urllib3.disable_warnings()
        except:
            pass
        commands = [x[4:] for x in dir(self) if x.startswith('cmd')]
        command_list = os.linesep + os.linesep.join(commands)

        parser = argparse.ArgumentParser()
        parser.add_argument('command', help='One of: %s' % command_list)
        parser.add_argument('--device', help='Specific device')
        parser.add_argument('--property',
                            help='Show only this property of a device')
        parser.add_argument('--state', help='State to set (on or off)')
        parser.add_argument('--every',
                            type=int,
                            default=0,
                            help='Repeat (interval in seconds)')
        parser.add_argument('--since',
                            type=int,
                            default=60,
                            metavar='SECS',
                            help='Show data since SECS seconds ago')
        parser.add_argument('--column-headers',
                            default=False,
                            action='store_true',
                            help='Show CSV column headers')
        parser.add_argument('--json',
                            default=False,
                            action='store_true',
                            help='Output raw JSON for the raw_ commands')
        parser.add_argument('--noverify',
                            default=False,
                            action='store_true',
                            help='Do not verify server SSL certificate')
        args = parser.parse_args()

        if not hasattr(self, 'cmd_%s' % args.command):
            print('No such command `%s\'' % args.command)
            return 1

        host, port, user, _pass, path, tls = client.get_auth_from_env()
        self._client = client.MFiClient(host,
                                        user,
                                        _pass,
                                        port=port,
                                        use_tls=tls,
                                        verify=not args.noverify)

        while True:
            getattr(self, 'cmd_%s' % args.command)(args)
            if not args.every:
                break
            time.sleep(args.every)
Esempio n. 4
0
    def main(self):
        try:
            requests.packages.urllib3.disable_warnings()
        except:
            pass
        commands = [x[4:] for x in dir(self) if x.startswith('cmd')]
        command_list = os.linesep + os.linesep.join(commands)

        parser = argparse.ArgumentParser()
        parser.add_argument('command',
                            help='One of: %s' % command_list)
        parser.add_argument('--device',
                            help='Specific device')
        parser.add_argument('--property',
                            help='Show only this property of a device')
        parser.add_argument('--state',
                            help='State to set (on or off)')
        parser.add_argument('--every', type=int, default=0,
                            help='Repeat (interval in seconds)')
        parser.add_argument('--since', type=int, default=60,
                            metavar='SECS',
                            help='Show data since SECS seconds ago')
        parser.add_argument('--column-headers', default=False,
                            action='store_true',
                            help='Show CSV column headers')
        parser.add_argument('--json', default=False,
                            action='store_true',
                            help='Output raw JSON for the raw_ commands')
        parser.add_argument('--noverify', default=False,
                            action='store_true',
                            help='Do not verify server SSL certificate')
        args = parser.parse_args()

        if not hasattr(self, 'cmd_%s' % args.command):
            print('No such command `%s\'' % args.command)
            return 1

        host, port, user, _pass, path, tls = client.get_auth_from_env()
        self._client = client.MFiClient(host, user, _pass, port=port,
                                        use_tls=tls, verify=not args.noverify)

        while True:
            getattr(self, 'cmd_%s' % args.command)(args)
            if not args.every:
                break
            time.sleep(args.every)