Example #1
0
    def generate_scenario_3_with_2_hypervisors(self):
        vms = []

        root = modelroot.ModelRoot()
        # number of nodes
        count_node = 2

        # define ressouce ( CPU, MEM disk, ... )
        mem = resource.Resource(resource.ResourceType.memory)
        # 2199.954 Mhz
        num_cores = resource.Resource(resource.ResourceType.cpu_cores)
        disk = resource.Resource(resource.ResourceType.disk)

        root.create_resource(mem)
        root.create_resource(num_cores)
        root.create_resource(disk)

        for i in range(0, count_node):
            node_uuid = "Node_{0}".format(i)
            node = hypervisor.Hypervisor()
            node.uuid = node_uuid
            node.hostname = "hostname_{0}".format(i)

            mem.set_capacity(node, 132)
            disk.set_capacity(node, 250)
            num_cores.set_capacity(node, 40)
            root.add_hypervisor(node)

        vm1 = modelvm.VM()
        vm1.uuid = "73b09e16-35b7-4922-804e-e8f5d9b740fc"
        mem.set_capacity(vm1, 2)
        disk.set_capacity(vm1, 20)
        num_cores.set_capacity(vm1, 10)
        vms.append(vm1)
        root.add_vm(vm1)

        vm2 = modelvm.VM()
        vm2.uuid = "a4cab39b-9828-413a-bf88-f76921bf1517"
        mem.set_capacity(vm2, 2)
        disk.set_capacity(vm2, 20)
        num_cores.set_capacity(vm2, 10)
        vms.append(vm2)
        root.add_vm(vm2)

        root.get_mapping().map(root.get_hypervisor_from_id("Node_0"),
                               root.get_vm_from_id(str(vm1.uuid)))

        root.get_mapping().map(root.get_hypervisor_from_id("Node_1"),
                               root.get_vm_from_id(str(vm2.uuid)))

        return root
Example #2
0
    def generate_scenario_1(self):
        '''
        Simulates a cluster with 2 hypervisors and
        2 VMs using 1:1 mapping
        '''
        current_state_cluster = modelroot.ModelRoot()
        count_node = 2
        count_vm = 2

        mem = resource.Resource(resource.ResourceType.memory)
        num_cores = resource.Resource(resource.ResourceType.cpu_cores)
        disk = resource.Resource(resource.ResourceType.disk)
        disk_capacity =\
            resource.Resource(resource.ResourceType.disk_capacity)

        current_state_cluster.create_resource(mem)
        current_state_cluster.create_resource(num_cores)
        current_state_cluster.create_resource(disk)
        current_state_cluster.create_resource(disk_capacity)

        for i in range(0, count_node):
            node_uuid = "Node_{0}".format(i)
            node = hypervisor.Hypervisor()
            node.uuid = node_uuid
            node.hostname = "hostname_{0}".format(i)
            node.state = 'up'

            mem.set_capacity(node, 64)
            disk_capacity.set_capacity(node, 250)
            num_cores.set_capacity(node, 40)
            current_state_cluster.add_hypervisor(node)

        for i in range(0, count_vm):
            vm_uuid = "VM_{0}".format(i)
            vm = modelvm.VM()
            vm.uuid = vm_uuid
            vm.state = vm_state.VMState.ACTIVE
            mem.set_capacity(vm, 2)
            disk.set_capacity(vm, 20)
            num_cores.set_capacity(vm, 10)
            current_state_cluster.add_vm(vm)

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_0"),
            current_state_cluster.get_vm_from_id("VM_0"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_1"),
            current_state_cluster.get_vm_from_id("VM_1"))

        return current_state_cluster
Example #3
0
    def generate_scenario_2(self):
        """Simulates a cluster

        With 4 hypervisors and  6 VMs all mapped to one hypervisor
        """

        current_state_cluster = modelroot.ModelRoot()
        count_node = 4
        count_vm = 6

        mem = resource.Resource(resource.ResourceType.memory)
        num_cores = resource.Resource(resource.ResourceType.cpu_cores)
        disk = resource.Resource(resource.ResourceType.disk)
        disk_capacity =\
            resource.Resource(resource.ResourceType.disk_capacity)

        current_state_cluster.create_resource(mem)
        current_state_cluster.create_resource(num_cores)
        current_state_cluster.create_resource(disk)
        current_state_cluster.create_resource(disk_capacity)

        for i in range(0, count_node):
            node_uuid = "Node_{0}".format(i)
            node = hypervisor.Hypervisor()
            node.uuid = node_uuid
            node.hostname = "hostname_{0}".format(i)
            node.state = 'up'

            mem.set_capacity(node, 64)
            disk_capacity.set_capacity(node, 250)
            num_cores.set_capacity(node, 16)
            current_state_cluster.add_hypervisor(node)

        for i in range(0, count_vm):
            vm_uuid = "VM_{0}".format(i)
            vm = modelvm.VM()
            vm.uuid = vm_uuid
            vm.state = vm_state.VMState.ACTIVE
            mem.set_capacity(vm, 2)
            disk.set_capacity(vm, 20)
            num_cores.set_capacity(vm, 10)
            current_state_cluster.add_vm(vm)

            current_state_cluster.get_mapping().map(
                current_state_cluster.get_hypervisor_from_id("Node_0"),
                current_state_cluster.get_vm_from_id("VM_%s" % str(i)))

        return current_state_cluster
Example #4
0
    def get_latest_cluster_data_model(self):
        LOG.debug("Getting latest cluster data model")

        cluster = model_root.ModelRoot()
        mem = resource.Resource(resource.ResourceType.memory)
        num_cores = resource.Resource(resource.ResourceType.cpu_cores)
        disk = resource.Resource(resource.ResourceType.disk)
        disk_capacity = resource.Resource(resource.ResourceType.disk_capacity)
        cluster.create_resource(mem)
        cluster.create_resource(num_cores)
        cluster.create_resource(disk)
        cluster.create_resource(disk_capacity)

        flavor_cache = {}
        hypervisors = self.wrapper.get_hypervisors_list()
        for h in hypervisors:
            service = self.wrapper.nova.services.find(id=h.service['id'])
            # create hypervisor in cluster_model_collector
            hypervisor = obj_hypervisor.Hypervisor()
            hypervisor.uuid = service.host
            hypervisor.hostname = h.hypervisor_hostname
            # set capacity
            mem.set_capacity(hypervisor, h.memory_mb)
            disk.set_capacity(hypervisor, h.free_disk_gb)
            disk_capacity.set_capacity(hypervisor, h.local_gb)
            num_cores.set_capacity(hypervisor, h.vcpus)
            hypervisor.state = h.state
            hypervisor.status = h.status
            cluster.add_hypervisor(hypervisor)
            vms = self.wrapper.get_vms_by_hypervisor(str(service.host))
            for v in vms:
                # create VM in cluster_model_collector
                vm = obj_vm.VM()
                vm.uuid = v.id
                # nova/nova/compute/vm_states.py
                vm.state = getattr(v, 'OS-EXT-STS:vm_state')

                # set capacity
                self.wrapper.get_flavor_instance(v, flavor_cache)
                mem.set_capacity(vm, v.flavor['ram'])
                disk.set_capacity(vm, v.flavor['disk'])
                num_cores.set_capacity(vm, v.flavor['vcpus'])

                cluster.get_mapping().map(hypervisor, vm)
                cluster.add_vm(vm)
        return cluster
Example #5
0
    def generate_scenario_5_with_vm_disk_0(self):
        vms = []
        current_state_cluster = modelroot.ModelRoot()
        # number of nodes
        count_node = 1
        # number of vms
        count_vm = 1

        # define ressouce ( CPU, MEM disk, ... )
        mem = resource.Resource(resource.ResourceType.memory)
        # 2199.954 Mhz
        num_cores = resource.Resource(resource.ResourceType.cpu_cores)
        disk = resource.Resource(resource.ResourceType.disk)

        current_state_cluster.create_resource(mem)
        current_state_cluster.create_resource(num_cores)
        current_state_cluster.create_resource(disk)

        for i in range(0, count_node):
            node_uuid = "Node_{0}".format(i)
            node = hypervisor.Hypervisor()
            node.uuid = node_uuid
            node.hostname = "hostname_{0}".format(i)

            mem.set_capacity(node, 4)
            disk.set_capacity(node, 4)
            num_cores.set_capacity(node, 4)
            current_state_cluster.add_hypervisor(node)

        for i in range(0, count_vm):
            vm_uuid = "VM_{0}".format(i)
            vm = modelvm.VM()
            vm.uuid = vm_uuid
            mem.set_capacity(vm, 2)
            disk.set_capacity(vm, 0)
            num_cores.set_capacity(vm, 4)
            vms.append(vm)
            current_state_cluster.add_vm(vm)

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_0"),
            current_state_cluster.get_vm_from_id("VM_0"))

        return current_state_cluster
Example #6
0
    def generate_scenario_1(self):
        vms = []

        current_state_cluster = modelroot.ModelRoot()
        # number of nodes
        count_node = 5
        # number max of vm per node
        node_count_vm = 7
        # total number of virtual machine
        count_vm = (count_node * node_count_vm)

        # define ressouce ( CPU, MEM disk, ... )
        mem = resource.Resource(resource.ResourceType.memory)
        # 2199.954 Mhz
        num_cores = resource.Resource(resource.ResourceType.cpu_cores)
        disk = resource.Resource(resource.ResourceType.disk)

        current_state_cluster.create_resource(mem)
        current_state_cluster.create_resource(num_cores)
        current_state_cluster.create_resource(disk)

        for i in range(0, count_node):
            node_uuid = "Node_{0}".format(i)
            node = hypervisor.Hypervisor()
            node.uuid = node_uuid
            node.hostname = "hostname_{0}".format(i)

            mem.set_capacity(node, 132)
            disk.set_capacity(node, 250)
            num_cores.set_capacity(node, 40)
            current_state_cluster.add_hypervisor(node)

        for i in range(0, count_vm):
            vm_uuid = "VM_{0}".format(i)
            vm = modelvm.VM()
            vm.uuid = vm_uuid
            mem.set_capacity(vm, 2)
            disk.set_capacity(vm, 20)
            num_cores.set_capacity(vm, 10)
            vms.append(vm)
            current_state_cluster.add_vm(vm)

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_0"),
            current_state_cluster.get_vm_from_id("VM_0"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_0"),
            current_state_cluster.get_vm_from_id("VM_1"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_1"),
            current_state_cluster.get_vm_from_id("VM_2"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_2"),
            current_state_cluster.get_vm_from_id("VM_3"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_2"),
            current_state_cluster.get_vm_from_id("VM_4"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_2"),
            current_state_cluster.get_vm_from_id("VM_5"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_3"),
            current_state_cluster.get_vm_from_id("VM_6"))

        current_state_cluster.get_mapping().map(
            current_state_cluster.get_hypervisor_from_id("Node_4"),
            current_state_cluster.get_vm_from_id("VM_7"))

        return current_state_cluster