Created
April 26, 2025 17:59
-
-
Save timfreund/9135f0a94af11fa6f5ae241b5a1f66a9 to your computer and use it in GitHub Desktop.
pylxd demo script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pylxd import Client | |
# change the following line and export it as an environment variable | |
# export REQUESTS_CA_BUNDLE=~/.config/incus/servercerts/YOURCLUSTER.crt | |
def create_instance(incus_client, name, image_alias): | |
iconfig = {'name': name, | |
'source': {'type': 'image', | |
'protocol': | |
'simplestreams', | |
'server': 'https://images.linuxcontainers.org', | |
'alias': image_alias}, | |
'type': 'container'} | |
incus_instance = incus_client.instances.create(iconfig) | |
return incus_instance | |
if __name__ == '__main__': | |
endpoint = 'https://YOURINCUS_SERVER_IP:8443' | |
cert_dir = '/home/YOURUSERNAME/.config/incus' | |
keypair = ('%s/client.crt' % cert_dir, | |
'%s/client.key' % cert_dir) | |
server_cert_path = "/home/YOURUSERNAME/.config/incus/servercerts/YOURCLUSTER.crt" | |
verify_value = server_cert_path | |
client = Client(endpoint=endpoint, | |
cert=keypair, | |
verify=verify_value, | |
project='cposc') | |
import IPython; IPython.embed() | |
# i = create_instance(client, "fromipython", "debian/12") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IPython | |
pylxd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment