Skip to content

Commit

Permalink
improve export vm output
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Sep 25, 2024
1 parent e1bf13b commit 8fc3b92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kvirt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ def delete_dns(args):
def export_vm(args):
image = args.image
config = Kconfig(client=args.client, debug=args.debug, region=args.region, zone=args.zone, namespace=args.namespace)
names = [common.get_lastvm(config.client)] if not args.names else args.names
names = [common.get_lastvm(config.client)] if not args.name else args.name
k = config.k
codes = []
for name in names:
Expand Down Expand Up @@ -4640,7 +4640,7 @@ def cli():
epilog=vmexport_epilog, formatter_class=rawhelp)
vmexport_parser.add_argument('-i', '--image', help='Name for the generated image. Uses the vm name otherwise',
metavar='IMAGE')
vmexport_parser.add_argument('vm', metavar='VM', nargs='?')
vmexport_parser.add_argument('name', metavar='VM', nargs='*')
vmexport_parser.set_defaults(func=export_vm)

expose_desc = 'Expose Object'
Expand Down
6 changes: 4 additions & 2 deletions kvirt/providers/kvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from kvirt.defaults import IMAGES
from kvirt.defaults import UBUNTUS, METADATA_FIELDS
from kvirt import common
from kvirt.common import error, pprint, warning, get_ssh_pub_key
from kvirt.common import error, pprint, warning, get_ssh_pub_key, success
from kvirt.providers.kvm.helpers import DHCPKEYWORDS
from ipaddress import ip_address, ip_network
from libvirt import open as libvirtopen, registerErrorHandler, libvirtError
Expand Down Expand Up @@ -3785,7 +3785,8 @@ def _deletelvm(self, disk):
os.system(command)

def export(self, name, image=None):
newname = image if image is not None else "image-%s" % name
self.stop(name, soft=True)
newname = image if image is not None else f"image-{name}"
conn = self.conn
oldvm = conn.lookupByName(name)
oldxml = oldvm.XMLDesc(0)
Expand All @@ -3809,6 +3810,7 @@ def export(self, name, image=None):
newvolumexml = self._xmlvolume(newpath, oldvolumesize, backing=backing)
pool.createXMLFrom(newvolumexml, oldvolume, 0)
break
success(f"{newpath} generated")
return {'result': 'success'}

def _create_host_entry(self, name, ip, netname, domain):
Expand Down

0 comments on commit 8fc3b92

Please sign in to comment.