Added list and update in webapp sample
This commit is contained in:
Родитель
fa5e117030
Коммит
8f3efa6674
|
@ -38,9 +38,11 @@ var webSiteClient = new WebSiteManagement(credentials, subscriptionId);
|
|||
// 1. create a resource group
|
||||
// 2. create a hosting plan
|
||||
// 3. create a website
|
||||
// 4. get website detials info
|
||||
// 5. delete website
|
||||
// 6. delete resource group
|
||||
// 4. list websites for given subscription
|
||||
// 5. get details for a given website
|
||||
// 6. update site config(number of workers and phpversion) for a website
|
||||
// 7. delete a website
|
||||
// 8. delete the resource group
|
||||
async.series([
|
||||
function(callback) {
|
||||
createResourceGroup(function(err, result, request, response) {
|
||||
|
@ -66,6 +68,16 @@ async.series([
|
|||
callback(null, result);
|
||||
});
|
||||
},
|
||||
function(callback) {
|
||||
listWebsites(function(err, result, request, response) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
console.log(util.format('\nWebsites in subscription %s : \n%s',
|
||||
subscriptionId, util.inspect(result, { depth: null })));
|
||||
callback(null, result);
|
||||
});
|
||||
},
|
||||
function(callback) {
|
||||
getWebSite(function(err, result, request, response) {
|
||||
if (err) {
|
||||
|
@ -76,6 +88,16 @@ async.series([
|
|||
callback(null, result);
|
||||
});
|
||||
},
|
||||
function(callback) {
|
||||
updateWebisteConfig(function(err, result, request, response) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
console.log(util.format('\nWeb site details: \n%s',
|
||||
util.inspect(result, { depth: null })));
|
||||
callback(null, result);
|
||||
});
|
||||
},
|
||||
function(callback) {
|
||||
deleteWebSite(function(err, result, request, response) {
|
||||
if (err) {
|
||||
|
@ -91,12 +113,12 @@ async.series([
|
|||
console.log(util.format('\n??????Error occurred in one of the operations.\n%s',
|
||||
util.inspect(err, { depth: null })));
|
||||
} else {
|
||||
console.log(util.format('\n######All the operations have completed successfully. ' +
|
||||
'The final set of results are as follows:\n%s', util.inspect(results, { depth: null })));
|
||||
console.log(util.format('\n######All the operations have completed successfully. ' ));
|
||||
}
|
||||
// clean up
|
||||
deleteResourceGroup(function(err, result, request, response) {
|
||||
process.exit();
|
||||
console.log('\n###### Exit ######')
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -136,47 +158,57 @@ function createHostingPlan(callback) {
|
|||
}
|
||||
|
||||
function createWebSite(callback) {
|
||||
var parameters = {
|
||||
location: location,
|
||||
serverFarmId: hostingPlanName,
|
||||
webSite: {
|
||||
properties: {
|
||||
serverFarm: hostingPlanName
|
||||
}
|
||||
}
|
||||
var parameters = {
|
||||
location: location,
|
||||
serverFarmId: hostingPlanName
|
||||
};
|
||||
var siteEnvelope = { "location": location };
|
||||
console.log('\nCreating web site: ' + webSiteName);
|
||||
return webSiteClient.sites.createOrUpdateSite(resourceGroupName, webSiteName, parameters, null, callback);
|
||||
}
|
||||
|
||||
function getWebSite(callback) {
|
||||
console.log('\nGeting info of : ' + webSiteName);
|
||||
console.log('\nGetting info of : ' + webSiteName);
|
||||
return webSiteClient.sites.getSite(resourceGroupName, webSiteName, callback);
|
||||
}
|
||||
|
||||
function listWebsites(callback) {
|
||||
console.log('\nListing websits in subscription : ' + subscriptionId);
|
||||
return webSiteClient.sites.getSites(resourceGroupName, null, callback);
|
||||
}
|
||||
|
||||
function updateWebisteConfig(callback) {
|
||||
var siteConfig = {
|
||||
location: location,
|
||||
serverFarmId: hostingPlanName,
|
||||
numberOfWorkers: 2,
|
||||
phpVersion: '5.5'
|
||||
};
|
||||
console.log('\nUpdating config for website : ' + webSiteName);
|
||||
return webSiteClient.sites.createOrUpdateSiteConfig(resourceGroupName, webSiteName, siteConfig, null, callback);
|
||||
}
|
||||
|
||||
function deleteWebSite(callback) {
|
||||
console.log('\nDeleting web site : ' + webSiteName);
|
||||
return webSiteClient.sites.deleteSite(resourceGroupName, webSiteName, callback);
|
||||
}
|
||||
|
||||
function _validateEnvironmentVariables() {
|
||||
var envs = [];
|
||||
if (!process.env['CLIENT_ID']) envs.push('CLIENT_ID');
|
||||
if (!process.env['DOMAIN']) envs.push('DOMAIN');
|
||||
if (!process.env['APPLICATION_SECRET']) envs.push('APPLICATION_SECRET');
|
||||
if (envs.length > 0) {
|
||||
throw new Error(util.format('please set/export the following environment variables: %s', envs.toString()));
|
||||
}
|
||||
var envs = [];
|
||||
if (!process.env['CLIENT_ID']) envs.push('CLIENT_ID');
|
||||
if (!process.env['DOMAIN']) envs.push('DOMAIN');
|
||||
if (!process.env['APPLICATION_SECRET']) envs.push('APPLICATION_SECRET');
|
||||
if (envs.length > 0) {
|
||||
throw new Error(util.format('please set/export the following environment variables: %s', envs.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
function _generateRandomId(prefix, exsitIds) {
|
||||
var newNumber;
|
||||
while (true) {
|
||||
newNumber = prefix + Math.floor(Math.random() * 10000);
|
||||
if (!exsitIds || !(newNumber in exsitIds)) {
|
||||
break;
|
||||
var newNumber;
|
||||
while (true) {
|
||||
newNumber = prefix + Math.floor(Math.random() * 10000);
|
||||
if (!exsitIds || !(newNumber in exsitIds)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newNumber;
|
||||
return newNumber;
|
||||
}
|
Загрузка…
Ссылка в новой задаче