def bigip(request, scope="module"): '''bigip fixture''' opt_bigip = request.config.getoption("--bigip") opt_username = request.config.getoption("--username") opt_password = request.config.getoption("--password") b = BigIP(opt_bigip, opt_username, opt_password) return b
def test_create_listener(): lb_service = LoadBalancerServiceBuilder() pool_builder = PoolServiceBuilder() bigips = [BigIP('10.190.5.7', 'admin', 'admin')] service = json.load(open("service.json"))["service"] try: # create partition lb_service.prep_service(service, bigips) # create BIG-IP® virtual servers pools = service["pools"] loadbalancer = service["loadbalancer"] for pool in pools: # create a service object in form expected by builder svc = {"loadbalancer": loadbalancer, "pool": pool} # create pool_builder.create_pool(svc, bigips) # delete pool_builder.delete_pool(svc, bigips) finally: lb_service.delete_partition(service, bigips)
def facts(**kwargs): result = dict() b = BigIP(kwargs['server'], kwargs['user'], kwargs['password'], kwargs['server_port']) r = b.net.route_domains.route_domain.load(name=kwargs['id'], partition=kwargs['partition']) result['id'] = r.id result['name'] = r.name result['parent'] = r.parent if hasattr(r, 'bwcPolicy'): result['bwc_policy'] = r.bwcPolicy if hasattr(r, 'connectionLimit'): result['connection_limit'] = r.connectionLimit if hasattr(r, 'description'): result['description'] = r.description if hasattr(r, 'flowEvictionPolicy'): result['evict_policy'] = r.flowEvictionPolicy if hasattr(r, 'servicePolicy'): result['service_policy'] = r.servicePolicy if hasattr(r, 'strict'): result['strict'] = r.strict if hasattr(r, 'routingProtocol'): result['routing_protocol'] = r.routingProtocol if hasattr(r, 'vlans'): result['vlans'] = r.vlans return result
def test_create_listener(): lb_service = LoadBalancerServiceBuilder() listener_builder = ListenerServiceBuilder() bigips = [BigIP('10.190.5.7', 'admin', 'admin')] service = json.load(open("service.json"))["service"] try: # create partition lb_service.prep_service(service, bigips) # create BIG-IP® virtual servers listeners = service["listeners"] loadbalancer = service["loadbalancer"] for listener in listeners: # create a service object in form expected by builder svc = {"loadbalancer": loadbalancer, "listener": listener} # create listener_builder.create_listener(svc, bigips) # validate l = listener_builder.get_listener(svc, bigips[0]) assert l.name == listener["name"] print "Created listener: " + l.name # delete listener_builder.delete_listener(svc, bigips) finally: lb_service.delete_partition(service, bigips)
def main(): from f5.bigip import BigIP b = BigIP('10.190.5.7', 'admin', 'admin') occrawler = OCCrawler(b, 'ltm/persistence') pp(occrawler.referenced) occrawler.get_referenced_configs() pp(occrawler.configs) config_writer = ConfigWriter(occrawler.configs, u"ltm/persistence") config_writer.dump_configs()
def main(): " " module = AnsibleModule(argument_spec=dict( host=dict(required=True), username=dict(required=True), password=dict(required=True), address=dict(required=False), name=dict(required=True), description=dict(required=False, default="updated by F5_sdk_LTM_node"), state=dict(required=True, choices=['present', 'absent']), partition=dict(default='Common', required=False)), check_invalid_arguments=False) name = module.params["name"] partition = module.params["partition"] description = module.params["description"] address = module.params["address"] delete_node = False if module.params["state"] == "absent": # Absent indicates a request to delete the node delete_node = True bigip = BigIP(module.params["host"], module.params["username"], module.params["password"]) obj = LTM(bigip, name, partition) if delete_node: if obj.node_exists(name, partition): obj.delete_LTM() else: obj.set_response("Asked to delete a node which does not exist") else: # State is present if obj.node_exists(name, partition): obj.update_LTM(description) else: obj.create_LTM(address, description) if obj.failure(): module.fail_json(msg=obj.get_response()) else: module.exit_json(changed=obj.get_changed_flag(), content=obj.get_response()) return
def __init__(self, args): set_log_file(args.pool_name, args.operation) self.bigip_server = args.bigip_server self.username = args.username self.password = args.password self.pool_name = args.pool_name self.operation = args.operation self.my_partition = 'Common' self.odd_even = args.odd_even if self.operation == 'disable': self.session = 'user-disabled' self.state = 'user-down' elif self.operation == 'enable': self.session = 'user-enabled' self.state = 'user-up' else: logging.info('Operation not required for getting the hostnames') self.session = None self.conn = BigIP(self.bigip_server, self.username, self.password) self.update_pool = self.conn.ltm.pools.pool.load(partition=self.my_partition, name=self.pool_name)
def tst_setup(request, symbols): print('test setup') testenv = ExecTestEnv() def tst_cleanup(): print('test cleanup') testenv.lbm.clear_proxies() exec_command(testenv.server_ssh, 'pkill -f SimpleHTTPServer', ignore_error=True) def tst_teardown(): print('test teardown') if not testenv.lbm.symbols['debug']: tst_cleanup() testenv.client_ssh.close() testenv.server_ssh.close() # create SSH conn to client testenv.client_ssh = paramiko.SSHClient() testenv.client_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) testenv.client_ssh.connect(testenv.symbols['client_public_mgmt_ip'], username=testenv.symbols['guest_username'], password=testenv.symbols['guest_password']) # create SSH conn to server testenv.server_ssh = paramiko.SSHClient() testenv.server_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) testenv.server_ssh.connect(testenv.symbols['server_public_mgmt_ip'], username=testenv.symbols['guest_username'], password=testenv.symbols['guest_password']) # testenv.bigip = BigIP(testenv.symbols['bigip_public_mgmt_ip'], testenv.symbols['bigip_username'], testenv.symbols['bigip_password']) testenv.request = request testenv.lbm = (LBaaSv1(testenv.symbols) if testenv.symbols['lbaas_version'] == 1 else LBaaSv2(testenv.symbols)) tst_cleanup() request.addfinalizer(tst_teardown) return testenv
def tst_setup(request, symbols): testenv = ExecTestEnv() def tst_teardown(): # pool delete sometimes get stuck in pending due to one or more of the # following objects existing on BIG-IP: # selfip, snat, route-domain, vxlan tunnel, gre tunnel testenv.lbm.clear_proxies() if testenv.webserver_started: exec_command(testenv.server_ssh, 'pkill -f SimpleHTTPServer') testenv.client_ssh.close() testenv.server_ssh.close() print "\ncreate SSH conn to client" testenv.client_ssh = paramiko.SSHClient() testenv.client_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) testenv.client_ssh.connect(testenv.symbols['client_public_mgmt_ip'], username=testenv.symbols['guest_username'], password=testenv.symbols['guest_password']) print "create SSH conn to server" testenv.server_ssh = paramiko.SSHClient() testenv.server_ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) testenv.server_ssh.connect(testenv.symbols['server_public_mgmt_ip'], username=testenv.symbols['guest_username'], password=testenv.symbols['guest_password']) print "bigip object" testenv.bigip = BigIP(testenv.symbols['bigip_public_mgmt_ip'], testenv.symbols['bigip_username'], testenv.symbols['bigip_password']) testenv.request = request print "LBaaSv2 with symbols" testenv.lbm = LBaaSv2(testenv.symbols) print "clear proxies" # > testenv.lbm.clear_proxies() print "test setup complete" #request.addfinalizer(tst_teardown) return testenv
def test_create_two(self): b = BigIP('192.168.1.1', 'admin', 'admin') r1 = b.ltm.rules.rule r2 = b.ltm.rules.rule assert r1 is not r2
def FakeBigIP(): FBIP = BigIP('FakeHostName', 'admin', 'admin') FBIP.icontrol = mock.MagicMock() return FBIP
def peer(opt_peer, opt_username, opt_password, scope="module"): '''peer bigip fixture''' p = BigIP(opt_peer, opt_username, opt_password) return p
def login(self): "Connect to the BigIP" self.bigip = BigIP(self.hostname, self.username, self.password) return
def test_create_two(self): b = BigIP('192.168.1.1', 'admin', 'admin') templ1 = b.sys.applications.customstats.customstat templ2 = b.sys.applications.customstats.customstat assert templ1 is not templ2
def test_create_two(self): b = BigIP('192.168.1.1', 'admin', 'admin') templ1 = b.sys.applications.templates.template templ2 = b.sys.applications.templates.template assert templ1 is not templ2
def bigip(opt_bigip, opt_username, opt_password, scope="module"): '''bigip fixture''' b = BigIP(opt_bigip, opt_username, opt_password) return b
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from f5.bigip import BigIP from f5.bigip.mixins import LazyAttributesRequired bigip = BigIP('10.190.5.7', 'admin', 'admin') nat1 = bigip.ltm.natcollection.nat nat2 = bigip.ltm.natcollection.nat try: nat1.create(name='za_test_001', partition='Common', originatingAddress='192.168.3.1', translationAddress='192.168.3.2') except LazyAttributesRequired as LAR: raise nat2.load(partition='Common', name='za_test_001') nat2.update(arp=u'disabled') nc = bigip.ltm.natcollection # print(nc.__dict__) print('******') CRLUDs = nc.get_collection()
def test_setlog_level(): RealBIP = BigIP('FakeHostName', 'admin', 'admin', loglevel=logging.DEBUG) iCRS = RealBIP._meta_data['icr_session'] iCRS.session.get('http://httpbin.org/headers')
#!/usr/bin/env python from f5.bigip import BigIP import csv bigip = BigIP("172.30.4.16", "admin", "password") #open nodes.txt document and turn into an array def open_csv(): with open('vs-input.csv', 'rb') as csvfile: vs_reader = csv.reader(csvfile, delimiter=' ', quotechar='|') for row in vs_reader: sendrow = ','.join(row) vs_list = sendrow.split(',') get_val(vs_list) def get_val(Node_Val): # Node_Val = x.split() vs_name = Node_Val[0] vs_dest = Node_Val[1] vs_port = Node_Val[3] vs_pool = Node_Val[5] #vs_profile = Node_Val[4] if vs_port == '80': vs_create_http(vs_name, vs_dest, vs_port, vs_pool) elif vs_port == '443': vs_create_https(vs_name, vs_dest, vs_port, vs_pool) #Create pools def vs_create_http (vs_name, vs_dest, vs_port, vs_pool): vs1 = bigip.ltm.virtuals.virtual.create(name=vs_name, partition='Common', destination=vs_dest+':'+vs_port, pool=vs_pool, rules='http_to_https', sourceAddressTranslation={'type':'automap'})
def test_create_two(self): b = BigIP('192.168.1.1', 'admin', 'admin') n1 = b.ltm.nats.nat n2 = b.ltm.nats.nat assert n1 is not n2
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from f5.bigip import BigIP from f5_openstack_agent.lbaasv2.drivers.bigip.cluster_manager import\ ClusterManager device_name = 'host-vm-26.int.lineratesystems.com' mgmt_ip = '10.190.5.7' bigip = BigIP(mgmt_ip, 'admin', 'admin') cm = ClusterManager() def test_device_name(): assert cm.get_device_name(bigip) == device_name def test_devices(): devices = cm.devices(bigip) assert len(devices) == 1 assert devices[0].managementIp == mgmt_ip def test_get_sync_status(): # expect Standalone
from pytest import symbols as symbols_data class DummyConf(object): def __init__(self): self.environment_prefix = 'Project' self.f5_snat_mode = True requests.packages.urllib3.disable_warnings(InsecureRequestWarning) disconnected_service = DisconnectedService() service_adapter = ServiceModelAdapter(DummyConf()) listener_builder = ListenerServiceBuilder(service_adapter) folder_helper = BigIPResourceHelper(ResourceType.folder) bigips = [ BigIP(symbols_data.bigip_ip, symbols_data.bigip_username, symbols_data.bigip_password) ] def deploy_service(service_file): service = {'listeners': []} folder = None try: service = json.load(open(service_file))["service"] # create partition folder = service_adapter.get_folder(service) for bigip in bigips: folder_helper.create(bigip, folder) disconnected_service.create_network(bigip, folder['name'])
def test_create_two(self): b = BigIP('192.168.1.1', 'admin', 'admin') serv1 = b.sys.applications.services.service serv2 = b.sys.applications.services.service assert serv1 is not serv2