~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to virtinst/_util.py

  • Committer: Bazaar Package Importer
  • Author(s): Jean-Louis Dupond
  • Date: 2010-05-05 03:32:42 UTC
  • mfrom: (1.3.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100505033242-um6f6pjcc89i07m0
Tags: 0.500.3-1ubuntu1
* Merge from debian unstable. (LP: #590068)  Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Added lucid and maverick to OS list and enable virtio for it.
  - debian/patches/0003-Fix-patch-to-keyboard-configuration.patch: disable
    as the keyboard config in Ubuntu is still in /etc/default/console-setup
    and this was causing virt-manager to always default to a en-us
    keyboard. (LP: #524318)
  - debian/control: added acl package to depends. (LP: #533048)
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin (LP: #215084)
* debian/patches/9002-add-ca-keymap.patch: dropped, its now in upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
153
153
        raise ValueError, _("%s name can only contain alphanumeric, '_', '.', "
154
154
                            "or '-' characters") % name_type
155
155
 
 
156
def validate_macaddr(val):
 
157
    if val is None:
 
158
        return
 
159
 
 
160
    if type(val) is not str:
 
161
        raise ValueError, _("MAC address must be a string.")
 
162
 
 
163
    form = re.match("^([0-9a-fA-F]{1,2}:){5}[0-9a-fA-F]{1,2}$", val)
 
164
    if form is None:
 
165
        raise ValueError(_("MAC address must be of the format "
 
166
                           "AA:BB:CC:DD:EE:FF"))
156
167
def xml_append(orig, new):
157
168
    """
158
169
    Little function that helps generate consistent xml
199
210
 
200
211
    @param msg: Option message to log before the backtrace
201
212
    """
 
213
    msg = str(msg)
202
214
    tb = "".join(traceback.format_exc()).strip()
203
215
    if tb != "None":
204
216
        if msg:
238
250
 
239
251
 
240
252
def generate_name(base, collision_cb, suffix="", lib_collision=True,
241
 
                  start_num=0, sep="-"):
 
253
                  start_num=0, sep="-", force_num=False):
242
254
    """
243
255
    Generate a new name from the passed base string, verifying it doesn't
244
256
    collide with the collision callback.
260
272
    @start_num: The number to start at for generating non colliding names
261
273
    @sep: The seperator to use between the basename and the generated number
262
274
          (default is "-")
 
275
    @force_num: Force the generated name to always end with a number
263
276
    """
264
277
 
265
278
    for i in range(start_num, start_num + 100000):
266
279
        tryname = base
267
 
        if i != 0:
 
280
        if i != 0 or force_num:
268
281
            tryname += ("%s%d" % (sep, i))
269
282
        tryname += suffix
270
283
        if lib_collision: