Пример #1
0
 def list(self):
     vms = []
     number = random.randint(1, 10)
     for i in range(number):
         name = random.choice(right)
         state = self.status(name)
         if state == 'up':
             ip = random_ip()
         else:
             ip = ''
         source = random.choice(self.templates + [''])
         plan = get_random_name()
         profile = 'kvirt'
         report = ''
         vms.append([name, state, ip, source, plan, profile, report])
     return sorted(vms)
Пример #2
0
    def info(self, name, vm=None):
        """

        :param name:
        :param vm:
        :return:
        """
        cpus = random.choice([1, 2, 4, 8])
        memory = random.choice([512, 1024, 2048, 4096, 8192])
        state = self.status(name)
        if state == 'up':
            ip = random_ip()
        else:
            ip = None
        template = random.choice(self.templates + [''])
        plan = get_random_name()
        profile = 'kvirt'
        yamlinfo = {'name': name, 'template': template, 'plan': plan, 'profile': profile, 'status': state, 'cpus': cpus,
                    'memory': memory}
        if ip is not None:
            yamlinfo['ip'] = ip
        disks, nets = [], []
        numnets = random.randint(1, 2)
        numdisks = random.randint(1, 3)
        for net in range(numnets):
            device = "eth%s" % net
            network = random.choice(right)
            network_type = 'routed'
            macs = []
            for i in range(6):
                element = random.choice('0123456789abcdef') + random.choice('0123456789abcdef')
                macs.append(element)
            mac = ':'.join(macs)
            nets.append({'device': device, 'mac': mac, 'net': network, 'type': network_type})
        for disk in range(numdisks):
            letter = chr(disk + ord('a'))
            device = 'vd%s' % letter
            disksize = random.choice([10, 20, 30, 40, 50])
            diskformat = 'file'
            drivertype = 'qcow2'
            path = '/var/lib/libvirt/images/%s_%s.img' % (name, disk)
            disks.append({'device': device, 'size': disksize, 'format': diskformat, 'type': drivertype, 'path': path})
        yamlinfo['nets'] = nets
        yamlinfo['disks'] = disks
        return yamlinfo