~racb/ubuntu/precise/cobbler/858860

« back to all changes in this revision

Viewing changes to koan/app.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Clint Byrum, Robie Basak
  • Date: 2011-11-15 12:35:40 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20111115123540-5g139uuhg7z0hv5d
Tags: 2.2.2-0ubuntu1
[Chuck Short]
* New upstream release:
  + Use dh_python2 everywhere.
  + Folded debian/patches/49_ubuntu_add_arm_arch_support.patch
    and debian/patches/56_ubuntu_arm_generate_pxe_files.patch
    into one patch for easier upstreaming.
  + Dropped debian/patches/50_fix_cobbler_timezone.patch:
    Fix upstream.
  + Dropped debian/patches/47_ubuntu_add_oneiric_codename.patch
    in favor of debian/patches/47_ubuntu_add_codenames.patch:
    It adds "precise" and drops unsupported releases as well.
  + Dropped debian/patches/41_update_tree_path_with_arch.patch:
    No longer needed.
  + Dropped debian/patches/55_ubuntu_branding.patch: Will be moved
    to orchestra

 [Clint Byrum]
 * debian/cobbler.postinst: create users.digest mode 0600 so it
   is not world readable. (LP: #858860)
 * debian/control: cobbler needs to depend on python-cobbler
   (LP: #863738)
 * debian/patches/58_fix_egg_cache.patch: Do not point dangerous
   PYTHON_EGG_CACHE at world writable directory. (LP: #858875)
 * debian/cobbler-common.install: remove users.digest as it is
   not required and contains a known password that would leave
   cobblerd vulnerable if started before configuration is done
 * debian/cobbler-web.postinst: fix perms on webui_sessions to
   be more secure (LP: #863755)

 [Robie Basak]
 * Backport safe YAML load from upstream. (LP: #858883)

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
import sys
58
58
import xmlrpclib
59
59
import string
60
 
import re
61
60
import glob
62
61
import socket
63
62
import utils
79
78
   "netboot_enabled",
80
79
   "kernel_options",
81
80
   "repos",
82
 
   "virt_ram","virt_disk","virt_type", "virt_path", "virt_auto_boot"
 
81
   "virt_ram",
 
82
   "virt_disk",
 
83
   "virt_disk_driver",
 
84
   "virt_type",
 
85
   "virt_path",
 
86
   "virt_auto_boot",
83
87
]
84
88
 
85
89
 
153
157
                 help="use static network configuration from this interface while installing")
154
158
    p.add_option("-t", "--port",
155
159
                 dest="port",
156
 
                 help="cobbler xmlrpc port (default 25151)")
 
160
                 help="cobbler port (default 80)")
157
161
    p.add_option("-w", "--vm-poll",
158
162
                 dest="should_poll",
159
163
                 action="store_true",
197
201
                 help="When used with  --replace-self, embed the kickstart in the initrd to overcome potential DHCP timeout issues. (seldom needed)")
198
202
    p.add_option("", "--qemu-disk-type",
199
203
                 dest="qemu_disk_type",
200
 
                 help="when used with --virt_type=qemu, add select of disk drivers: ide,scsi,virtio")
 
204
                 help="when used with --virt_type=qemu, add select of disk driver types: ide,scsi,virtio")
 
205
    p.add_option("", "--qemu-net-type",
 
206
                 dest="qemu_net_type",
 
207
                 help="when used with --virt_type=qemu, select type of network device to use: e1000, ne2k_pci, pcnet, rtl8139, virtio")
201
208
 
202
209
    (options, args) = p.parse_args()
203
210
 
229
236
        k.embed_kickstart     = options.embed_kickstart
230
237
        k.virt_auto_boot      = options.virt_auto_boot
231
238
        k.qemu_disk_type      = options.qemu_disk_type
 
239
        k.qemu_net_type       = options.qemu_net_type
232
240
 
233
241
        if options.virt_name is not None:
234
242
            k.virt_name          = options.virt_name
286
294
        self.virt_path         = None
287
295
        self.force_path        = None
288
296
        self.qemu_disk_type    = None
 
297
        self.qemu_net_type     = None
289
298
        self.virt_auto_boot    = None
290
299
 
291
300
        # This option adds the --copy-default argument to /sbin/grubby
359
368
            if self.virt_type not in [ "qemu", "auto" ]:
360
369
               raise InfoException, "--qemu-disk-type must use with --virt-type=qemu"
361
370
 
 
371
        # if --qemu-net-type was called without --virt-type=qemu, then fail
 
372
        if (self.qemu_net_type is not None):
 
373
            self.qemu_net_type = self.qemu_net_type.lower()
 
374
            if self.virt_type not in [ "qemu", "auto" ]:
 
375
               raise InfoException, "--qemu-net-type must use with --virt-type=qemu"
 
376
 
362
377
 
363
378
 
364
379
        # if --static-interface and --profile was called together, then fail
1211
1226
 
1212
1227
        if self.server:
1213
1228
            if kernel[0] == "/":
1214
 
                kernel = "http://%s/cobbler/images/%s/%s" % (self.server, distro, kernel_short)
 
1229
                kernel = "http://%s/cobbler/images/%s/%s" % (profile_data["http_server"], distro, kernel_short)
1215
1230
            if initrd[0] == "/":
1216
 
                initrd = "http://%s/cobbler/images/%s/%s" % (self.server, distro, initrd_short)
 
1231
                initrd = "http://%s/cobbler/images/%s/%s" % (profile_data["http_server"], distro, initrd_short)
1217
1232
 
1218
1233
        try:
1219
1234
            print "downloading initrd %s to %s" % (initrd_short, initrd_save)
1264
1279
                interface_data = self.safe_load(interfaces, interface_name)
1265
1280
 
1266
1281
            ip = self.safe_load(interface_data, "ip_address")
1267
 
            subnet = self.safe_load(interface_data, "subnet")
 
1282
            netmask = self.safe_load(interface_data, "netmask")
1268
1283
            gateway = self.safe_load(pd, "gateway")
1269
1284
 
1270
1285
            hashv["ksdevice"] = self.static_interface
1271
1286
            if ip is not None:
1272
1287
                hashv["ip"] = ip
1273
 
            if subnet is not None:
1274
 
                hashv["netmask"] = subnet
 
1288
            if netmask is not None:
 
1289
                hashv["netmask"] = netmask
1275
1290
            if gateway is not None:
1276
1291
                hashv["gateway"] = gateway
1277
1292
 
1308
1323
        vcpus               = self.calc_virt_cpus(pd)
1309
1324
        path_list           = self.calc_virt_path(pd, virtname)
1310
1325
        size_list           = self.calc_virt_filesize(pd)
1311
 
        disks               = self.merge_disk_data(path_list,size_list)
 
1326
        driver_list         = self.calc_virt_drivers(pd)
 
1327
        disks               = self.merge_disk_data(path_list,size_list,driver_list)
1312
1328
        virt_auto_boot      = self.calc_virt_autoboot(pd, self.virt_auto_boot)
1313
1329
 
1314
1330
        results = create_func(
1325
1341
                bridge           =  self.virt_bridge,
1326
1342
                virt_type        =  self.virt_type,
1327
1343
                virt_auto_boot   =  virt_auto_boot,
1328
 
                qemu_driver_type =  self.qemu_disk_type
 
1344
                qemu_driver_type =  self.qemu_disk_type,
 
1345
                qemu_net_type    =  self.qemu_net_type
1329
1346
        )
1330
1347
 
1331
1348
        print results
1416
1433
 
1417
1434
    #---------------------------------------------------
1418
1435
 
1419
 
    def merge_disk_data(self, paths, sizes):
 
1436
    def merge_disk_data(self, paths, sizes, drivers):
1420
1437
        counter = 0
1421
1438
        disks = []
1422
1439
        for p in paths:
1425
1442
                size = sizes[-1]
1426
1443
            else:
1427
1444
                size = sizes[counter]
1428
 
            disks.append([path,size])
 
1445
            driver = drivers[counter]
 
1446
            disks.append([path,size,driver])
1429
1447
            counter = counter + 1
1430
1448
        if len(disks) == 0:
1431
 
            print "paths: ", paths
1432
 
            print "sizes: ", sizes
 
1449
            print "paths:   ", paths
 
1450
            print "sizes:   ", sizes
 
1451
            print "drivers: ", drivers
1433
1452
            raise InfoException, "Disk configuration not resolvable!"
1434
1453
        return disks
1435
1454
 
1499
1518
 
1500
1519
    #---------------------------------------------------
1501
1520
 
 
1521
    def calc_virt_drivers(self,data):
 
1522
        driver = self.safe_load(data,'virt_disk_driver',default='raw')
 
1523
 
 
1524
        tokens = driver.split(",")
 
1525
        accum = []
 
1526
        for t in tokens:
 
1527
            # FIXME: this list should be pulled out of 
 
1528
            #        the virtinst VirtualDisk class, but
 
1529
            #        not all versions of virtinst have a 
 
1530
            #        nice list to use
 
1531
            if t in ('raw','qcow','aio'):
 
1532
               accum.append(t)
 
1533
            else:
 
1534
               print "invalid disk driver specified, defaulting to 'raw'"
 
1535
               accum.append('raw')
 
1536
        return accum
 
1537
 
 
1538
    #---------------------------------------------------
 
1539
 
1502
1540
    def calc_virt_ram(self,data,default_ram=64):
1503
1541
        """
1504
1542
        Assign a virt ram size if none is given in the profile.
1655
1693
            cmd = sub_process.Popen(args, stdout=sub_process.PIPE, shell=True)
1656
1694
            freespace_str = cmd.communicate()[0]
1657
1695
            freespace_str = freespace_str.split("\n")[0].strip()
1658
 
            freespace_str = re.sub("(?i)G","", freespace_str) # remove gigabytes
 
1696
            freespace_str = freespace_str.lower().replace("g","") # remove gigabytes
1659
1697
            print "(%s)" % freespace_str
1660
1698
            freespace = int(float(freespace_str))
1661
1699