def create_pf(vip_option, nic_uuid, num): try: #create vip and eip vip = net_ops.create_vip(vip_option) pf_option = test_util.PortForwardingRuleOption() if num < 32767: port_s = 2 * num port_e = port_s + 1 pf_option.set_allowedCidr('192.168.0.1/32') else: port_s = num / 20 port_e = port_s + 1 pf_option.set_allowedCidr('192.168.%d.%d/32' % (num / 1000, num % 255)) pf_option.set_vip_uuid(vip.uuid) pf_option.set_vm_nic_uuid(nic_uuid) pf_option.set_session_uuid(session_uuid) pf_option.set_protocol(inventory.TCP) pf_option.set_private_ports(port_s, port_e) pf_option.set_vip_ports(port_s, port_e) pf_option.set_name('pf_%s' % vip_option.get_name()) pf = net_ops.create_port_forwarding(pf_option) except: exc_info.append(sys.exc_info())
def create(self, target_vm=None): if not self.pf_creation_option.get_vm_nic_uuid(): self.state = pf_header.DETACHED else: if not self.pf_creation_option.get_vip_uuid(): l3_uuid = test_lib.lib_get_l3_uuid_by_nic(self.pf_creation_option.get_vm_nic_uuid()) if not 'PortForwarding' in test_lib.lib_get_l3_service_type(l3_uuid): test_util.test_fail('[l3:] %s is not available PortForwarding network for [vm:] %s' % (l3_uuid, target_vm.get_vm().uuid)) vr = test_lib.lib_find_vr_by_l3_uuid(l3_uuid)[0] vr_pub_nic = test_lib.lib_find_vr_pub_nic(vr) vip = net_ops.create_vip(vr_pub_nic.l3NetworkUuid) self.pf_creation_option.set_vip_uuid(vip.uuid) self.state = pf_header.ATTACHED if not target_vm: test_util.test_fail('You forget to add target_vm object when calling pf.create(target_vm). ') self.port_forwarding = net_ops.create_port_forwarding(self.pf_creation_option) self.target_vm = target_vm super(ZstackTestPortForwarding, self).create() return self.port_forwarding