Edit a profile with .yaml
tkasidakis opened this issue · 1 comments
Hello to everyone.
I have a .yaml file.
When i am doing
sudo lxc profile edit routed_192.168.2.20 < net_192.168.2.20.yaml
routed_192.168.2.20 is configured well
config: user.network-config: | version: 2 ethernets: eth0: addresses: - 192.168.2.20/32 nameservers: addresses: - 8.8.8.8 search: [] routes: - to: 0.0.0.0/0 via: 169.254.0.1 on-link: true description: Default LXD profile devices: eth0: ipv4.address: 192.168.2.20 nictype: routed parent: wlp6s0 type: nic name: routed_192.168.2.20 used_by: []
When i am trying the same inside a python script it doesn't work.
command4LXD = ['sudo','lxc','profile','edit','routed_'+possibleIP,' < ',name4yaml]
subprocess.run(command4LXD)
It prints :
...........................................................................
Description:
Edit profile configurations as YAML
Usage:
lxc profile edit [:] [flags]
...................................................................................................
When i am doing
command = "sudo lxc profile edit " + "routed_"+possibleIP + " < " + name4yaml
os.system(command)
it works , but when i am doing
sudo lxc profile show routed_192.168.2.20
the output looks like this
config: {} description: "" devices: {} name: routed_192.168.2.20 used_by: []
Any help ? Can i achieve the same result using pylxd ?
Thanks in advance !!
Yes, this kind of thing can be done with pylxd. You want the profile
part of the API which is detailed here: https://github.com/lxc/lxd/blob/master/doc/rest-api.md#10profiles
You use the profiles part of pylxd: https://pylxd.readthedocs.io/en/latest/profiles.html
Use the ipython repl to explore what you can do with the API; it'll give you a feel for how to achieve things. Code that uses the profile: https://opendev.org/x/nova-lxd/src/branch/stable/rocky/nova/virt/lxd/flavor.py -- it's a bit hairy but focus in the client.profile.*
bits.
The subprocess.run()
didn't work as you can't use a pipe (<
) in the list passed to run()
... it just doesn't work that way. Please read up on how subprocess works, and how you can pipe stuff to and from it.
Closing as it's not a bug. Please re-open if you find a bug related to this behaviour. Thanks.