Ubuntu Pastebin

Paste from Brendan at Thu, 22 Sep 2016 09:09:41 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def get_auth_headers(consumer_key, key, secret):
    resource_tok_string = "oauth_token_secret=%s&oauth_token=%s" % (
        secret, key)
    resource_token = oauth.OAuthToken.from_string(resource_tok_string)
    consumer_token = oauth.OAuthConsumer(consumer_key, "")

    oauth_request = oauth.OAuthRequest.from_consumer_and_token(
        consumer_token, token=resource_token, http_url=MAAS_API,
        parameters={'oauth_nonce': uuid.uuid4().hex})
    oauth_request.sign_request(
        oauth.OAuthSignatureMethod_PLAINTEXT(), consumer_token,
        resource_token)
    headers = oauth_request.to_header()
    headers['Accept'] = 'application/json'
    return headers

uri = MAAS_API + "/machines/{system_id}/".format(
    system_id=system_id
)

params = {
    'hostname': 'herbert',
}
response = requests.put(
    uri, data=params, headers=get_auth_headers(consumer_key, key, secret)
)
# result is in response.json()
Download as text