• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python service.get_container_by_hostname函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mdts.services.service.get_container_by_hostname函数的典型用法代码示例。如果您正苦于以下问题:Python get_container_by_hostname函数的具体用法?Python get_container_by_hostname怎么用?Python get_container_by_hostname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_container_by_hostname函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: start_midolman_agents

def start_midolman_agents():
    agents = [service.get_container_by_hostname('midolman1'),
              service.get_container_by_hostname('midolman2')]
    for agent in agents:
        agent.start()
    for agent in agents:
        agent.wait_for_status("up")
开发者ID:yamt,项目名称:midonet,代码行数:7,代码来源:test_l4state.py


示例2: check_uplink

def check_uplink(vm, vm_host, fip, dst_port):
    quagga_cont = service.get_container_by_hostname('quagga0')
    vm_cont = service.get_container_by_hostname(vm_host)

    # First check Quagga to VM.
    vm_listen_cmd =\
        'ip netns exec %s nc -l %d' % (vm.get_vm_ns(), dst_port)
    quagga_send_cmd =\
        "/bin/sh -c 'echo test | nc -w 5 %s %d'" % (fip, dst_port)

    result, exec_id = vm_cont.exec_command(vm_listen_cmd, stream=True)
    quagga_cont.exec_command(quagga_send_cmd)

    # nc -l has no timeout mechanism, so make sure the process completed
    # before we try to read the result stream.
    vm_cont.check_exit_status(exec_id, timeout=5)

    assert_that(result.next(), equal_to('test\n'))

    # Now check VM to quagga.
    quagga_listen_cmd = 'nc -l %d' % dst_port
    vm_send_cmd =\
        "ip netns exec %s /bin/sh -c 'echo test | nc -w 5 1.1.1.1 %d'" \
        % (vm.get_vm_ns(), dst_port)

    result, exec_id = quagga_cont.exec_command(quagga_listen_cmd,
                                               stream=True)
    vm_cont.exec_command(vm_send_cmd)
    quagga_cont.check_exit_status(exec_id, timeout=5)
    assert_that(result.next(), equal_to('test\n'))
开发者ID:midonet,项目名称:midonet,代码行数:30,代码来源:test_5_4_router_upgrade.py


示例3: build

    def build(self, binding_data=None, ptm=None):
        super(QosTopology, self).build(binding_data)

        ptm.add_host_to_tunnel_zone('midolman1', 'tztest1')
        ptm.add_host_to_tunnel_zone('midolman2', 'tztest1')

        self.add_bridge({'name': 'main1'})
        self.main_bridge = self.get_bridge('main1')
        self.main_bridge.add_dhcp_subnet(
            {'id': 1,
             'ipv4_gw': '172.16.1.254',
             'network': '172.16.1.0/24'})

        self.main_bridge.add_port({'id': 1, 'type': 'exterior'})
        self.main_bridge.add_port({'id': 2, 'type': 'exterior'})
        self.vm1_port = self.main_bridge.get_port(1)
        self.vm2_port = self.main_bridge.get_port(2)

        host1 = service.get_container_by_hostname('midolman1')
        host2 = service.get_container_by_hostname('midolman2')

        vm1data = {'hw_addr': 'aa:bb:cc:00:00:11',
                   'ipv4_addr': ['172.16.1.2/24'],
                   'ipv4_gw': '172.16.1.1'}
        vm2data = {'hw_addr': 'aa:bb:cc:00:00:22',
                   'ipv4_addr': ['172.16.1.3/24'],
                   'ipv4_gw': '172.16.1.1'}

        self.vm1 = host1.create_vmguest(**vm1data)
        self.vm2 = host2.create_vmguest(**vm2data)

        ptm.addCleanup(host1.destroy_vmguest, self.vm1)
        ptm.addCleanup(host2.destroy_vmguest, self.vm2)

        port1_real_id = self.vm1_port.get_real_id()
        port2_real_id = self.vm2_port.get_real_id()

        host1.bind_port(self.vm1, port1_real_id)
        host2.bind_port(self.vm2, port2_real_id)

        utils.await_port_active(port1_real_id, active=True)
        utils.await_port_active(port2_real_id, active=True)

        self.qos_pol1 = self.add_qos_policy(
            {'name': 'pol1', 'description': 'Description',
             'shared': True})
        self.qos_pol2 = self.add_qos_policy(
            {'name': 'pol2', 'description': 'Description Two',
             'shared': True})

        assert_that(self.qos_pol1)
        assert_that(self.qos_pol2)
开发者ID:midonet,项目名称:midonet,代码行数:52,代码来源:test_qos.py


示例4: cleanup

def cleanup():
    agent = service.get_container_by_hostname('midolman1')
    # We wait just to make sure that it's been unregistered
    agent.stop(wait=True)
    # Wipe out the container
    sandbox.remove_container(agent)
    # Restart sandbox, the --no-recreate flag will spawn only missing containers
    sandbox.restart_sandbox('default_v2_neutron+kilo+compat',
                            'sandbox/override_v2_compat')
    # Reset cached containers and reload them (await for the new agent to be up)
    service.loaded_containers = None
    agent = service.get_container_by_hostname('midolman1')
    agent.wait_for_status('up')
开发者ID:th3architect,项目名称:midonet,代码行数:13,代码来源:test_compat_flowstate.py


示例5: bind

    def bind(self):
        # Schedule deletion of virtual and physical topologies
        self.addCleanup(self._ptm.destroy)
        self._ptm.build(self._data)
        self.addCleanup(self._vtm.destroy)
        self._add_hosts_to_tunnel_zone()
        self._vtm.build(self._data)
        for binding in self._data['bindings']:
            vport = self._vtm.get_resource(binding['vport'])
            bind_iface = binding['interface']
            if isinstance(bind_iface, dict):
                # We are specifying the vms inside the binding
                iface_def = self._update_addresses(bind_iface['definition'], vport)
                iface_type = bind_iface['type']
                hostname = bind_iface['hostname']
                host = service.get_container_by_hostname(hostname)
                iface = getattr(host, "create_%s" % iface_type)(**iface_def)
                self.addCleanup(getattr(host, "destroy_%s" % iface_type), iface)
            else:
                # It's a vm already created and saved as a resource
                iface = self._ptm.get_resource(binding['interface'])

            vport_id = self._get_port_id(vport)

            # Do the actual binding
            binding = iface.compute_host.bind_port(iface, vport_id)
            self.addCleanup(iface.compute_host.unbind_port, iface)
            self._mappings[vport_id] = iface
            await_port_active(vport_id)

        # create and bind a "router", which is actually just a namespace
        # residing on the host with multiple interfaces that can be bound
        # to a port in midonet.
        # Example definition:
        #
        # 'routers': [
        #     {'bindings': [
        #         {'vport': 'uplink_left',
        #          'iface': 'l_tun',
        #          'addr': '100.0.0.10/24'},
        #         {'vport': 'uplink_right',
        #          'iface': 'r_tun',
        #          'addr': '200.0.0.10/24'}],
        #      'name': 'UPL',
        #      'host': 'midolman1'}],

        for router_def in self._data.get('routers') or []:
            hostname = router_def['host']
            host = service.get_container_by_hostname(hostname)
            host.create_netns_router(router_def['name'], router_def['bindings'])
            self.addCleanup(host.destroy_router, router_def['name'])
开发者ID:midonet,项目名称:midonet,代码行数:51,代码来源:bindings.py


示例6: test_simple_port_migration

def test_simple_port_migration():
    """
    Title: Tests that flow state changes are backwards compatible

    The topology is set up in such a way that both conntrack
    and NAT flow state is generated.

    Send nonfip-to-fip udp packets between two agents and return packets
    Unbind the public port and bind it to a different vm
    Verify that previous flows still work in both directions
    """

    binding_type = BM.get_binding_data()['binding_type']

    agent2 = service.get_container_by_hostname('midolman2')
    agent3 = service.get_container_by_hostname('midolman3')

    # vm on midolman1
    private_interface_vm = BM.get_interface_on_vport('private_port')
    # vm on midolman2
    public_interface_vm = BM.get_interface_on_vport('public_port')
    # port to be migrated
    public_port = VTM.get_resource('public_port')['port']

    # new free vm on midolman3
    free_interface_vm_data = {
        'hw_addr': public_port['mac_address'],
        'ipv4_addr': [public_port['fixed_ips'][0]['ip_address'] + '/24'],
        'ipv4_gw': '10.0.1.1'}
    free_interface_vm = agent3.create_vmguest(**free_interface_vm_data)
    VTM.addCleanup(agent3.destroy_vmguest, free_interface_vm)

    fip = VTM.get_resource('public_port_fip')['floatingip']['floating_ip_address']

    # Generate flow state
    snat = check_forward_flow(
        private_interface_vm, public_interface_vm, fip, 50000, 80)
    check_return_flow(
        public_interface_vm, private_interface_vm, snat['ip'], snat['port'], 50000, 80)

    # Unbind/bind port to a different host
    if binding_type == BindingType.API:
        agent2.unbind_port(public_interface_vm, type=binding_type)
    agent3.bind_port(free_interface_vm, public_port['id'], type=binding_type)

    await_port_active(public_port['id'], active=True)

    check_return_flow(
        free_interface_vm, private_interface_vm, snat['ip'], snat['port'], 50000, 80)
开发者ID:midonet,项目名称:midonet,代码行数:49,代码来源:test_port_migration.py


示例7: setup_remote_host

    def setup_remote_host(self, container, interface, gw_address,
                          local_address, local_router):
        self.addCleanup(self.cleanup_remote_host, container, interface, gw_address)
        cont = service.get_container_by_hostname(container)

        cont.try_command_blocking('ip r add 100.0.0.0/8 via 10.1.0.1')
        cont.try_command_blocking('ip a add %s/64 dev %s' % (gw_address, interface))
        cont.try_command_blocking('ip -6 r add cccc:bbbb::/32 via 2001::1')
        cont.try_command_blocking('ip -6 r add cccc:cccc::/32 via 2001::1')

        # enable ip6 forwarding
        cont.try_command_blocking('sysctl net.ipv6.conf.all.forwarding=1')

        # setup ip6 namespace
        cont.try_command_blocking('ip netns add ip6')
        cont.try_command_blocking(
            'ip l add name ip6dp type veth peer name ip6ns')
        cont.try_command_blocking('ip l set netns ip6 dev ip6ns')
        cont.try_command_blocking('ip l set up dev ip6dp')
        cont.try_command_blocking('ip netns exec ip6 ip link set up dev lo')
        cont.try_command_blocking('ip netns exec ip6 ip link set up dev ip6ns')
        cont.try_command_blocking(
            'ip a add %s/48 dev ip6dp' % local_router)
        cont.try_command_blocking(
            'ip netns exec ip6 ip a add %s/48 dev ip6ns' % local_address)
        cont.try_command_blocking(
            'ip netns exec ip6 ip -6 r add default via %s' % local_router)
开发者ID:midonet,项目名称:midonet,代码行数:27,代码来源:test_ipv6.py


示例8: add_host_to_tunnel_zone

    def add_host_to_tunnel_zone(self, hostname, tz_name, add_clean_up=True):
        """

        :param hostname: string
        :param tz_name: string
        :param add_clean_up: boolean
        :rtype: None
        """
        def get_or_create_tz(tz_name):
            tzones = self._midonet_api.get_tunnel_zones()
            for tz in tzones:
                if tz_name in tz.get_name():
                    return tz
            tz = self._midonet_api.add_vxlan_tunnel_zone()
            tz.name('%s-%s' % (tz_name, str(uuid.uuid4())[:4]))
            tz.create()
            self.addCleanup(tz.delete)
            return tz

        tz = get_or_create_tz(tz_name)
        host = service.get_container_by_hostname(hostname)
        hostid = host.get_midonet_host_id()
        tz_hostids = [tz_host.get_host_id() for tz_host in tz.get_hosts()]
        # Make sure not to add an existing host in the tz
        if hostid not in tz_hostids:
            tz_host = tz.add_tunnel_zone_host()
            tz_host.ip_address(host.get_ip_address())
            tz_host.host_id(host.get_midonet_host_id())
            tz_host.create()
            if add_clean_up:
                self.addCleanup(tz_host.delete)
开发者ID:332054781,项目名称:midonet,代码行数:31,代码来源:topology_manager.py


示例9: bind

    def bind(self):
        # Schedule deletion of virtual and physical topologies
        self.addCleanup(self._ptm.destroy)
        self._ptm.build(self._data)
        self.addCleanup(self._vtm.destroy)
        self._vtm.build(self._data)
        self._add_hosts_to_tunnel_zone()
        for binding in self._data['bindings']:
            vport = self._vtm.get_resource(binding['vport'])
            bind_iface = binding['interface']
            if isinstance(bind_iface, dict):
                # We are specifying the vms inside the binding
                iface_def = self._update_addresses(bind_iface['definition'], vport)
                iface_type = bind_iface['type']
                hostname = bind_iface['hostname']
                host = service.get_container_by_hostname(hostname)
                iface = getattr(host, "create_%s" % iface_type)(**iface_def)
                self.addCleanup(getattr(host, "destroy_%s" % iface_type), iface)
            else:
                # It's a vm already created and saved as a resource
                iface = self._ptm.get_resource(binding['interface'])

            vport_id = self._get_port_id(vport)

            # Do the actual binding
            binding = iface.compute_host.bind_port(iface, vport_id)
            self.addCleanup(iface.compute_host.unbind_port, iface)
            self._mappings[vport_id] = iface
            await_port_active(vport_id)
开发者ID:yantarou,项目名称:midonet,代码行数:29,代码来源:bindings.py


示例10: setup_package

def setup_package():
    """
    Setup method at the tests module level (init)
    :return:
    """
    # Read configuration
    conf_file = os.getenv('MDTS_CONF_FILE', 'mdts.conf')
    config = SafeConfigParser()
    config.read(conf_file)

    # Check all services (including midolman) are online
    api_host = service.get_container_by_hostname('cluster1')
    api_host.wait_for_status('up')
    for type, hosts in service.get_all_containers().items():
        for host in hosts:
            LOG.debug("Checking liveness of %s" % host.get_hostname())
            host.wait_for_status('up', timeout=240)

    # Wait until bindings do not fail, at that point, mdts is ready for test
    max_attempts = 10
    for current_attempts in xrange(max_attempts):
        topology = build_simple_topology()
        try:
            destroy_simple_topology(topology)
            LOG.debug("MDTS ready to run tests.")
            return
        except:
            destroy_simple_topology(topology)
            current_attempts += 1
            LOG.debug("MDTS failed to bind port... check again. Attempt: %d" %
                      current_attempts)

    raise RuntimeError("MDTS was unable to bind a single port... Exiting.")
开发者ID:tinv33043,项目名称:midonet,代码行数:33,代码来源:__init__.py


示例11: test_new_interface_becomes_visible

def test_new_interface_becomes_visible():
    """
    mdts.tests.functional_tests.test_midolman_and_interfaces.test_new_interface_becomes_visible

    Scenario:
    When: On start up, a Midolman sees no interface,
    Then: adds a new interface,
    And: Midolman detects a new interface.
    """

    # FIXME: pick the midonet-agent from binding manager (when parallel)
    midonet_api = get_midonet_api()
    agent = service.get_container_by_hostname('midolman1')
    iface_name = 'interface%d' % random.randint(1, 100)
    new_interface = get_interface(
        midonet_api,
        agent.get_midonet_host_id(),
        iface_name)
    # Test that no interface with name 'interface_01' exists.
    assert_that(new_interface, none(), iface_name)

    # Create a new interface 'interface_01'.
    iface = agent.create_vmguest(ifname=iface_name)
    time.sleep(5)
    new_interface = get_interface(
        midonet_api,
        agent.get_midonet_host_id(),
        iface_name)

    # Test that the created interface is visible.
    assert_that(new_interface, not_none(), iface_name)

    agent.destroy_vmguest(iface)
开发者ID:ody,项目名称:midonet,代码行数:33,代码来源:test_midolman_and_interfaces.py


示例12: test_mmctl_unbinding_without_mm_running

def test_mmctl_unbinding_without_mm_running():
    """
    Title: Unbinding a port using mmctl when midolman is not running
    """
    mm1 = service.get_container_by_hostname('midolman1')
    port1 = VTM.port1
    iface_port2 = BM.get_interface_on_vport('port2')

    iface = mm1.create_vmguest(hw_addr=port1['mac_address'])
    VTM.addCleanup(iface.destroy)

    mm1.bind_port(iface, port1['id'], BindingType.MMCTL)
    VTM.addCleanup(mm1.unbind_port, iface, BindingType.MMCTL)

    iface.dhclient()
    iface.try_command_blocking("ping -c 5 %s" % (iface_port2.get_ip()))

    mm1.stop()

    mm1.unbind_port(iface, BindingType.MMCTL)

    mm1.start()

    ret = iface.exec_command_blocking("ping -c 5 %s" % (iface_port2.get_ip()))
    # Ping returns 0 if the ping succeeds, 1 or 2 on error conditions.
    assert_that(ret,
                is_not(equal_to(0)),
                "Ping should have failed, but did not.")
开发者ID:midonet,项目名称:midonet,代码行数:28,代码来源:test_mmctl.py


示例13: ping_from_inet

def ping_from_inet(container, ipv6='2001::1', count=4, namespace=None):
    count = max(1, count)
    cmd = "%s ping6 %s -c %d" % (
        "ip netns exec %s" % namespace if namespace else "",
        ipv6, count)
    cont_services = service.get_container_by_hostname(container)
    cont_services.try_command_blocking(cmd)
开发者ID:danielmellado,项目名称:midonet,代码行数:7,代码来源:test_ipv6.py


示例14: cleanup_remote_host

    def cleanup_remote_host(self, container, interface, address):
        cont = service.get_container_by_hostname(container)
        cont.exec_command('ip r del 100.0.0.0/8')
        cont.exec_command('ip a del %s/64 dev %s' % (address, interface))
        cont.exec_command('ip -6 r del cccc:bbbb::/32')
        cont.exec_command('ip -6 r del cccc:cccc::/32')

        cont.exec_command('ip netns delete ip6')
开发者ID:midonet,项目名称:midonet,代码行数:8,代码来源:test_ipv6.py


示例15: cleanup_ipv6_flows

 def cleanup_ipv6_flows(self, container, from_port, to_port):
     cont = service.get_container_by_hostname(container)
     cont.exec_command(
         'mm-dpctl flows --delete -d midonet -e 86dd -i %s -o %s' %
         (from_port, to_port))
     cont.exec_command(
         'mm-dpctl flows --delete -d midonet -e 86dd -i %s -o %s' %
         (to_port, from_port))
开发者ID:midonet,项目名称:midonet,代码行数:8,代码来源:test_ipv6.py


示例16: add_port_to_vpp

 def add_port_to_vpp(self, container, port, mac, address, vrf=0):
     cont = service.get_container_by_hostname(container)
     self.addCleanup(self.del_port_from_vpp, container, port)
     cont.vppctl('create host-interface name %s hw-addr %s' % (port, mac))
     cont.vppctl('set int state host-%s up' % port)
     if vrf != 0:
         cont.vppctl('set int ip table host-%s %d' % (port, vrf))
     self.add_vpp_ip_address(cont, port, address)
开发者ID:midonet,项目名称:midonet,代码行数:8,代码来源:test_ipv6.py


示例17: test_qos_dscp_mark_on_network

def test_qos_dscp_mark_on_network():
    """
    1) Test that setting a DSCP rule on a network will transform all
    default packets that ingress the cloud on the network to set the IP
    DS headers to the given DSCP mark, or reset the IP DS headers to the
    given DSCP mark, if already set.

    2) Test that clearing a DSCP rule on a network will no longer set
    the IP DS header on default, and will no longer change the IP DS
    header on packets with DS header already set.

    3) Test that setting and clearing the DSCP rule on a network will also
    affect any traffic on any new ports created on that network.
    """

    try:
        PTM.build()
        VTM.build(ptm=PTM)
        VTM.qos_pol1.add_dscp_rule({'dscp_mark': 11})

        VTM.main_bridge.set_qos_policy(VTM.qos_pol1)

        VTM.vm1.verify_packet_field(
            target_iface=VTM.vm2,
            field='tos', value=11)

        VTM.main_bridge.add_port({'id': 3, 'type': 'exterior'})
        vm3_port = VTM.main_bridge.get_port(3)
        host1 = service.get_container_by_hostname('midolman1')
        vm3data = {'hw_addr': 'aa:bb:cc:00:00:11',
                   'ipv4_addr': ['172.16.1.4/24'],
                   'ipv4_gw': '172.16.1.1'}
        vm3 = host1.create_vmguest(**vm3data)
        port3_real_id = vm3_port.get_real_id()
        host1.bind_port(vm3, port3_real_id)
        utils.await_port_active(port3_real_id, active=True)

        vm3.verify_packet_field(
            target_iface=VTM.vm2,
            field='tos', value=11)

        VTM.main_bridge.clear_qos_policy()

        VTM.vm1.verify_packet_field(
            target_iface=VTM.vm2,
            field='tos', value=None)

        vm3.verify_packet_field(
            target_iface=VTM.vm2,
            field='tos', value=None)

        VTM.qos_pol2.clear_dscp_rules()
        VTM.qos_pol1.clear_dscp_rules()

        host1.destroy_vmguest(vm3)
    finally:
        VTM.destroy()
        PTM.destroy()
开发者ID:midonet,项目名称:midonet,代码行数:58,代码来源:test_qos.py


示例18: install_packages

def install_packages(container_name, *packages):
    container = service.get_container_by_hostname(container_name)
    output, exec_id = container.exec_command(
        "sh -c 'env DEBIAN_FRONTEND=noninteractive apt-get install " + \
        "-qy --force-yes -o Dpkg::Options::=\"--force-confnew\" " + \
        "%s'" % (" ".join(packages)), stream=True)
    exit_code = container.check_exit_status(exec_id, output, timeout=60)
    if exit_code != 0:
        raise RuntimeError("Failed to update packages (%s)." % (packages))
开发者ID:midonet,项目名称:midonet,代码行数:9,代码来源:setup_utils.py


示例19: stop_jfr

def stop_jfr(hostname, filename):
    agent = service.get_container_by_hostname(hostname)
    pid = agent.exec_command("pgrep -f Midolman")
    output, exec_id = agent.exec_command(
        "jcmd %s JFR.stop name=%s" % (pid, filename), stream=True)
    exit_code = agent.check_exit_status(exec_id, output, timeout=60)
    if exit_code != 0:
        raise RuntimeError("Failed to stop Java Flight Recorder for "
                           "'%s'" % (hostname))
开发者ID:gustavomitt,项目名称:midonet,代码行数:9,代码来源:test_perf_flowstate.py


示例20: add_member

def add_member(host_name, tzone_name):
    host_container = service.get_container_by_hostname(host_name)
    tz_host = _tunnel_zones[tzone_name].add_tunnel_zone_host()
    tz_host.host_id(host_container.get_midonet_host_id())
    tz_host.ip_address(host_container.get_ip_address())
    tz_host.create()
    LOG.debug("Added VTEP tunnel zone member: {0} <- {1} @ {2}"
              .format(tzone_name, host_container.get_midonet_host_id(),
                      host_container.get_ip_address()))
开发者ID:th3architect,项目名称:midonet,代码行数:9,代码来源:test_vxlangw.py



注:本文中的mdts.services.service.get_container_by_hostname函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python asserts.async_assert_that函数代码示例发布时间:2022-05-27
下一篇:
Python moves.xrange函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap