Skip to content

Commit 5fe2011

Browse files
committed
Add Dedicated Groups resource
Signed-off-by: Maxime Dufour <[email protected]>
1 parent 925c8e7 commit 5fe2011

File tree

8 files changed

+131
-12
lines changed

8 files changed

+131
-12
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390
"eslint": "^8.14.0",
391391
"glob": "^8.0.1",
392392
"mocha": "^9.2.2",
393-
"outscale-api": "^0.11.0",
393+
"outscale-api": "^0.12.0",
394394
"ovsx": "^0.8.0",
395395
"sinon": "^14.0.1",
396396
"ts-mock-imports": "^1.3.8",
@@ -403,7 +403,7 @@
403403
"@types/cytoscape": "^3.19.9",
404404
"@vscode/l10n": "^0.0.13",
405405
"cross-fetch": "^3.1.5",
406-
"outscale-api": "^0.11.0",
406+
"outscale-api": "^0.12.0",
407407
"rxjs": "^7.5.7",
408408
"true-myth": "^6.2.0"
409409
}

src/cloud/dedicatedgroup.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
import * as osc from "outscale-api";
3+
import { FiltersDedicatedGroup } from "outscale-api";
4+
import { getConfig, handleRejection } from '../cloud/cloud';
5+
import { Profile } from "../flat/node";
6+
7+
8+
// Retrieve all items of the resource DedicatedGroup
9+
export function getDedicatedGroups(profile: Profile, filters?: FiltersDedicatedGroup): Promise<Array<osc.DedicatedGroup> | string> {
10+
const config = getConfig(profile);
11+
const readParameters: osc.ReadDedicatedGroupsOperationRequest = {
12+
readDedicatedGroupsRequest: {
13+
filters: filters
14+
}
15+
};
16+
17+
const api = new osc.DedicatedGroupApi(config);
18+
return api.readDedicatedGroups(readParameters)
19+
.then((res: osc.ReadDedicatedGroupsResponse) => {
20+
if (res.dedicatedGroups === undefined || res.dedicatedGroups.length === 0) {
21+
return [];
22+
}
23+
return res.dedicatedGroups;
24+
}, (err_: any) => {
25+
return handleRejection(err_);
26+
});
27+
}
28+
29+
// Retrieve a specific item of the resource DedicatedGroup
30+
export function getDedicatedGroup(profile: Profile, resourceId: string): Promise<osc.DedicatedGroup | undefined | string> {
31+
const config = getConfig(profile);
32+
const readParameters: osc.ReadDedicatedGroupsOperationRequest = {
33+
readDedicatedGroupsRequest: {
34+
filters: {
35+
dedicatedGroupIds: [resourceId]
36+
}
37+
}
38+
};
39+
40+
const api = new osc.DedicatedGroupApi(config);
41+
return api.readDedicatedGroups(readParameters)
42+
.then((res: osc.ReadDedicatedGroupsResponse) => {
43+
if (res.dedicatedGroups === undefined || res.dedicatedGroups.length === 0) {
44+
return undefined;
45+
}
46+
return res.dedicatedGroups[0];
47+
}, (err_: any) => {
48+
return handleRejection(err_);
49+
});
50+
}
51+
52+
// Delete a specific item the resource DedicatedGroup
53+
export function deleteDedicatedGroup(profile: Profile, resourceId: string): Promise<string | undefined> {
54+
const config = getConfig(profile);
55+
const deleteParameters: osc.DeleteDedicatedGroupOperationRequest = {
56+
deleteDedicatedGroupRequest: {
57+
dedicatedGroupId: resourceId
58+
}
59+
};
60+
61+
const api = new osc.DedicatedGroupApi(config);
62+
return api.deleteDedicatedGroup(deleteParameters)
63+
.then(() => {
64+
return undefined;
65+
}, (err_: any) => {
66+
return handleRejection(err_);
67+
});
68+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as vscode from 'vscode';
2+
import { ExplorerNode, ExplorerFolderNode, Profile, resourceNodeCompare } from '../../node';
3+
import { FiltersFolderNode } from '../node.filterfolder';
4+
import { ResourceNode } from '../../resources/node.resources';
5+
import { FiltersDedicatedGroup, FiltersDedicatedGroupFromJSON } from 'outscale-api';
6+
import { deleteDedicatedGroup, getDedicatedGroup, getDedicatedGroups } from '../../../cloud/dedicatedgroup';
7+
8+
export const DEDICATEDGROUP_FOLDER_NAME = "Dedicated Groups";
9+
export class DedicatedGroupsFolderNode extends FiltersFolderNode<FiltersDedicatedGroup> implements ExplorerFolderNode {
10+
constructor(readonly profile: Profile) {
11+
super(profile, DEDICATEDGROUP_FOLDER_NAME);
12+
}
13+
14+
getChildren(): Thenable<ExplorerNode[]> {
15+
this.updateFilters();
16+
return getDedicatedGroups(this.profile, this.filters).then(results => {
17+
if (typeof results === "string") {
18+
vscode.window.showErrorMessage(vscode.l10n.t(`Error while reading {0}: {1}`, this.folderName, results));
19+
return Promise.resolve([]);
20+
}
21+
const resources = [];
22+
for (const item of results) {
23+
24+
if (typeof item.dedicatedGroupId === 'undefined') {
25+
26+
continue;
27+
}
28+
29+
if (typeof item.name === 'undefined') {
30+
31+
continue;
32+
}
33+
34+
resources.push(new ResourceNode(this.profile, item.name, item.dedicatedGroupId, "DedicatedGroup", deleteDedicatedGroup, getDedicatedGroup));
35+
36+
}
37+
return Promise.resolve(resources.sort(resourceNodeCompare));
38+
});
39+
40+
}
41+
42+
filtersFromJson(json: string): FiltersDedicatedGroup {
43+
return FiltersDedicatedGroupFromJSON(json);
44+
}
45+
}

src/flat/node.profile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { VpnConnectionsFolderNode, VPNCONNECTIONS_FOLDER_NAME } from './folders/
3030
import { DISABLE_FOLDER_PARAMETER, getConfigurationParameter } from '../configuration/utils';
3131
import { VMGROUPS_FOLDER_NAME, VmGroupsFolderNode } from './folders/simple/node.folder.vmgroup';
3232
import { VMTEMPLATES_FOLDER_NAME, VmTemplatesFolderNode } from './folders/simple/node.folder.vmtemplate';
33+
import { DEDICATEDGROUP_FOLDER_NAME, DedicatedGroupsFolderNode } from './folders/simple/node.folder.dedicatedgroup';
3334

3435

3536
export class ProfileNode implements ExplorerProfileNode {
@@ -50,6 +51,7 @@ export class ProfileNode implements ExplorerProfileNode {
5051
[APIACCESSRULES_FOLDER_NAME, new ApiAccessRulesFolderNode(this.profile)],
5152
[CA_FOLDER_NAME, new CasFolderNode(this.profile)],
5253
[CLIENTGATEWAYS_FOLDER_NAME, new ClientGatewaysFolderNode(this.profile)],
54+
[DEDICATEDGROUP_FOLDER_NAME, new DedicatedGroupsFolderNode(this.profile)],
5355
[DHCPOPTIONS_FOLDER_NAME, new DhcpOptionsFolderNode(this.profile)],
5456
[DIRECTLINKS_FOLDER_NAME, new DirectLinksFolderNode(this.profile)],
5557
[DIRECTLINKINTERFACES_FOLDER_NAME, new DirectLinkInterfacesFolderNode(this.profile)],

src/flat/node.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export type ResourceNodeType =
5757
"snapshots" |
5858
"routetables" |
5959
"VmTemplate" |
60-
"VmGroup";
60+
"VmGroup" |
61+
"DedicatedGroup";
6162
export class NodeImpl {
6263
}
6364

src/ui-test/treeview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const resourceTypes = [
1616
"Api Access Rules",
1717
"Cas",
1818
"Client Gateways",
19+
"Dedicated Groups",
1920
"Dhcp Options",
2021
"DirectLinks",
2122
"DirectLink Interfaces",

src/virtual_filesystem/oscvirtualfs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22

3-
import { AccessKeyToJSON, AccountToJSON, ApiAccessRuleToJSON, CaToJSON, ClientGatewayToJSON, DhcpOptionsSetToJSON, DirectLinkInterfaceToJSON, DirectLinkToJSON, FlexibleGpuToJSON, ImageToJSON, InternetServiceToJSON, KeypairToJSON, LoadBalancerToJSON, NatServiceToJSON, NetAccessPointToJSON, NetPeeringToJSON, NetToJSON, NicToJSON, PublicIpToJSON, RouteTableToJSON, SecurityGroupToJSON, SnapshotToJSON, SubnetToJSON, VirtualGatewayToJSON, VmGroupFromJSON, VmGroupToJSON, VmTemplateToJSON, VmToJSON, VolumeToJSON, VpnConnectionToJSON } from "outscale-api";
3+
import { AccessKeyToJSON, AccountToJSON, ApiAccessRuleToJSON, CaToJSON, ClientGatewayToJSON, DedicatedGroupToJSON, DhcpOptionsSetToJSON, DirectLinkInterfaceToJSON, DirectLinkToJSON, FlexibleGpuToJSON, ImageToJSON, InternetServiceToJSON, KeypairToJSON, LoadBalancerToJSON, NatServiceToJSON, NetAccessPointToJSON, NetPeeringToJSON, NetToJSON, NicToJSON, PublicIpToJSON, RouteTableToJSON, SecurityGroupToJSON, SnapshotToJSON, SubnetToJSON, VirtualGatewayToJSON, VmGroupToJSON, VmTemplateToJSON, VmToJSON, VolumeToJSON, VpnConnectionToJSON } from "outscale-api";
44
import { getExternalIP } from "../cloud/publicips";
55
import { getKeypair } from "../cloud/keypairs";
66
import { getLoadBalancer } from "../cloud/loadbalancers";
@@ -32,6 +32,7 @@ import { getVirtualGateway } from '../cloud/virtualgateways';
3232
import { getVpnConnection } from '../cloud/vpnconnections';
3333
import { getVmGroup } from '../cloud/vmgroup';
3434
import { getVmTemplate } from '../cloud/vmtemplate';
35+
import { getDedicatedGroup } from '../cloud/dedicatedgroup';
3536

3637

3738
class ResourceEncoding {
@@ -71,6 +72,7 @@ const resourceMap = new Map([
7172
["VpnConnection", new ResourceEncoding(getVpnConnection, VpnConnectionToJSON)],
7273
["VmGroup", new ResourceEncoding(getVmGroup, VmGroupToJSON)],
7374
["VmTemplate", new ResourceEncoding(getVmTemplate, VmTemplateToJSON)],
75+
["DedicatedGroup", new ResourceEncoding(getDedicatedGroup, DedicatedGroupToJSON)],
7476
]);
7577

7678
export class OscVirtualContentProvider implements vscode.TextDocumentContentProvider {

0 commit comments

Comments
 (0)