| class VirtualMachine: |
| def __init__(self, vm_id, capacity): |
| self.vm_id = vm_id |
| self.capacity = capacity |
| self.current_workload = 0 |
| def assign_task(self, task): |
| self.current_workload + = task |
| def get_utilization(self): |
| return self.current_workload/self.capacity |
| class LoadBalancer: |
| def __init__(self, vms): |
| self.vms = vms |
| def balance_load(self, task): |
| # Simple load balancing: Assign the task to the VM with the lowest current workload |
| target_vm = min(self.vms, key = lambda vm: vm.current_workload) |
| target_vm.assign_task (task) |
| def print_utilization(self): |
| for vm in self.vms: |
| print (f“VM {vm.vm_id} Utilization: {vm.get_utilization()}”) |
| # Example usage |
| if __name__ = = “__main__”: |
| # Create virtual machines |
| vm1 = VirtualMachine (vm_id = 1, capacity = 120) |
| vm2 = VirtualMachine (vm_id = 2, capacity = 170) |
| vm3 = VirtualMachine (vm_id = 3, capacity = 130) |
| vms = [vm1, vm2, vm3] |
| # Create a load balancer |
| load_balancer = LoadBalancer (vms) |
| # Simulate tasks and load balancing |
| tasks = [30, 40, 15, 25, 10] |
| for task in tasks: |
| load_balancer.balance_load (task) |
| # Print VM utilizations |
| load_balancer.print_utilization() |
| Level 1 of Cargo process |
| Select: Accept the user’s request. |
| Results: Distribute resources using a sophisticated algorithm |
| Case1: |
| Call Allotment_agent (Cargo info) and Master_Commit_Agent (Cargo info) for each node in Table 4 with status = “Empty.” |
| Case 2: |
| For every node N_Node with Status = “Normal” in Table 2, |
| { |
| If (N_Node.Availablememory-requested_memory >25%)∼{ Call Allotment_agent() Call Master_Commit_Agent() } |
| Case 3: |
| If (no node with the statuses “Free” or “Normal” is accessible in Table 2) |
| Call Passage_Agent(); |
| Level 2 Allotment Process (i)Update Tables 2 and 3 and create a VM in the chosen node with the needed cargo information. (ii)Using the information in the Node Resource Table, compute the modified node’s fitness value. |
| µtotal = µavailable [from Node_Resource_Table]–µused [According to Table 2] |
| v% = µavailable/µtotal × 100 |
| if (v >75%) |
| { |
| Allotment_status = Empty |
| } |
| Otherwise, if (Allotment_status >25%) |
| { |
| Allotment_status = Normal |
| } |
| Otherwise, Allotment_status = critical |
| Refresh Tables 2 and 3. |
| Agent for travel () |
| { |
| Provide: Get the container agency |
| To obtain the Non-Critical DC, initiate the Relocation agent. |
| Please forward the request to DC. |
| } |
| Relocation process() |
| { |
| Scan Table 4 |
| Select the DC that is least loaded and give the Passage agent back the DCID. |
| } //sample can be shown in Figure 5. |
| Cargo Information: Master_Commit Agent |
| { |
| Add the information of the cargo to Table 4. |
| Determine the Zone’s fitness value by using the information shown in Table outlined below: |
| From the Prime DC Resource Table, µavailable = µtotal. Used from the Prime DC Cargo Table |
| v% is equal to available divided by total times 100. |
| The allocation status is empty if (v >75%) |
| If (Allotment_status >25%), then } Else |
| The allocation status is Normal. |
| Otherwise, allocation_status = critical |
| Make Table 4 updates |