@@ -695,13 +695,17 @@ def _set_param(paramname, keyname, val=None):
695695def parse_vcpu_option (guest , optstring , default_vcpus ):
696696 """
697697 Helper to parse --vcpu string
698+
699+ @param guest: virtinst.Guest instance (object)
700+ @param optstring: value of the option '--vcpus' (str)
701+ @param default_vcpus: ? (it should be None at present.)
698702 """
699703 vcpus , opts = parse_optstr (optstring , remove_first = True )
700704 vcpus = vcpus or default_vcpus
701705
702706 set_param = _build_set_param (guest , opts )
703707 set_cpu_param = _build_set_param (guest .cpu , opts )
704- has_vcpus = ("vcpus" in opts or vcpus )
708+ has_vcpus = ("vcpus" in opts or ( vcpus is not None ) )
705709
706710 set_param ("vcpus" , "vcpus" , vcpus )
707711 set_param ("maxvcpus" , "maxvcpus" )
@@ -718,21 +722,29 @@ def parse_vcpu_option(guest, optstring, default_vcpus):
718722
719723
720724def get_vcpus (vcpus , check_cpu , guest , image_vcpus = None ):
721- if vcpus is None and image_vcpus is not None :
722- vcpus = int (image_vcpus )
725+ """
726+ @param vcpus: value of the option '--vcpus' (str or None)
727+ @param check_cpu: Whether to check that the number virtual cpus requested
728+ does not exceed physical CPUs (bool)
729+ @param guest: virtinst.Guest instance (object)
730+ @param image_vcpus: ? (It's not used currently and should be None.)
731+ """
732+ if vcpus is None :
733+ if image_vcpus is not None :
734+ vcpus = image_vcpus
735+ else :
736+ vcpus = ""
723737
724738 parse_vcpu_option (guest , vcpus , image_vcpus )
725739
726- conn = guest .conn
727740 if check_cpu :
728- vcpucount = str (guest .vcpus )
729-
730- hostinfo = conn .getInfo ()
731- cpu_num = hostinfo [4 ] * hostinfo [5 ] * hostinfo [6 ] * hostinfo [7 ]
732- if not vcpus <= cpu_num :
733- msg = _ ("You have asked for more virtual CPUs (%s) than there "
734- "are physical CPUs (%s) on the host. This will work, "
735- "but performance will be poor. " ) % (vcpucount , cpu_num )
741+ hostinfo = guest .conn .getInfo ()
742+ pcpus = hostinfo [4 ] * hostinfo [5 ] * hostinfo [6 ] * hostinfo [7 ]
743+
744+ if guest .vcpus > pcpus :
745+ msg = _ ("You have asked for more virtual CPUs (%d) than there "
746+ "are physical CPUs (%d) on the host. This will work, "
747+ "but performance will be poor. " ) % (guest .vcpus , pcpus )
736748 askmsg = _ ("Are you sure? (yes or no)" )
737749
738750 if not prompt_for_yes_or_no (msg , askmsg ):
0 commit comments