Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dedicated Groups resource #99

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
"eslint": "^8.14.0",
"glob": "^8.0.1",
"mocha": "^9.2.2",
"outscale-api": "^0.11.0",
"outscale-api": "^0.12.0",
"ovsx": "^0.8.0",
"sinon": "^14.0.1",
"ts-mock-imports": "^1.3.8",
Expand All @@ -403,7 +403,7 @@
"@types/cytoscape": "^3.19.9",
"@vscode/l10n": "^0.0.13",
"cross-fetch": "^3.1.5",
"outscale-api": "^0.11.0",
"outscale-api": "^0.12.0",
"rxjs": "^7.5.7",
"true-myth": "^6.2.0"
}
Expand Down
68 changes: 68 additions & 0 deletions src/cloud/dedicatedgroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

import * as osc from "outscale-api";
import { FiltersDedicatedGroup } from "outscale-api";
import { getConfig, handleRejection } from '../cloud/cloud';
import { Profile } from "../flat/node";


// Retrieve all items of the resource DedicatedGroup
export function getDedicatedGroups(profile: Profile, filters?: FiltersDedicatedGroup): Promise<Array<osc.DedicatedGroup> | string> {
const config = getConfig(profile);
const readParameters: osc.ReadDedicatedGroupsOperationRequest = {
readDedicatedGroupsRequest: {
filters: filters
}
};

const api = new osc.DedicatedGroupApi(config);
return api.readDedicatedGroups(readParameters)
.then((res: osc.ReadDedicatedGroupsResponse) => {
if (res.dedicatedGroups === undefined || res.dedicatedGroups.length === 0) {
return [];
}
return res.dedicatedGroups;
}, (err_: any) => {
return handleRejection(err_);
});
}

// Retrieve a specific item of the resource DedicatedGroup
export function getDedicatedGroup(profile: Profile, resourceId: string): Promise<osc.DedicatedGroup | undefined | string> {
const config = getConfig(profile);
const readParameters: osc.ReadDedicatedGroupsOperationRequest = {
readDedicatedGroupsRequest: {
filters: {
dedicatedGroupIds: [resourceId]
}
}
};

const api = new osc.DedicatedGroupApi(config);
return api.readDedicatedGroups(readParameters)
.then((res: osc.ReadDedicatedGroupsResponse) => {
if (res.dedicatedGroups === undefined || res.dedicatedGroups.length === 0) {
return undefined;
}
return res.dedicatedGroups[0];
}, (err_: any) => {
return handleRejection(err_);
});
}

// Delete a specific item the resource DedicatedGroup
export function deleteDedicatedGroup(profile: Profile, resourceId: string): Promise<string | undefined> {
const config = getConfig(profile);
const deleteParameters: osc.DeleteDedicatedGroupOperationRequest = {
deleteDedicatedGroupRequest: {
dedicatedGroupId: resourceId
}
};

const api = new osc.DedicatedGroupApi(config);
return api.deleteDedicatedGroup(deleteParameters)
.then(() => {
return undefined;
}, (err_: any) => {
return handleRejection(err_);
});
}
45 changes: 45 additions & 0 deletions src/flat/folders/simple/node.folder.dedicatedgroup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as vscode from 'vscode';
import { ExplorerNode, ExplorerFolderNode, Profile, resourceNodeCompare } from '../../node';
import { FiltersFolderNode } from '../node.filterfolder';
import { ResourceNode } from '../../resources/node.resources';
import { FiltersDedicatedGroup, FiltersDedicatedGroupFromJSON } from 'outscale-api';
import { deleteDedicatedGroup, getDedicatedGroup, getDedicatedGroups } from '../../../cloud/dedicatedgroup';

export const DEDICATEDGROUP_FOLDER_NAME = "Dedicated Groups";
export class DedicatedGroupsFolderNode extends FiltersFolderNode<FiltersDedicatedGroup> implements ExplorerFolderNode {
constructor(readonly profile: Profile) {
super(profile, DEDICATEDGROUP_FOLDER_NAME);
}

getChildren(): Thenable<ExplorerNode[]> {
this.updateFilters();
return getDedicatedGroups(this.profile, this.filters).then(results => {
if (typeof results === "string") {
vscode.window.showErrorMessage(vscode.l10n.t(`Error while reading {0}: {1}`, this.folderName, results));
return Promise.resolve([]);
}
const resources = [];
for (const item of results) {

if (typeof item.dedicatedGroupId === 'undefined') {

continue;
}

if (typeof item.name === 'undefined') {

continue;
}

resources.push(new ResourceNode(this.profile, item.name, item.dedicatedGroupId, "DedicatedGroup", deleteDedicatedGroup, getDedicatedGroup));

}
return Promise.resolve(resources.sort(resourceNodeCompare));
});

}

filtersFromJson(json: string): FiltersDedicatedGroup {
return FiltersDedicatedGroupFromJSON(json);
}
}
2 changes: 2 additions & 0 deletions src/flat/node.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { VpnConnectionsFolderNode, VPNCONNECTIONS_FOLDER_NAME } from './folders/
import { DISABLE_FOLDER_PARAMETER, getConfigurationParameter } from '../configuration/utils';
import { VMGROUPS_FOLDER_NAME, VmGroupsFolderNode } from './folders/simple/node.folder.vmgroup';
import { VMTEMPLATES_FOLDER_NAME, VmTemplatesFolderNode } from './folders/simple/node.folder.vmtemplate';
import { DEDICATEDGROUP_FOLDER_NAME, DedicatedGroupsFolderNode } from './folders/simple/node.folder.dedicatedgroup';


export class ProfileNode implements ExplorerProfileNode {
Expand All @@ -50,6 +51,7 @@ export class ProfileNode implements ExplorerProfileNode {
[APIACCESSRULES_FOLDER_NAME, new ApiAccessRulesFolderNode(this.profile)],
[CA_FOLDER_NAME, new CasFolderNode(this.profile)],
[CLIENTGATEWAYS_FOLDER_NAME, new ClientGatewaysFolderNode(this.profile)],
[DEDICATEDGROUP_FOLDER_NAME, new DedicatedGroupsFolderNode(this.profile)],
[DHCPOPTIONS_FOLDER_NAME, new DhcpOptionsFolderNode(this.profile)],
[DIRECTLINKS_FOLDER_NAME, new DirectLinksFolderNode(this.profile)],
[DIRECTLINKINTERFACES_FOLDER_NAME, new DirectLinkInterfacesFolderNode(this.profile)],
Expand Down
3 changes: 2 additions & 1 deletion src/flat/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export type ResourceNodeType =
"snapshots" |
"routetables" |
"VmTemplate" |
"VmGroup";
"VmGroup" |
"DedicatedGroup";
export class NodeImpl {
}

Expand Down
1 change: 1 addition & 0 deletions src/ui-test/treeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const resourceTypes = [
"Api Access Rules",
"Cas",
"Client Gateways",
"Dedicated Groups",
"Dhcp Options",
"DirectLinks",
"DirectLink Interfaces",
Expand Down
4 changes: 3 additions & 1 deletion src/virtual_filesystem/oscvirtualfs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';

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";
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";
import { getExternalIP } from "../cloud/publicips";
import { getKeypair } from "../cloud/keypairs";
import { getLoadBalancer } from "../cloud/loadbalancers";
Expand Down Expand Up @@ -32,6 +32,7 @@ import { getVirtualGateway } from '../cloud/virtualgateways';
import { getVpnConnection } from '../cloud/vpnconnections';
import { getVmGroup } from '../cloud/vmgroup';
import { getVmTemplate } from '../cloud/vmtemplate';
import { getDedicatedGroup } from '../cloud/dedicatedgroup';


class ResourceEncoding {
Expand Down Expand Up @@ -71,6 +72,7 @@ const resourceMap = new Map([
["VpnConnection", new ResourceEncoding(getVpnConnection, VpnConnectionToJSON)],
["VmGroup", new ResourceEncoding(getVmGroup, VmGroupToJSON)],
["VmTemplate", new ResourceEncoding(getVmTemplate, VmTemplateToJSON)],
["DedicatedGroup", new ResourceEncoding(getDedicatedGroup, DedicatedGroupToJSON)],
]);

export class OscVirtualContentProvider implements vscode.TextDocumentContentProvider {
Expand Down
Loading