Ver código fonte

Add VM inventory CSV export data layer

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 2 meses atrás
pai
commit
ad05000834
3 arquivos alterados com 20 adições e 0 exclusões
  1. 1 0
      src/constants.ts
  2. 8 0
      src/sources/EndpointSource.ts
  3. 11 0
      src/stores/EndpointStore.ts

+ 1 - 0
src/constants.ts

@@ -49,6 +49,7 @@ export const providerTypes = {
   TARGET_UPDATE: 262144,
   SOURCE_MINION_POOL: 524288,
   DESTINATION_MINION_POOL: 1048576,
+  INVENTORY_EXPORT: 2097152,
 };
 
 export const loginButtons = [

+ 8 - 0
src/sources/EndpointSource.ts

@@ -307,6 +307,14 @@ class EndpointSource {
     return SchemaParser.parseConnectionResponse(response.data.endpoint);
   }
 
+  async exportInventoryCsv(endpointId: string): Promise<string> {
+    const response = await Api.send({
+      url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/endpoints/${endpointId}/inventory`,
+      responseType: "text",
+    });
+    return response.data as string;
+  }
+
   async loadStorage(
     endpointId: string,
     data: any,

+ 11 - 0
src/stores/EndpointStore.ts

@@ -198,6 +198,17 @@ class EndpointStore {
     }
   }
 
+  @action async exportInventoryCsv(endpoint: Endpoint): Promise<void> {
+    const csvContent = await EndpointSource.exportInventoryCsv(endpoint.id);
+    const now = new Date();
+    const pad = (n: number) => String(n).padStart(2, "0");
+    const d =
+      `${now.getFullYear()}-${pad(now.getMonth() + 1)}` +
+      `-${pad(now.getDate())}_${pad(now.getHours())}` +
+      `:${pad(now.getMinutes())}`;
+    DomUtils.download(csvContent, `vm_inventory_${endpoint.name}_${d}.csv`);
+  }
+
   @action async exportToJson(endpoint: Endpoint): Promise<void> {
     const connectionInfo = await EndpointSource.getConnectionInfo(endpoint);
     const newEndpoint = JSON.parse(JSON.stringify(endpoint));