Added list and update in webapp sample

This commit is contained in:
Hao Chen 2016-05-19 18:34:35 -07:00
Родитель fa5e117030
Коммит 8f3efa6674
1 изменённых файлов: 62 добавлений и 30 удалений

Просмотреть файл

@ -38,9 +38,11 @@ var webSiteClient = new WebSiteManagement(credentials, subscriptionId);
// 1. create a resource group // 1. create a resource group
// 2. create a hosting plan // 2. create a hosting plan
// 3. create a website // 3. create a website
// 4. get website detials info // 4. list websites for given subscription
// 5. delete website // 5. get details for a given website
// 6. delete resource group // 6. update site config(number of workers and phpversion) for a website
// 7. delete a website
// 8. delete the resource group
async.series([ async.series([
function(callback) { function(callback) {
createResourceGroup(function(err, result, request, response) { createResourceGroup(function(err, result, request, response) {
@ -66,6 +68,16 @@ async.series([
callback(null, result); 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) { function(callback) {
getWebSite(function(err, result, request, response) { getWebSite(function(err, result, request, response) {
if (err) { if (err) {
@ -76,6 +88,16 @@ async.series([
callback(null, result); 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) { function(callback) {
deleteWebSite(function(err, result, request, response) { deleteWebSite(function(err, result, request, response) {
if (err) { if (err) {
@ -91,11 +113,11 @@ async.series([
console.log(util.format('\n??????Error occurred in one of the operations.\n%s', console.log(util.format('\n??????Error occurred in one of the operations.\n%s',
util.inspect(err, { depth: null }))); util.inspect(err, { depth: null })));
} else { } else {
console.log(util.format('\n######All the operations have completed successfully. ' + 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 })));
} }
// clean up // clean up
deleteResourceGroup(function(err, result, request, response) { deleteResourceGroup(function(err, result, request, response) {
console.log('\n###### Exit ######')
process.exit(); process.exit();
}); });
} }
@ -138,23 +160,33 @@ function createHostingPlan(callback) {
function createWebSite(callback) { function createWebSite(callback) {
var parameters = { var parameters = {
location: location, location: location,
serverFarmId: hostingPlanName, serverFarmId: hostingPlanName
webSite: {
properties: {
serverFarm: hostingPlanName
}
}
}; };
var siteEnvelope = { "location": location };
console.log('\nCreating web site: ' + webSiteName); console.log('\nCreating web site: ' + webSiteName);
return webSiteClient.sites.createOrUpdateSite(resourceGroupName, webSiteName, parameters, null, callback); return webSiteClient.sites.createOrUpdateSite(resourceGroupName, webSiteName, parameters, null, callback);
} }
function getWebSite(callback) { function getWebSite(callback) {
console.log('\nGeting info of : ' + webSiteName); console.log('\nGetting info of : ' + webSiteName);
return webSiteClient.sites.getSite(resourceGroupName, webSiteName, callback); 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) { function deleteWebSite(callback) {
console.log('\nDeleting web site : ' + webSiteName); console.log('\nDeleting web site : ' + webSiteName);
return webSiteClient.sites.deleteSite(resourceGroupName, webSiteName, callback); return webSiteClient.sites.deleteSite(resourceGroupName, webSiteName, callback);