Skip to content

Introduce device-management/dev-mgmt/dm subcommand #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 31, 2018

Conversation

theotherjimmy
Copy link
Contributor

This subcommand will be used for device management.
I will submit the companion PR to mbed-os very soon.

mbed/mbed.py Outdated
dict(name='--source', action='append', help='Source directory. Default: . (current dir)'),
help='device management supcommand',
hidden_aliases=['dev-mgmt', 'dm'],
description=("Manage Device with Palion"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure Palion should be Pelion 😄

mbed/mbed.py Outdated

if build:
build_path = build
elif not build and target and toolchain:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll nit. I understand this as (not A) and (B) and (C), but might be misunderstood as not (A and B and C).
Might make it easier to understand if parentheses were explicit.

@@ -1575,6 +1575,10 @@ def get_env(self):
for c in compilers:
if self.get_cfg(c+'_PATH'):
env['MBED_'+c+'_PATH'] = self.get_cfg(c+'_PATH')
config_options = ['COLOR', 'CLOUD_SDK_API_KEY', 'CLOUD_SDK_HOST']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COLOR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah MBED_COLOR makes errors stick out.

Copy link
Contributor

@cmonr cmonr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am appeased

@teetak01
Copy link

I think the "help" need a bit wider print out:

   compile          Compile code using the mbed build tools
    test             Find, build and run tests
    device-management
                     device management supcommand

device-management seems to be one char too long for nice printing.

theotherjimmy added a commit to theotherjimmy/Handbook that referenced this pull request Aug 23, 2018
@MarceloSalazar
Copy link
Contributor

MarceloSalazar commented Aug 27, 2018

@theotherjimmy

Is there a prerequisite to use the mbed dm command?

I'm testing this PR with ARMmbed/mbed-os/pull/7844 and following steps described in ARMmbed/mbed-os-5-docs/pull/681

  • Add config for CLOUD_SDK_API_KEY
  • mbed dm init -d "arm" --model-name "mbed" -vv

Output:

[mbed] Auto-installing missing Python modules...
[mbed] Exec "/usr/local/opt/python/bin/python2.7 -m pip install -q -r /Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/requirements.txt" in "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted"

[mbed] Exec "/usr/local/opt/python/bin/python2.7 -u /Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/tools/device_management.py init -d arm --model-name mbed" in "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted"
Traceback (most recent call last):
  File "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/tools/device_management.py", line 155, in <module>
    main()
  File "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/tools/device_management.py", line 150, in main
    }[options.action](options) or 0
  File "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/tools/device_management.py", line 94, in inner
    dev_cert_info = certs.get_certificate(certif.id)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/decorators.py", line 40, in wrapped_f
    raise_(CloudApiException, e, traceback)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/decorators.py", line 33, in wrapped_f
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/certificates/certificates.py", line 96, in get_certificate
    self._extend_certificate(certificate)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/certificates/certificates.py", line 103, in _extend_certificate
    dev_cert = dev_api.get_developer_certificate(certificate.id, self.auth)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/apis/developer_certificate_api.py", line 159, in get_developer_certificate
    (data) = self.get_developer_certificate_with_http_info(developer_certificate_id, authorization, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/apis/developer_certificate_api.py", line 238, in get_developer_certificate_with_http_info
    collection_formats=collection_formats)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/api_client.py", line 353, in call_api
    _return_http_data_only, collection_formats, _preload_content, _request_timeout)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/api_client.py", line 113, in wrapped_f
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/api_client.py", line 182, in __call_api
    _request_timeout=_request_timeout)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/api_client.py", line 374, in request
    headers=headers)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/rest.py", line 235, in GET
    query_params=query_params)
  File "/usr/local/lib/python2.7/site-packages/mbed_cloud/_backends/connector_ca/rest.py", line 226, in request
    raise ApiException(http_resp=r)
mbed_cloud.exceptions.CloudApiException: (403) "Forbidden" (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Connection': 'Keep-Alive', 'Content-Type': 'application/json', 'Content-Length': '113'})
HTTP response body: { "object": "error","code": 403,"type": "invalid_request",
  "message": "The API is only accessible over HTTPS" }

[mbed] ERROR: "/usr/local/opt/python/bin/python2.7" returned error.
       Code: 1
       Path: "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted"
       Command: "/usr/local/opt/python/bin/python2.7 -u /Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/tools/device_management.py init -d arm --model-name mbed"
       Tip: You could retry the last command with "-v" flag for verbose output

@theotherjimmy
Copy link
Contributor Author

@MarceloSalazar Thanks for the bug report. I need to update the default for MBED_CLOUD_SDK_URL.

@theotherjimmy
Copy link
Contributor Author

@MarceloSalazar I updated the mbed-os PR to make HTTPS the default.

@theotherjimmy
Copy link
Contributor Author

Turns out that was better done here, so it's done here.

@MarceloSalazar
Copy link
Contributor

Thanks for the fix @theotherjimmy . I've managed to make a bit of progress.

What's the expected input for the company domain and model parameters?

I'm not able to find entries that work with mbed dm init, even after looking at the manifest-tool docs; I feel we need to expand the docs a bit and provide some hints in Mbed CLI when the entries are not correct.

See output:

$ mbed dm init -d "my_company_name" --model-name "my_model_name" 
[mbed] Auto-installing missing Python modules...
[INFO] 2018-08-28 19:18:52 - __main__ - Found developer certificate onwed by Marcelo Salazar named mbed-cli-auto Marcelo Salazar
[INFO] 2018-08-28 19:18:52 - __main__ - Writing developer certificate mbed-cli-auto Marcelo Salazar into c file mbed_cloud_dev_credentials.c
[]
[CRITICAL] 2018-08-28 19:18:52 - manifesttool.init - "my_company_name" is not a valid domain name.
[mbed] ERROR: "/usr/local/opt/python/bin/python2.7" returned error.
       Code: 1
       Path: "/Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted"
       Command: "/usr/local/opt/python/bin/python2.7 -u /Users/marsal01/mbed/SimpleMCC/official/fw_update/simple-mbed-cloud-client-template-restricted/mbed-os/tools/device_management.py init -d my_company_name --model-name my_model_name"
       Tip: You could retry the last command with "-v" flag for verbose output

@theotherjimmy
Copy link
Contributor Author

@MarceloSalazar -d accepts a url, so something like arm.com is what's expected.

@lorjala
Copy link
Contributor

lorjala commented Aug 29, 2018

@theotherjimmy good, it works now as expected.

A minor concern is that since you cannot get the usage information for manifest-tool with mbed dm -h, you need to check arguments from the tool itself. This can be confusing and counter-productive. Mbed CLI and manifest-tool share same keywords for arguments, but for different purposes (e.g. -m) so you need to be careful when using those.

Is this expected behaviour and should this be mentioned in the documentation?

@theotherjimmy
Copy link
Contributor Author

@lorjala That's true for all subcommands that do something other than repo management.

@teetak01
Copy link

mbed.py device-management init -d "test.arm.com" -m "model-name" -a

fails with -m/--model-name is required

mbed.py device-management init -d "test.arm.com" --model-name "model-name" -a

mbed-os/tools/device_management.py", line 86, in inner
'key': getenv("MBED_CLOUD_SDK_API_KEY")
File "/usr/local/lib/python2.7/dist-packages/mbed_cloud/pagination.py", line 150, in next
return self.next()
File "/usr/local/lib/python2.7/dist-packages/mbed_cloud/pagination.py", line 159, in next
raise StopIteration()
StopIteration

  1. '-m' flag does not seem to work
  2. '-a' flag also does not seem to work either.

usage: device_management.py init [-h] [-c CERTIFICATE] [-k PRIVATE_KEY]
(-V VENDOR_ID | -d VENDOR_DOMAIN)
(-C CLASS_ID | -m MODEL_NAME)
[-S SERVER_ADDRESS] [-a API_KEY] [-q] [-f]
[--psk]

@teetak01
Copy link

teetak01 commented Aug 31, 2018

@theotherjimmy is there a flag to prevent downloading the certificate? I think this should be configuration option, (off by default).

@theotherjimmy theotherjimmy merged commit c30230f into ARMmbed:master Aug 31, 2018
@theotherjimmy
Copy link
Contributor Author

@teetak01 That's actually controlled by mbed-os at this time. I can make it "opt-out".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants