forked from bmb/pyazure
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_usage.py
81 lines (62 loc) · 2.74 KB
/
sample_usage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# encoding: utf-8
import sys, os
sys.path.append('/path/to/pyazure')
from pyazure import pyazure
ACCOUNT_NAME = '<Azure_storage_account_name>'
ACCOUNT_KEY = '<Azure_storage_account_key>'
pa = pyazure.PyAzure(ACCOUNT_NAME, ACCOUNT_KEY)
tables = pa.tables.list_tables()
for t in tables:
print(e.name)
MANAGEMENT_CERT = \
'<path to Azure management certificate (PEM with embedded key)>'
SUBSCRIPTION_ID = '<Azure subscription ID>'
print 'Initialising Azure management interface'
pa = pyazure.PyAzure(management_cert_path=MANAGEMENT_CERT,
subscription_id=SUBSCRIPTION_ID)
print 'Listing existing hosted services...'
for svc in pa.wasm.list_services():
print svc
print 'Listing existing storage accounts...'
for store in pa.wasm.list_storage_accounts():
print store
print "Switching pyazure to 'pyazuretest' storage account..."
pa.set_storage_account('pyazuretest', create=True)
print 'Uploading azure cspkg...'
cspkg_file = open('/path/to/MyAzureService.cspkg', 'rb')
status = self.azure.blobs.create_container('my-azure-service')
print '...create container status: %s' % status
status = self.azure.blobs.put_blob('my-azure-service', 'MyAzureService.cspkg',
cspkg_file.read())
print '...put blob status: %s' % status
cspkg_url = pa.blobs.get_base_url() + '/my-azure-service/MyAzureService.cspkg'
print "Creating hosted service 'myservice1'"
pa.wasm.create_service('myservice1', 'This is version 1 of my-service',
'anywhere us')
print 'Loading hosted service configuration from file'
cscfg = pa.wasm.ServiceConfiguration('/path/to/MyAzureService.cscfg')
print "Editing hosted service configuration to update connection strings for the 'pyazuretest' storage account"
cscfg.update_connections(pa.data_connection_string)
print "Editing hosted service configuration to update service settings"
cscfg.update_setting('WORKER_CONCURRENCY', 4)
cscfg.update_setting('WORKER_CLOUD_STORE', 'my-azure-service')
print 'Deploying to myservice1...'
request = pa.wasm.create_deployment('myservice1', 'staging', 'mydeployment1',
cspkg_url, 'Staging deployment of my-service v1', cscfg,
start_deployment=True)
pa.wasm.wait_for_request(request)
print 'Retrieving hosted service properties...'
s = pa.wasm.get_service_properties('myservice1', embed_detail=True)
print '%d roles instances in deployment' % \
len(s['Deployments'][0]['RoleInstanceList'])
print 'Updating deployment, increasing instances...'
cscfg += 1
request = pa.wasm.change_deployment_configuration('myservice1',
'mydeployment1', cscfg)
pa.wasm.wait_for_request(request)
print "Tearing down 'myservice1'"
pa.wasm.wait_for_request(pa.wasm.delete_deployment('myservice1',
'mydeployment1'))
pa.wasm.delete_service('myservice1')
pa.wasm.delete_storage_account('pyazuretest')