Skip to content

Instantly share code, notes, and snippets.

@ashwoods
Created November 12, 2021 12:35
Show Gist options
  • Save ashwoods/2ca5ad497dd04bd480e8c6d1caeda203 to your computer and use it in GitHub Desktop.
Save ashwoods/2ca5ad497dd04bd480e8c6d1caeda203 to your computer and use it in GitHub Desktop.
mender deploy python script
#!/usr/bin/env python3
import requests
import argparse
def get_token(user, password):
headers = {
'Content-Type': 'application/json',
'Accept': 'application/jwt',
}
r = requests.post('https://hosted.mender.io/api/management/v1/useradm/auth/login', headers = headers, auth=(user, password))
return r.text
def create_deployment(device, artifact, token):
headers = {
'Accept': 'application/json',
'Authorization': f'Bearer {token}'
}
body = {
"name": device,
"artifact_name": artifact,
"devices": [
device
],
}
r = requests.post('https://hosted.mender.io/api/management/v1/deployments/deployments', headers = headers, json=body)
print(r)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(dest='user', help="Mender user")
parser.add_argument(dest='password', help="Mender password password")
parser.add_argument(dest='device', help="Device ID")
parser.add_argument(dest='artifact', help="Mender artifact release name")
args = parser.parse_args()
token = get_token(args.user, args.password)
create_deployment(args.device, args.artifact, token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment