Open
Description
How t get single instance details?
I could not find how to get a single instance using the api in the documentation. I am now fetching all instances and making a filter function to retrieve one instance, which is not optimal.
/**
* @param {{
* instancePrefix: string;
* region: string;
* }} param0
* @returns {Promise<
* {
* name: string | undefined;
* id: string | undefined;
* status: string | undefined;
* ip: string | undefined;
* }[]
* >}
*/
async getInstancesFromProvider({ instancePrefix, region }) {
try {
const token = await getOSToken();
// get current region
const url_splitted = config.openstack.servers_url.split(".");
url_splitted[1] = region.toLowerCase();
const url = url_splitted.join(".");
const headers = {
"X-Auth-Token": token,
};
const response = await axios.get(url, { headers });
// get instances array
let instances = response.data.servers;
// format return output
instances = this.processInstancesFromOpenstack(instances);
// retrive one instance using js filter function :/
let instancesOS = instances.filter((instanceOS) => instanceOS.name.includes(instancePrefix));
return instancesOS;
} catch (error) {
console.log(error);
throw new CustomApiError("ovh.get-instances-error", {
originalError: error,
});
}
}
config
openstack: {
token_url: "https://auth.cloud.ovh.net/v3/auth/tokens",
token_payload: {
auth: {
identity: {
methods: ["password"],
password: {
user: {
name: "<name>",
domain: {
name: "Default",
},
password: "<password>",
},
},
},
scope: {
project: {
id: "project_id",
},
},
},
},
servers_url: "https://compute.de1.cloud.ovh.net/v2.1/<project_id>/servers/detail",
},
Metadata
Metadata
Assignees
Labels
No labels