mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
# Description For js, we had a previous [PR](https://github.com/Azure/azure-sdk-for-js/pull/25859) which was mainly to address changes caused by updating the DevCenter Data Plane API to 2023-04-01 version. Since the PR was not completed, I have picked the commits from there with the intention of reusing tests and samples. On top of that, I have regenerated the SDK from TypeSpec since this is the new type of generation desired going forward. This will be released as a beta SDK and later down the road we will be working on the stable SDK for this same API version. The recordings were updated to the [assets repo](https://github.com/Azure/azure-sdk-assets/tree/js/devcenter/developer-devcenter-rest_89c2b6dafe). The changes to add typespec support can be find at [feature/devcenter-tsp](https://github.com/Azure/azure-rest-api-specs/pull/26359). Note the PR hasn't been merged, so we will have a separate pr in the future to update the commit hash pointing to the new tsp location. # All SDK Contribution checklist: - [ ] **The pull request does not introduce [breaking changes]** - [x] **CHANGELOG is updated for new features, bug fixes or other significant changes.** - [x] **I have read the [contribution guidelines](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md).** ## General Guidelines and Best Practices - [x] Title of the pull request is clear and informative. - [x] There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md). ### [Testing Guidelines](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md##building-and-testing) - [x] Pull request includes test coverage for the included changes. ### Pipeline runs Dry runs on the release pipeline: https://dev.azure.com/azure-sdk/internal/_build?definitionId=5622&_a=summary ### List of tests (same as previous PR) DevBox - [x] get_pool - [x] list_pools - [x] get_dev_box - [x] get_remote_connection - [x] get_action - [x] list_actions - [x] skip_action - [x] delay_action - [x] delay_all_actions - [x] get_schedule - [x] list_schedules - [x] list_dev_boxes - [x] list_all_dev_boxes - [x] list_all_dev_boxes_by_user - [x] begin_create_dev_box - [x] begin_delete_dev_box - [x] begin_start_dev_box - [x] begin_stop_dev_box - [x] begin_restart_dev_box DevCenter - [x] get_project - [x] list_projects Environments - [x] begin_delete_environment - [x] begin_create_or_update_environment - [x] list_environment_types - [x] list_catalogs - [x] list_environments - [x] list_all_environments - [x] get_environment_definition - [x] list_environment_definitions - [x] list_environment_definitions_by_catalog - [x] get_catalog - [x] get_environment Also updated samples. --------- Co-authored-by: Sean Brennan <[email protected]> Co-authored-by: Oleg Demchenko <[email protected]>
96 lines
2.9 KiB
JavaScript
96 lines
2.9 KiB
JavaScript
const { DefaultAzureCredential } = require("@azure/identity");
|
|
const { isUnexpected, getLongRunningPoller } = require("@azure-rest/developer-devcenter");
|
|
const createClient = require("@azure-rest/developer-devcenter").default;
|
|
require("dotenv").config();
|
|
|
|
/**
|
|
* @summary Demonstrates creating, accessing, and deleting a Dev Box
|
|
*/
|
|
async function createDevBox() {
|
|
// Build client and fetch required parameters
|
|
const endpoint = process.env.DEVCENTER_ENDPOINT || "<devcenter name>";
|
|
const client = createClient(endpoint, new DefaultAzureCredential());
|
|
|
|
const projectList = await client.path("/projects").get();
|
|
if (isUnexpected(projectList)) {
|
|
throw new Error(projectList.body.error);
|
|
}
|
|
|
|
let project = projectList.body.value[0];
|
|
if (project === undefined || project.name === undefined) {
|
|
throw new Error("No projects found.");
|
|
}
|
|
const projectName = project.name;
|
|
|
|
const poolList = await client.path("/projects/{projectName}/pools", projectName).get();
|
|
if (isUnexpected(poolList)) {
|
|
throw new Error(poolList.body.error);
|
|
}
|
|
|
|
let pool = poolList.body.value[0];
|
|
if (pool === undefined || pool.name === undefined) {
|
|
throw new Error("No pools found.");
|
|
}
|
|
|
|
const devBoxCreateParameters = {
|
|
contentType: "application/json",
|
|
body: { poolName: pool.name },
|
|
};
|
|
|
|
// Provision a dev box
|
|
const devBoxCreateResponse = await client
|
|
.path(
|
|
"/projects/{projectName}/users/{userId}/devboxes/{devBoxName}",
|
|
projectName,
|
|
"me",
|
|
"TestDevBox"
|
|
)
|
|
.put(devBoxCreateParameters);
|
|
|
|
if (isUnexpected(devBoxCreateResponse)) {
|
|
throw new Error(devBoxCreateResponse.body.error.message);
|
|
}
|
|
|
|
const devBoxCreatePoller = await getLongRunningPoller(client, devBoxCreateResponse);
|
|
const devBoxCreateResult = await devBoxCreatePoller.pollUntilDone();
|
|
|
|
console.log(`Provisioned dev box with state ${devBoxCreateResult.body.provisioningState}.`);
|
|
|
|
// Get the connection URL to access the machine
|
|
const remoteConnectionResult = await client
|
|
.path(
|
|
"/projects/{projectName}/users/{userId}/devboxes/{devBoxName}/remoteConnection",
|
|
projectName,
|
|
"me",
|
|
"TestDevBox"
|
|
)
|
|
.get();
|
|
|
|
if (isUnexpected(remoteConnectionResult)) {
|
|
throw new Error(remoteConnectionResult.body.error.message);
|
|
}
|
|
|
|
console.log(`Connect using remote connection URL ${remoteConnectionResult.body.webUrl}.`);
|
|
|
|
// Tear down the machine when finished
|
|
const devBoxDeleteResponse = await client
|
|
.path(
|
|
"/projects/{projectName}/users/{userId}/devboxes/{devBoxName}",
|
|
projectName,
|
|
"me",
|
|
"TestDevBox"
|
|
)
|
|
.delete();
|
|
|
|
if (isUnexpected(devBoxDeleteResponse)) {
|
|
throw new Error(devBoxDeleteResponse.body.error.message);
|
|
}
|
|
|
|
const devBoxDeletePoller = await getLongRunningPoller(client, devBoxDeleteResponse);
|
|
await devBoxDeletePoller.pollUntilDone();
|
|
|
|
console.log(`Cleaned up dev box successfully.`);
|
|
}
|
|
|
|
createDevBox();
|