Esempio n. 1
0
def _build_cloud(cloud_name, cloud_config=None, cloud_args=None):
    if cloud_config:
        # Using JSON format so convert the keys to snake case
        for key in cloud_config:
            cloud_config[to_snake_case(key)] = cloud_config.pop(key)
        cloud_args = cloud_config
    c = Cloud(cloud_name)
    for arg in cloud_args:
        if arg.startswith('endpoint_') and cloud_args[arg] is not None:
            setattr(c.endpoints, arg.replace('endpoint_', ''), cloud_args[arg])
        elif arg.startswith('suffix_') and cloud_args[arg] is not None:
            setattr(c.suffixes, arg.replace('suffix_', ''), cloud_args[arg])
    return c
Esempio n. 2
0
def _build_cloud(cloud_name, cloud_config=None, cloud_args=None):
    if cloud_config:
        # Using JSON format so convert the keys to snake case
        for key in cloud_config:
            cloud_config[to_snake_case(key)] = cloud_config.pop(key)
        cloud_args = cloud_config
    c = Cloud(cloud_name)
    c.profile = cloud_args.get('profile', None)
    for arg in cloud_args:
        if arg.startswith('endpoint_') and cloud_args[arg] is not None:
            setattr(c.endpoints, arg.replace('endpoint_', ''), cloud_args[arg])
        elif arg.startswith('suffix_') and cloud_args[arg] is not None:
            setattr(c.suffixes, arg.replace('suffix_', ''), cloud_args[arg])
    return c
Esempio n. 3
0
def _build_cloud(cloud_name, cloud_config=None, cloud_args=None):
    if cloud_config:
        # Using JSON format so convert the keys to snake case
        for key in cloud_config:
            cloud_config[to_snake_case(key)] = cloud_config.pop(key)
        cloud_args = cloud_config
    c = Cloud(cloud_name)
    c.profile = cloud_args.get('profile', None)
    for arg in cloud_args:
        if arg.startswith('endpoint_') and cloud_args[arg] is not None:
            setattr(c.endpoints, arg.replace('endpoint_', ''), cloud_args[arg])
        elif arg.startswith('suffix_') and cloud_args[arg] is not None:
            setattr(c.suffixes, arg.replace('suffix_', ''), cloud_args[arg])
    arm_endpoint = cloud_args.get('endpoint_resource_manager', None)
    _populate_from_metadata_endpoint(c, arm_endpoint)
    return c
Esempio n. 4
0
def _build_cloud(cloud_name, cloud_config=None, cloud_args=None):
    if cloud_config:
        # Using JSON format so convert the keys to snake case
        for key in cloud_config:
            cloud_config[to_snake_case(key)] = cloud_config.pop(key)
        cloud_args = cloud_config
    c = Cloud(cloud_name)
    c.profile = cloud_args.get('profile', None)
    for arg in cloud_args:
        if arg.startswith('endpoint_') and cloud_args[arg] is not None:
            setattr(c.endpoints, arg.replace('endpoint_', ''), cloud_args[arg])
        elif arg.startswith('suffix_') and cloud_args[arg] is not None:
            setattr(c.suffixes, arg.replace('suffix_', ''), cloud_args[arg])
    arm_endpoint = cloud_args.get('endpoint_resource_manager', None)
    _populate_from_metadata_endpoint(c, arm_endpoint)
    required_endpoints = {
        'resource_manager':
        '--endpoint-resource-manager',
        'active_directory':
        '--endpoint-active-directory',
        'active_directory_resource_id':
        '--endpoint-active-directory-resource-id',
        'active_directory_graph_resource_id':
        '--endpoint-active-directory-graph-resource-id'
    }
    missing_endpoints = [
        e_param for e_name, e_param in required_endpoints.items()
        if not c.endpoints.has_endpoint_set(e_name)
    ]
    if missing_endpoints:
        raise CLIError(
            "The following endpoints are required for the CLI to function and were not specified on the "
            "command line, in the cloud config or could not be autodetected.\n"
            "Specify them on the command line or through the cloud config file:\n"
            "{}".format(', '.join(missing_endpoints)))
    return c
Esempio n. 5
0
 def test_to_snake_case_already_snake(self):
     the_input = 'this_is_snake_cased'
     expected = 'this_is_snake_cased'
     actual = to_snake_case(the_input)
     self.assertEqual(expected, actual)
Esempio n. 6
0
 def test_to_snake_case_empty(self):
     the_input = ''
     expected = ''
     actual = to_snake_case(the_input)
     self.assertEqual(expected, actual)
Esempio n. 7
0
 def test_to_snake_case_from_camel(self):
     the_input = 'thisIsCamelCase'
     expected = 'this_is_camel_case'
     actual = to_snake_case(the_input)
     self.assertEqual(expected, actual)
 def test_to_snake_case_already_snake(self):
     the_input = 'this_is_snake_cased'
     expected = 'this_is_snake_cased'
     actual = to_snake_case(the_input)
     self.assertEqual(expected, actual)
 def test_to_snake_case_empty(self):
     the_input = ''
     expected = ''
     actual = to_snake_case(the_input)
     self.assertEqual(expected, actual)
 def test_to_snake_case_from_camel(self):
     the_input = 'thisIsCamelCase'
     expected = 'this_is_camel_case'
     actual = to_snake_case(the_input)
     self.assertEqual(expected, actual)