public function addRecord($record) { // Add a record to the usage structure. if ($record instanceof UsageInstance) { $entry = $this->getInstance($record->vmInstanceId, $record->serviceOfferingId); if ($entry === false) { // Create a new entry $entry = ['startdate' => $record->startDate, 'enddate' => $record->endDate, 'resources' => ['cpunumber' => $record->cpuNumber, 'memory' => $record->memory], 'usage' => $record->usage, 'name' => $record->vm_name]; } else { // Add usage from the record we have to the existing VM entry. $entry['usage'] += $record->usage; // If the start date of the record is before our VM's start date, use the if ($record->startDate->lt($entry['startdate'])) { $entry['startdate'] = $record->startDate; } // Same treatment for the end date. if ($record->endDate->gt($entry['enddate'])) { $entry['enddate'] = $record->endDate; } } // Save the entry $this->_instances[$record->vmInstanceId][$record->serviceOfferingId] = $entry; } else { if ($record instanceof UsageDisk) { $entry = $this->getDisk($record->volumeId); if ($entry === false) { $diskType = DiskType::whereTags($record->tags)->first(); $entry = ['startdate' => $record->startDate, 'enddate' => $record->endDate, 'size' => $record->size, 'acs_type' => $record->type, 'usage' => $record->usage, 'instance' => $record->vmInstanceId]; if ($diskType instanceof DiskType) { $entry['type'] = $diskType->id; } } else { $entry['usage'] += $record->usage; // If the start date of the record is before our VM's start date, use the if ($record->startDate->lt($entry['startdate'])) { $entry['startdate'] = $record->startDate; } // Same treatment for the end date. if ($record->endDate->gt($entry['enddate'])) { $entry['enddate'] = $record->endDate; } } $this->_disks[$record->volumeId] = $entry; } } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $domainId = SiteConfig::whereParameter('domainId')->first()->data; // Find the one VM for $id. listVMs returns an array of stdObjects representing virtualMachines. $vm = $this->acs->listVirtualMachines(['id' => $id])[0]; $disk = $this->acs->listVolumes(['virtualmachineid' => $vm->id, 'listall' => 'true', 'type' => 'ROOT'])[0]; $serviceOffering = $this->acs->listServiceOfferings(['id' => $vm->serviceofferingid])[0]; $diskType = DiskType::whereTags($serviceOffering->tags)->first(); $snapshots = $this->acs->listSnapshots(['volmueid' => $disk->id, 'account' => Auth::User()->email, 'domainid' => $domainId]); return view('instance.show')->with(compact('vm', 'disk', 'diskType', 'snapshots')); }