def update_targets(self, sources, destinations, services): source = Source() destination = Destination() service = Service() if sources is not None: if isinstance(sources, str) and sources.lower() == "any": source.set_any() else: source.add_many(sources) else: source.set_none() if destinations is not None: if isinstance(destinations, str) and destinations.lower() == "any": destination.set_any() else: destination.add_many(destinations) else: destination.set_none() if services is not None: if isinstance(services, str) and services.lower() == "any": service.set_any() else: service.add_many(services) else: service.set_none() e = {} e.update(sources=source.data) e.update(destinations=destination.data) e.update(services=service.data) return e
def services(self): """ Services assigned to this rule :rtype: Service """ return Service(self)
def services(self): """ Services assigned to this rule :return: :py:class:`smc.policy.rule_elements.Service` """ return Service(self.data.get('services'))
def test_services(self): service = Service(data={'any': True}) source = Source() dest = Destination() self.assertEqual(service.data, {'any': True}) self.assertEqual(source.data, {'none': True}) self.assertEqual(dest.data, {'none': True}) source.set_any() self.assertTrue(source.is_any) source.set_none() self.assertTrue(source.is_none) source.add('http://1.1.1.1') self.assertEqual(source.data, {'src': ['http://1.1.1.1']}) source.set_none() source.add_many(['http://1.1.1.1', 'http://2.2.2.2']) self.assertEqual(source.data, {'src': ['http://1.1.1.1', 'http://2.2.2.2']}) self.assertEqual(source.all_as_href(), ['http://1.1.1.1', 'http://2.2.2.2']) o = service() self.assertIsNotNone(o.get('services')) o = source() self.assertIsNotNone(o.get('sources')) o = dest() self.assertIsNotNone(o.get('destinations'))
def update_targets(self, sources, destinations, services): source = Source() destination = Destination() service = Service() if sources is not None: if isinstance(sources, str) and sources.lower() == 'any': source.set_any() else: source.add_many(sources) else: source.set_none() if destinations is not None: if isinstance(destinations, str) and destinations.lower() == 'any': destination.set_any() else: destination.add_many(destinations) else: destination.set_none() if services is not None: if isinstance(services, str) and services.lower() == 'any': service.set_any() else: service.add_many(services) else: service.set_none() e = {} #e.update(source()) e.update(sources=source.data) e.update(destinations=destination.data) e.update(services=service.data) return e
def _rule_common(sources, destinations, services): """ Common rule elements """ source = Source() destination = Destination() service = Service() if sources is not None: if isinstance(sources, str) and sources.lower() == 'any': source.set_any() else: source.add_many(sources) else: source.set_none() if destinations is not None: if isinstance(destinations, str) and destinations.lower() == 'any': destination.set_any() else: destination.add_many(destinations) else: destination.set_none() if services is not None: if isinstance(services, str) and services.lower() == 'any': service.set_any() else: service.add_many(services) else: service.set_none() e = {} e.update(source()) e.update(destination()) e.update(service()) return e