some minor things.

Diff comments:

> diff --git a/cloudinit/sources/DataSourceOpenStack.py 
> b/cloudinit/sources/DataSourceOpenStack.py
> index 1a12a3f..e7b0b41 100644
> --- a/cloudinit/sources/DataSourceOpenStack.py
> +++ b/cloudinit/sources/DataSourceOpenStack.py
> @@ -205,6 +209,25 @@ def read_metadata_service(base_url, ssl_details=None,
>      return reader.read_v2()
>  
>  
> +def detect_openstack():
> +    """Return True when a potential OpenStack platform is detected."""
> +    cpu_arch = os.uname()[4]
> +    if not re.match(r'i.86|x86_64', cpu_arch):
> +        return True  # Non-Intel cpus don't properly report dmi product names

in util.read_dmi_data we have:

if not (uname_arch == 'x86_64' or (uname_arch.startswith("i") and 
uname_arch[2:] == "86")

over engineered, but faster.
$ CR=$'\n'; python3 -m timeit --setup="import re${CR}def check(cpu): return 
re.match(r'i.86|x86_64', cpu)" "check('x86_64')"
1000000 loops, best of 3: 0.775 usec per loop

$ CR=$'\n'; python3 -m timeit --setup="import re${CR}def check(cpu): return 
cpu.startswith('i') and cpu[2:] == '86'" "check('x86_64')"
10000000 loops, best of 3: 0.178 usec per loop

Perhaps pull that out and make a util.is_x86 ?

> +    product_name = util.read_dmi_data('system-product-name')
> +    if product_name in ('OpenStack Nova', 'OpenStack Compute'):
> +        return True
> +    elif util.read_dmi_data('chassis-asset-tag') == 'OpenTelekomCloud':
> +        return True
> +    elif os.path.exists('/proc/1/environ'):

this is 'get_proc_env'.
you can then write this as:

elif get_proc_env(1).get('product_name') == 'OpenStack Nova'

> +        environ_content = util.load_file('/proc/1/environ')
> +        env_items = re.split(r'\0|=', environ_content)
> +        pid1_environ = dict(zip(env_items[::2], env_items[1::2]))
> +        if pid1_environ.get('product_name') == 'OpenStack Nova':
> +            return True
> +    return False
> +
> +
>  # Used to match classes to dependencies
>  datasources = [
>      (DataSourceOpenStackLocal, (sources.DEP_FILESYSTEM,)),


-- 
https://code.launchpad.net/~chad.smith/cloud-init/+git/cloud-init/+merge/347937
Your team cloud-init commiters is requested to review the proposed merge of 
~chad.smith/cloud-init:bug/1776701-openstack-local-no-probe-on-ec2 into 
cloud-init:master.

_______________________________________________
Mailing list: https://launchpad.net/~cloud-init-dev
Post to     : cloud-init-dev@lists.launchpad.net
Unsubscribe : https://launchpad.net/~cloud-init-dev
More help   : https://help.launchpad.net/ListHelp

Reply via email to