def create_app_service_plan(resource_group_name, name, is_linux, sku='B1', number_of_workers=None, location=None): client = web_client_factory() sku = _normalize_sku(sku) if location is None: location = _get_location_from_resource_group(resource_group_name) #the api is odd on parameter naming, have to live with it for now sku_def = SkuDescription(tier=_get_sku_name(sku), name=sku, capacity=number_of_workers) plan_def = ServerFarmWithRichSku(location, server_farm_with_rich_sku_name=name, sku=sku_def, reserved=(is_linux or None)) poller = client.server_farms.create_or_update_server_farm(resource_group_name, name, plan_def) return AppServiceLongRunningOperation(creating_plan=True)(poller)
def create_app_service_plan(resource_group, name, tier=None, number_of_workers=None, location=None): client = web_client_factory() if location is None: location = _get_location_from_resource_group(resource_group) sku_name = _get_sku_name(tier) #the api is odd on parameter naming, have to live with it for now sku = SkuDescription(name=tier, tier=sku_name, capacity=number_of_workers) plan_def = ServerFarmWithRichSku(location, server_farm_with_rich_sku_name=name, sku=sku) #TODO: handle bad error on creating too many F1 plans: # Operation failed with status: 'Conflict'. Details: 409 Client Error: Conflict for url: return client.server_farms.create_or_update_server_farm( resource_group, name, plan_def)
def update_app_service_plan(resource_group, name, tier=None, number_of_workers=None, admin_site_name=None): client = web_client_factory() plan = client.server_farms.get_server_farm(resource_group, name) sku = plan.sku if tier is not None: sku_name = _get_sku_name(tier) sku.tier = sku_name sku.name = tier if number_of_workers is not None: sku.capacity = number_of_workers plan_def = ServerFarmWithRichSku(plan.location, server_farm_with_rich_sku_name=name, sku=sku, admin_site_name=admin_site_name) return client.server_farms.create_or_update_server_farm( resource_group, name, plan_def)
def run_example(): """Web Site management example.""" # # Create the Resource Manager Client with an Application (service principal) token provider # subscription_id = os.environ.get( 'AZURE_SUBSCRIPTION_ID', '11111111-1111-1111-1111-111111111111') # your Azure Subscription Id credentials = ServicePrincipalCredentials( client_id=os.environ['AZURE_CLIENT_ID'], secret=os.environ['AZURE_CLIENT_SECRET'], tenant=os.environ['AZURE_TENANT_ID'] ) resource_client = ResourceManagementClient(credentials, subscription_id) web_client = WebSiteManagementClient(credentials, subscription_id) # Create Resource group print('Create Resource Group') resource_group_params = {'location':'westus'} print_item(resource_client.resource_groups.create_or_update(GROUP_NAME, resource_group_params)) # # Create a Server Farm for your WebApp # print('Create a Server Farm for your WebApp') server_farm_async_operation = web_client.server_farms.create_or_update_server_farm( GROUP_NAME, SERVER_FARM_NAME, ServerFarmWithRichSku( location=WEST_US, sku=SkuDescription( name='S1', capacity=1, tier='Standard' ) ) ) server_farm = server_farm_async_operation.result() print_item(server_farm) # # Create a Site to be hosted in the Server Farm # print('Create a Site to be hosted in the Server Farm') site_async_operation = web_client.sites.create_or_update_site( GROUP_NAME, SITE_NAME, Site( location=WEST_US, server_farm_id=server_farm.id ) ) site = site_async_operation.result() print_item(site) # # List Sites by Resource Group # print('List Sites by Resource Group') for site in web_client.sites.get_sites(GROUP_NAME).value: print_item(site) # # Get a single Site # print('Get a single Site') site = web_client.sites.get_site(GROUP_NAME, SITE_NAME) print_item(site) print("Your site and server farm have been created. " \ "You can now go and visit at http://{}/".format(site.default_host_name)) input("Press enter to delete the site and server farm.") # # Delete a Site # print('Deleting the Site') web_client.sites.delete_site(GROUP_NAME, SITE_NAME) # # Delete the Resource Group # print('Deleting the resource group') delete_async_operation = resource_client.resource_groups.delete(GROUP_NAME) delete_async_operation.wait()