usage = "list all vpns in an environment" parser = OptionParser(usage=usage) parser.add_option("-e", "--env", "--environment", action="store", type="string", dest="env", help="environment to run job in eg:[ dev | ci1 | si1 | qa1 | pt1 | prod ]") parser.add_option("-d", "--debug", action="store_true", dest="debug", default=False, help="toggles solace debug mode") (options, args) = parser.parse_args() if not options.env: parser.print_help() sys.exit() if options.debug: logging.getLogger().setLevel(logging.DEBUG) # forces read-only options.testmode = True settings.env = options.env.lower() logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode)) connection = SolaceAPI(settings.env, testmode=options.testmode) connection.manage("SolaceClientProfile") request = SolaceXMLBuilder() request.show.message_vpn.vpn_name = '*' response = connection.rpc(str(request), primaryOnly=True) for vpn in response[0]['rpc-reply']['rpc']['show']['message-vpn']['vpn']: print vpn['name']
parser.print_help() sys.exit() if not options.vpn_name: parser.print_help() sys.exit() if options.testmode: logging.info("TEST MODE ACTIVE!!!") settings.env = options.env.lower() logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode)) connection = SolaceAPI(settings.env, testmode=options.testmode) print("Available VPNS are: %s" % connection.manage(SOLACE_VPN_PLUGIN).list_vpns(vpn_name='*')) if options.queue_filter: print( "You have said that the queue mentioned is a filter, searching for queues" ) queues = connection.list_queues(options.vpn_name, queue_filter=options.queues) else: queues = options.queues.split(',') print("The following queues will be manipulated in %s environment! " % settings.env) pprint.pprint(queues) # validating the plan validate_the_plan(connection=connection,
class TestSolaceAPI(unittest.TestCase): def setUp(self): self.solace = SolaceAPI('dev') def test_connect(self): self.assertIsInstance(self.solace, SolaceAPI) def test_testmode(self): self.solace = SolaceAPI("dev", testmode=True) self.assertTrue(self.solace.testmode) def test_testmode(self): self.solace = SolaceAPI("dev", testmode=False) self.assertFalse(self.solace.testmode) def test_bad_config(self): with self.assertRaises(Exception): self.solace = SolaceAPI("bad") def test_single_node_bad_config(self): with self.assertRaises(Exception): self.solace = SolaceAPI("bad", detect_status=False) def test_single_appliance(self): self.solace = SolaceAPI("single", detect_status=False) self.assertEqual(self.solace.primaryRouter, "http://solace1.swe1.unibet.com/SEMP") def test_failed_detection(self): with self.assertRaises(Exception): self.solace = SolaceAPI("backup_only") def test_failed_detection2(self): with self.assertRaises(Exception): self.solace = SolaceAPI("primary_only") def test_bad_config_no_mgmt(self): with self.assertRaises(Exception): self.solace = SolaceAPI("bad_no_mgmt", detect_status=False) def test_backup_only_rpc(self): self.solace = SolaceAPI("dev") self.solace.rpc('<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', backupOnly=True) def test_get_redundancy(self): response = SolaceAPI("dev").get_redundancy() self.assertIsInstance(response, list) def test_get_redundancy_error(self): with self.assertRaises(Exception): response = SolaceAPI("dev", version="foo").get_redundancy() def test_get_memory(self): memory = SolaceAPI("dev").get_memory() self.assertIsInstance(memory, list) def test_plugin_response_rpc(self): p = PluginResponse('<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', primaryOnly=True) x = self.solace.rpc(p) self.assertIsInstance(x, list) def test_plugin_rpc_tuple(self, **kwargs): res = ('<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', kwargs) x = self.solace.rpc(res) self.assertIsInstance(x, list) def test_plugin_rpc_bad_request_object(self): res = [] with self.assertRaises(Exception): x = self.solace.rpc(res) def test_manage(self): x = self.solace.manage("SolaceUser") self.assertEqual(str(x.__class__), "<class 'libsolace.items.SolaceUser.SolaceUser'>")
if not options.env: parser.print_help() sys.exit() if not options.vpn_name: parser.print_help() sys.exit() if options.testmode: logging.info("TEST MODE ACTIVE!!!") settings.env = options.env.lower() logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode)) connection = SolaceAPI(settings.env, testmode=options.testmode) print("Available VPNS are: %s" % connection.manage(SOLACE_VPN_PLUGIN).list_vpns(vpn_name='*')) if options.queue_filter: print("You have said that the queue mentioned is a filter, searching for queues") queues = connection.list_queues(options.vpn_name, queue_filter=options.queues) else: queues = options.queues.split(',') print("The following queues will be manipulated in %s environment! " % settings.env) pprint.pprint(queues) # validating the plan validate_the_plan(connection=connection, vpn_name=options.vpn_name, queues=queues) s = raw_input('Do you want to continue? N/y? ') if s.lower() == 'y':
class TestSolaceAPI(unittest.TestCase): def setUp(self): self.solace = SolaceAPI('dev') def test_connect(self): self.assertIsInstance(self.solace, SolaceAPI) def test_testmode(self): self.solace = SolaceAPI("dev", testmode=True) self.assertTrue(self.solace.testmode) def test_testmode(self): self.solace = SolaceAPI("dev", testmode=False) self.assertFalse(self.solace.testmode) def test_bad_config(self): with self.assertRaises(Exception): self.solace = SolaceAPI("bad") def test_single_node_bad_config(self): with self.assertRaises(Exception): self.solace = SolaceAPI("bad", detect_status=False) def test_single_appliance(self): self.solace = SolaceAPI("single", detect_status=False) self.assertEqual(self.solace.primaryRouter, "http://solace1.swe1.unibet.com/SEMP") def test_failed_detection(self): with self.assertRaises(Exception): self.solace = SolaceAPI("backup_only") def test_failed_detection2(self): with self.assertRaises(Exception): self.solace = SolaceAPI("primary_only") def test_bad_config_no_mgmt(self): with self.assertRaises(Exception): self.solace = SolaceAPI("bad_no_mgmt", detect_status=False) def test_backup_only_rpc(self): self.solace = SolaceAPI("dev") self.solace.rpc( '<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', backupOnly=True) def test_get_redundancy(self): response = SolaceAPI("dev").get_redundancy() self.assertIsInstance(response, list) def test_get_redundancy_error(self): with self.assertRaises(Exception): response = SolaceAPI("dev", version="foo").get_redundancy() def test_get_memory(self): memory = SolaceAPI("dev").get_memory() self.assertIsInstance(memory, list) def test_plugin_response_rpc(self): p = PluginResponse( '<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', primaryOnly=True) x = self.solace.rpc(p) self.assertIsInstance(x, list) def test_plugin_rpc_tuple(self, **kwargs): res = ( '<rpc semp-version="soltr/6_0"><show><message-spool/></show></rpc>', kwargs) x = self.solace.rpc(res) self.assertIsInstance(x, list) def test_plugin_rpc_bad_request_object(self): res = [] with self.assertRaises(Exception): x = self.solace.rpc(res) def test_manage(self): x = self.solace.manage("SolaceUser") self.assertEqual(str(x.__class__), "<class 'libsolace.items.SolaceUser.SolaceUser'>")
"--debug", action="store_true", dest="debug", default=False, help="toggles solace debug mode") (options, args) = parser.parse_args() if not options.env: parser.print_help() sys.exit() if options.debug: logging.getLogger().setLevel(logging.DEBUG) # forces read-only options.testmode = True settings.env = options.env.lower() logging.info("Connecting to appliance in %s, testmode:%s" % (settings.env, options.testmode)) connection = SolaceAPI(settings.env, testmode=options.testmode) connection.manage("SolaceClientProfile") request = SolaceXMLBuilder() request.show.message_vpn.vpn_name = '*' response = connection.rpc(str(request), primaryOnly=True) for vpn in response[0]['rpc-reply']['rpc']['show']['message-vpn']['vpn']: print vpn['name']