client = $client; } public function getAllTemplate() { if ($this->client->checkApiExits()) { $response = Http::withoutVerifying() ->withHeaders([ 'vmware-api-session-id' => $this->client->token ]) ->get("https://{$this->client->apiUri}/rest/com/vmware/content/library")->json(); if (!isset($response['type'])) { return $response['value']; } return false; } return "Login_Again"; } public function getTemplatebyID($template = '') { $response = Http::withoutVerifying() ->withHeaders([ 'vmware-api-session-id' => $this->client->token ]) ->get("https://{$this->client->apiUri}/rest/com/vmware/content/library/id:{$template}")->json(); if (!isset($response['type'])) { return $response['value']['storage_backings'][0]['datastore_id']; } return false; } public function getTemplateFromDatastore($datastore = '') { $allTemplate = $this->getAllTemplate(); if (!$allTemplate) { return false; } foreach ($allTemplate as $template) { $detailTemplate = $this->getTemplatebyID($template); if ($detailTemplate && $detailTemplate === $datastore) { return $template; } } return false; } public function getVersionDetail($version_id = '') { $response = Http::withoutVerifying() ->withHeaders([ 'vmware-api-session-id' => $this->client->token ]) ->get("https://{$this->client->apiUri}/rest/com/vmware/content/library/item/id:{$version_id}")->json(); if (!isset($response['type'])) { return $response['value']; } return false; } public function getAllVersion($library = ''): bool|array|string { if ($this->client->checkApiExits()) { $response = Http::withoutVerifying() ->withHeaders([ 'vmware-api-session-id' => $this->client->token ]) ->get("https://{$this->client->apiUri}/rest/com/vmware/content/library/item", [ 'library_id' => $library ])->json(); if (!isset($response['type'])) { $library_item = []; foreach ($response['value'] as $value) { $value_detail = $this->getVersionDetail($value); if ($value_detail) { $library_item[] = [ 'name' => $value_detail['name'], 'id' => $value_detail['id'] ]; } } return $library_item; } return false; } return "Login_Again"; } }