def test_correct_number_of_cpus_have_been_allocated_for_requested_cpu_count(self): requested_num_of_cpu = 5 result = instance_allocator.instances_for_given_cpu_count(self.region_dict, 5, requested_num_of_cpu)[0] server_list = result['servers'] allocated_cpu = 0 for each_server in server_list: allocated_cpu = allocated_cpu + each_server[1] * self.instance_dict[each_server[0]] self.assertEqual(requested_num_of_cpu, allocated_cpu)
def test_getting_instance_count_for_valid_hours_and_valid_cpu_count_returns_proper_output( self): self.assertEqual( instance_allocator.instances_for_given_cpu_count( self.region_dict, 3, 5), [{ 'region': 'us-east', 'servers': [('large', 1), ('2xlarge', 1)], 'total_cost': '$1.71' }])
def test_getting_instance_count_with_valid_hours_and_negative_cpu_returns_error( self): self.assertEqual( instance_allocator.instances_for_given_cpu_count( self.region_dict, 4, -1), [{ 'ERROR': "Hours and/or " "CPU count must be " "greater than " "zero" }])
def get_costs(n_cpu=None, n_hours=1, max_price=None): region_dict = read_cost('cost_file.json') if n_cpu is not None: if max_price is not None: print("CPU + Max prize combo") result = instance_allocator.instances_for_given_cpu_and_price( region_dict, n_hours, n_cpu, max_price) else: print("CPU + H hours combo") result = instance_allocator.instances_for_given_cpu_count( region_dict, n_hours, n_cpu) elif max_price is not None: print("Max price + H hours combo") result = instance_allocator.instances_for_given_price( region_dict, n_hours, max_price) else: print("Invalid input combo") result = [{'ERROR': 'Invalid input combination'}] pretty_result(result)