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
|
// 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,12 +113,12 @@ 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) {
|
||||||
process.exit();
|
console.log('\n###### Exit ######')
|
||||||
|
process.exit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -136,47 +158,57 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _validateEnvironmentVariables() {
|
function _validateEnvironmentVariables() {
|
||||||
var envs = [];
|
var envs = [];
|
||||||
if (!process.env['CLIENT_ID']) envs.push('CLIENT_ID');
|
if (!process.env['CLIENT_ID']) envs.push('CLIENT_ID');
|
||||||
if (!process.env['DOMAIN']) envs.push('DOMAIN');
|
if (!process.env['DOMAIN']) envs.push('DOMAIN');
|
||||||
if (!process.env['APPLICATION_SECRET']) envs.push('APPLICATION_SECRET');
|
if (!process.env['APPLICATION_SECRET']) envs.push('APPLICATION_SECRET');
|
||||||
if (envs.length > 0) {
|
if (envs.length > 0) {
|
||||||
throw new Error(util.format('please set/export the following environment variables: %s', envs.toString()));
|
throw new Error(util.format('please set/export the following environment variables: %s', envs.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _generateRandomId(prefix, exsitIds) {
|
function _generateRandomId(prefix, exsitIds) {
|
||||||
var newNumber;
|
var newNumber;
|
||||||
while (true) {
|
while (true) {
|
||||||
newNumber = prefix + Math.floor(Math.random() * 10000);
|
newNumber = prefix + Math.floor(Math.random() * 10000);
|
||||||
if (!exsitIds || !(newNumber in exsitIds)) {
|
if (!exsitIds || !(newNumber in exsitIds)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return newNumber;
|
||||||
return newNumber;
|
|
||||||
}
|
}
|
Загрузка…
Ссылка в новой задаче