GitHub user YashasAnand added a comment to the discussion: How to call
scaleVirtualMachine api with details parameter
Hi @bernardodemarco @weizhouapache Thank you for your respective responses.
Below is my python code.
`import hashlib
import hmac
import base64
import urllib.parse
import json
def generate_signature(baseurl, request, secretkey):
# Encode keys and values properly
encoded_request = {urllib.parse.quote_plus(k):
urllib.parse.quote_plus(str(v)) for k, v in request.items()}
# Build the sorted signature string
sorted_request = sorted(encoded_request.items(), key=lambda x: x[0].lower())
sig_str = '&'.join(['='.join([k.lower(), v.lower()]) for k, v in
sorted_request])
# Compute the HMAC SHA-1 signature
sig = hmac.new(secretkey.encode('utf-8'), sig_str.encode('utf-8'),
hashlib.sha1).digest()
# Encode the signature in base64 and URL encode it
encoded_sig = base64.b64encode(sig).decode('utf-8')
final_signature = urllib.parse.quote_plus(encoded_sig)
# Build the final request string
request_str = '&'.join(['='.join([k, v]) for k, v in
encoded_request.items()])
return final_signature, request_str
# Define the base URL and request parameters
baseurl = 'basrurl'
request = {
'command': 'scaleVirtualMachine',
'id': 'id', # ID of the system VM
'serviceofferingid': 'serviceofferingid',
'response': 'json',
'details[0].memory': 3072,
'details[0].cpuNumber': 2
}
secretkey = 'secret key'
# Generate the signature
signature, request_str = generate_signature(baseurl, request, secretkey)
# Construct the full URL with the signature
req = baseurl + request_str + '&signature=' + signature
# Print the final request URL
print("Final Request URL:", req)`
I am getting response like this but i dont observe any scaling happening on the
vm even though i have domain admin access. Pls can you suggest what might be
the issue.
`{
"scalevirtualmachineresponse": {
"jobid": "f75d1e48-132e-4b5c-9241-9115271dc08e"
}
}`
GitHub link:
https://github.com/apache/cloudstack/discussions/9961#discussioncomment-11345010
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]