def describe_simulation_scenario():
    """ Describes the simulation scenario with all created objects and its relationships
    """

    occupation_rate = 0
    for server in Server.all():
        occupation_rate += server.occupation_rate()
    occupation_rate = occupation_rate / Server.count()

    print(f'DATASET NAME: {OUTPUT_FILE_NAME}.json')
    print(f'DATA CENTER OCCUPATION: {round(occupation_rate)}% ({occupation_rate})')
def create_servers():
    """ Creates Server objects according to user-specified parameters.
    """

    for _ in range(SERVERS):
        # Creating object
        server = Server(id=None, cpu=None, memory=None, disk=None, updated=None)

        # Defining values for the object attributes
        server.id = Server.count()

        server.cpu_capacity = SERVERS_CAPACITY[0][0]
        server.memory_capacity = SERVERS_CAPACITY[0][1]
        server.disk_capacity = SERVERS_CAPACITY[0][2]
        server.updated = SERVERS_UPDATE_STATUS[0]
        server.patch_duration = SERVERS_PATCH_DURATION[0][0]
        server.sanity_check_duration = SERVERS_PATCH_DURATION[0][1]

        # Updating attribute lists after the object is created
        SERVERS_CAPACITY.pop(0)
        SERVERS_UPDATE_STATUS.pop(0)
        SERVERS_PATCH_DURATION.pop(0)
Пример #3
0
def show_metrics(dataset, heuristic, output_file=None):
    """ Presents information and metrics of the performed placement
    and optionally stores these results into an output CSV file.

    Currently, this method outputs the following metrics:
        - Servers occupation rate
        - Servers consolidation rate

    Parameters
    ==========
    dataset : String
        Name of the used dataset

    heuristic : STring
        Name of the used placement heuristic

    output_file : String
        Optional parameters regarding the name of the output CSV file
    """

    # Servers occupation rate
    occupation_rate = sum(sv.occupation_rate()
                          for sv in Server.all()) / len(Server.used_servers())

    # Servers consolidation rate
    consolidation_rate = Server.consolidation_rate()

    # Prints out the placement metrics
    print(
        '========================\n== SIMULATION RESULTS ==\n========================'
    )

    print(f'Dataset: "{dataset}"')
    print(f'Placement Strategy: {heuristic}\n')

    print(f'Consolidation Rate: {consolidation_rate}')
    print(f'Occupation Rate: {occupation_rate}\n')

    print('Placement:')
    for server in Server.all():
        vms = [vm.id for vm in server.virtual_machines]
        print(f'SV_{server.id}. VMs: {vms}')

    # If the output_file parameter was provided, stores the placement results into a CSV file
    if output_file:

        with open(output_file, mode='w') as csv_file:
            output_writer = csv.writer(csv_file,
                                       delimiter='\t',
                                       quotechar='"',
                                       quoting=csv.QUOTE_MINIMAL)

            # Creating header
            output_writer.writerow([
                'Dataset', 'Strategy', 'No. of Servers', 'No. of VMs',
                'Occupation Rate', 'Consolidation Rate'
            ])

            # Creating body
            output_writer.writerow([
                dataset, heuristic,
                Server.count(),
                VirtualMachine.count(), occupation_rate, consolidation_rate
            ])