You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the python-oca API to start a VM on demand.
Start the new VM using:
import sys
import argparse
from xml.etree import ElementTree as ET
import oca
ADDRESS = 'https://api.hpccloud.surfsara.nl/RPC2'
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--memory', default=2048, type=int, help="Memory (MB)")
parser.add_argument('-c', '--cpu', default=2, type=int, help="Number of CPU cores")
args = parser.parse_args()
return args
def main(memory=2048, cpu=2):
options = f"memory={memory} cpu={cpu}"
client = oca.Client(None, address=ADDRESS)
# [secret,] ID, name, hold/pending, extra-attrs, persistent
vmid = client.call('template.instantiate', 10377, 'server', False, options, False)
print("Started VM with ID =", vmid)
if __name__ == '__main__':
args = parse_args()
main(memory=args.memory, cpu=args.cpu)
With the first argument to oca.Client as None, it grabs the credentials from a ~/.one/one_auth file, which is a standard one-liner file like: "cloud_login:cloud_pass"
See http://python-oca.github.io/python-oca/api/client.html
Use a sensible template (e.g. Ubuntu)
Then run an action on the VM using something similar to:
import sys
from xml.etree import ElementTree as ET
import oca
ADDRESS = 'https://api.hpccloud.surfsara.nl/RPC2'
client = oca.Client(None, address=ADDRESS)
r = client.call('vmpool.info', -1, -1, -1, -1)
root = ET.fromstring(r)
ET.dump(root)
id = root.find('VM/ID').text
print('VM ID =', id)
r = client.call('vm.action', sys.argv[1], int(id))
print(r)
The text was updated successfully, but these errors were encountered:
Use the python-oca API to start a VM on demand.
Start the new VM using:
oca.Client
as None, it grabs the credentials from a~/.one/one_auth
file, which is a standard one-liner file like: "cloud_login:cloud_pass"See http://python-oca.github.io/python-oca/api/client.html
Then run an action on the VM using something similar to:
The text was updated successfully, but these errors were encountered: