Beispiel #1
0
 def test_flatten__string_list(self):
     self.assertEqual(
         [
             '2018-09-15 19:41:43', 'CREATE_IN_PROGRESS       ',
             'my-cfn-stack (AWS::CloudFormation::Stack)\nUser Initiated         '
         ],
         utils.flatten([
             ['2018-09-15 19:41:43'], ['CREATE_IN_PROGRESS       '],
             [
                 'my-cfn-stack (AWS::CloudFormation::Stack)\nUser Initiated         '
             ]
         ]))
Beispiel #2
0
def get_exposed_hostports(container_id):
    """
    Get the host ports we exposed when we ran this container.
    :param container_id: str: the id or name of the running container
    :return list
    """

    # Since we ran the container, we can guarantee that
    # one host port and one or more container ports are exposed.
    # Example of port_map:
    #
    #    {'4848/tcp': None,
    #     '8080/tcp': [{'HostPort': '8080', 'HostIp': '0.0.0.0'}],
    #     '8181/tcp': None}

    try:
        port_map = _get_network_settings(container_id)[PORTS_KEY] or {}
        return utils.flatten([[p[HOST_PORT_KEY] for p in ports]
                             for ports in six.itervalues(port_map) if ports])
    except CommandError:  # Not running
        return []
Beispiel #3
0
 def get_cid_hostport_pairs(self):
     return utils.flatten([[
         (cid, p) for p in hostports
     ] for cid, hostports in six.iteritems(self.get_cid_hostports_map())])
Beispiel #4
0
def _get_opts(_map, opt_name, val_format):
    _map = _map or {}
    kv_pairs = six.iteritems(_map)
    return utils.flatten([[opt_name, val_format.format(k, v)] for k, v
                          in kv_pairs])
Beispiel #5
0
 def test_flatten_nested_long_list(self):
     self.assertEqual([0, 1, 2], utils.flatten([[0], [1], [2]]))
Beispiel #6
0
 def test_flatten_nested_single_list(self):
     self.assertEqual([0], utils.flatten([[0]]))
Beispiel #7
0
 def test_flatten_empty_list(self):
     self.assertEqual([], utils.flatten([]))