-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
servicemanagementservice.py
2477 lines (2284 loc) · 108 KB
/
servicemanagementservice.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#-------------------------------------------------------------------------
# Copyright (c) Microsoft. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
from azure import (
WindowsAzureError,
DEFAULT_HTTP_TIMEOUT,
MANAGEMENT_HOST,
_str,
_validate_not_none,
)
from azure.servicemanagement import (
AffinityGroups,
AffinityGroup,
AvailabilityResponse,
Certificate,
Certificates,
DataVirtualHardDisk,
Deployment,
Disk,
Disks,
Locations,
HostedService,
HostedServices,
Images,
OperatingSystems,
OperatingSystemFamilies,
OSImage,
PersistentVMRole,
ResourceExtensions,
ReservedIP,
ReservedIPs,
RoleSize,
RoleSizes,
StorageService,
StorageServices,
Subscription,
Subscriptions,
SubscriptionCertificate,
SubscriptionCertificates,
SubscriptionOperationCollection,
VirtualNetworkSites,
VMImages,
_XmlSerializer,
)
from azure.servicemanagement.servicemanagementclient import (
_ServiceManagementClient,
)
class ServiceManagementService(_ServiceManagementClient):
def __init__(self, subscription_id=None, cert_file=None,
host=MANAGEMENT_HOST, request_session=None,
timeout=DEFAULT_HTTP_TIMEOUT):
'''
Initializes the management service.
subscription_id:
Subscription to manage.
cert_file:
Path to .pem certificate file (httplib), or location of the
certificate in your Personal certificate store (winhttp) in the
CURRENT_USER\my\CertificateName format.
If a request_session is specified, then this is unused.
host:
Live ServiceClient URL. Defaults to Azure public cloud.
request_session:
Session object to use for http requests. If this is specified, it
replaces the default use of httplib or winhttp. Also, the cert_file
parameter is unused when a session is passed in.
The session object handles authentication, and as such can support
multiple types of authentication: .pem certificate, oauth.
For example, you can pass in a Session instance from the requests
library. To use .pem certificate authentication with requests
library, set the path to the .pem file on the session.cert
attribute.
timeout:
Optional. Timeout for the http request, in seconds.
'''
super(ServiceManagementService, self).__init__(
subscription_id, cert_file, host, request_session, timeout)
#--Operations for subscriptions --------------------------------------
def list_role_sizes(self):
'''
Lists the role sizes that are available under the specified
subscription.
'''
return self._perform_get(self._get_role_sizes_path(),
RoleSizes)
def list_subscriptions(self):
'''
Returns a list of subscriptions that you can access.
You must make sure that the request that is made to the management
service is secure using an Active Directory access token.
'''
return self._perform_get(self._get_subscriptions_path(),
Subscriptions)
#--Operations for storage accounts -----------------------------------
def list_storage_accounts(self):
'''
Lists the storage accounts available under the current subscription.
'''
return self._perform_get(self._get_storage_service_path(),
StorageServices)
def get_storage_account_properties(self, service_name):
'''
Returns system properties for the specified storage account.
service_name:
Name of the storage service account.
'''
_validate_not_none('service_name', service_name)
return self._perform_get(self._get_storage_service_path(service_name),
StorageService)
def get_storage_account_keys(self, service_name):
'''
Returns the primary and secondary access keys for the specified
storage account.
service_name:
Name of the storage service account.
'''
_validate_not_none('service_name', service_name)
return self._perform_get(
self._get_storage_service_path(service_name) + '/keys',
StorageService)
def regenerate_storage_account_keys(self, service_name, key_type):
'''
Regenerates the primary or secondary access key for the specified
storage account.
service_name:
Name of the storage service account.
key_type:
Specifies which key to regenerate. Valid values are:
Primary, Secondary
'''
_validate_not_none('service_name', service_name)
_validate_not_none('key_type', key_type)
return self._perform_post(
self._get_storage_service_path(
service_name) + '/keys?action=regenerate',
_XmlSerializer.regenerate_keys_to_xml(
key_type),
StorageService)
def create_storage_account(self, service_name, description, label,
affinity_group=None, location=None,
geo_replication_enabled=None,
extended_properties=None,
account_type='Standard_GRS'):
'''
Creates a new storage account in Windows Azure.
service_name:
A name for the storage account that is unique within Windows Azure.
Storage account names must be between 3 and 24 characters in length
and use numbers and lower-case letters only.
description:
A description for the storage account. The description may be up
to 1024 characters in length.
label:
A name for the storage account. The name may be up to 100
characters in length. The name can be used to identify the storage
account for your tracking purposes.
affinity_group:
The name of an existing affinity group in the specified
subscription. You can specify either a location or affinity_group,
but not both.
location:
The location where the storage account is created. You can specify
either a location or affinity_group, but not both.
geo_replication_enabled:
Deprecated. Replaced by the account_type parameter.
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
account_type:
Specifies whether the account supports locally-redundant storage,
geo-redundant storage, zone-redundant storage, or read access
geo-redundant storage.
Possible values are:
Standard_LRS, Standard_ZRS, Standard_GRS, Standard_RAGRS
'''
_validate_not_none('service_name', service_name)
_validate_not_none('description', description)
_validate_not_none('label', label)
if affinity_group is None and location is None:
raise WindowsAzureError(
'location or affinity_group must be specified')
if affinity_group is not None and location is not None:
raise WindowsAzureError(
'Only one of location or affinity_group needs to be specified')
if geo_replication_enabled == False:
account_type = 'Standard_LRS'
return self._perform_post(
self._get_storage_service_path(),
_XmlSerializer.create_storage_service_input_to_xml(
service_name,
description,
label,
affinity_group,
location,
account_type,
extended_properties),
async=True)
def update_storage_account(self, service_name, description=None,
label=None, geo_replication_enabled=None,
extended_properties=None,
account_type='Standard_GRS'):
'''
Updates the label, the description, and enables or disables the
geo-replication status for a storage account in Windows Azure.
service_name:
Name of the storage service account.
description:
A description for the storage account. The description may be up
to 1024 characters in length.
label:
A name for the storage account. The name may be up to 100
characters in length. The name can be used to identify the storage
account for your tracking purposes.
geo_replication_enabled:
Deprecated. Replaced by the account_type parameter.
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
account_type:
Specifies whether the account supports locally-redundant storage,
geo-redundant storage, zone-redundant storage, or read access
geo-redundant storage.
Possible values are:
Standard_LRS, Standard_ZRS, Standard_GRS, Standard_RAGRS
'''
_validate_not_none('service_name', service_name)
if geo_replication_enabled == False:
account_type = 'Standard_LRS'
return self._perform_put(
self._get_storage_service_path(service_name),
_XmlSerializer.update_storage_service_input_to_xml(
description,
label,
account_type,
extended_properties))
def delete_storage_account(self, service_name):
'''
Deletes the specified storage account from Windows Azure.
service_name:
Name of the storage service account.
'''
_validate_not_none('service_name', service_name)
return self._perform_delete(
self._get_storage_service_path(service_name))
def check_storage_account_name_availability(self, service_name):
'''
Checks to see if the specified storage account name is available, or
if it has already been taken.
service_name:
Name of the storage service account.
'''
_validate_not_none('service_name', service_name)
return self._perform_get(
self._get_storage_service_path() +
'/operations/isavailable/' +
_str(service_name) + '',
AvailabilityResponse)
#--Operations for hosted services ------------------------------------
def list_hosted_services(self):
'''
Lists the hosted services available under the current subscription.
'''
return self._perform_get(self._get_hosted_service_path(),
HostedServices)
def get_hosted_service_properties(self, service_name, embed_detail=False):
'''
Retrieves system properties for the specified hosted service. These
properties include the service name and service type; the name of the
affinity group to which the service belongs, or its location if it is
not part of an affinity group; and optionally, information on the
service's deployments.
service_name:
Name of the hosted service.
embed_detail:
When True, the management service returns properties for all
deployments of the service, as well as for the service itself.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('embed_detail', embed_detail)
return self._perform_get(
self._get_hosted_service_path(service_name) +
'?embed-detail=' +
_str(embed_detail).lower(),
HostedService)
def create_hosted_service(self, service_name, label, description=None,
location=None, affinity_group=None,
extended_properties=None):
'''
Creates a new hosted service in Windows Azure.
service_name:
A name for the hosted service that is unique within Windows Azure.
This name is the DNS prefix name and can be used to access the
hosted service.
label:
A name for the hosted service. The name can be up to 100 characters
in length. The name can be used to identify the storage account for
your tracking purposes.
description:
A description for the hosted service. The description can be up to
1024 characters in length.
location:
The location where the hosted service will be created. You can
specify either a location or affinity_group, but not both.
affinity_group:
The name of an existing affinity group associated with this
subscription. This name is a GUID and can be retrieved by examining
the name element of the response body returned by
list_affinity_groups. You can specify either a location or
affinity_group, but not both.
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('label', label)
if affinity_group is None and location is None:
raise WindowsAzureError(
'location or affinity_group must be specified')
if affinity_group is not None and location is not None:
raise WindowsAzureError(
'Only one of location or affinity_group needs to be specified')
return self._perform_post(self._get_hosted_service_path(),
_XmlSerializer.create_hosted_service_to_xml(
service_name,
label,
description,
location,
affinity_group,
extended_properties),
async=True)
def update_hosted_service(self, service_name, label=None, description=None,
extended_properties=None):
'''
Updates the label and/or the description for a hosted service in
Windows Azure.
service_name:
Name of the hosted service.
label:
A name for the hosted service. The name may be up to 100 characters
in length. You must specify a value for either Label or
Description, or for both. It is recommended that the label be
unique within the subscription. The name can be used
identify the hosted service for your tracking purposes.
description:
A description for the hosted service. The description may be up to
1024 characters in length. You must specify a value for either
Label or Description, or for both.
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
'''
_validate_not_none('service_name', service_name)
return self._perform_put(self._get_hosted_service_path(service_name),
_XmlSerializer.update_hosted_service_to_xml(
label,
description,
extended_properties))
def delete_hosted_service(self, service_name, complete=False):
'''
Deletes the specified hosted service from Windows Azure.
service_name:
Name of the hosted service.
complete:
True if all OS/data disks and the source blobs for the disks should
also be deleted from storage.
'''
_validate_not_none('service_name', service_name)
path = self._get_hosted_service_path(service_name)
if complete == True:
path = path +'?comp=media'
return self._perform_delete(path, async=True)
def get_deployment_by_slot(self, service_name, deployment_slot):
'''
Returns configuration information, status, and system properties for
a deployment.
service_name:
Name of the hosted service.
deployment_slot:
The environment to which the hosted service is deployed. Valid
values are: staging, production
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_slot', deployment_slot)
return self._perform_get(
self._get_deployment_path_using_slot(
service_name, deployment_slot),
Deployment)
def get_deployment_by_name(self, service_name, deployment_name):
'''
Returns configuration information, status, and system properties for a
deployment.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
return self._perform_get(
self._get_deployment_path_using_name(
service_name, deployment_name),
Deployment)
def create_deployment(self, service_name, deployment_slot, name,
package_url, label, configuration,
start_deployment=False,
treat_warnings_as_error=False,
extended_properties=None):
'''
Uploads a new service package and creates a new deployment on staging
or production.
service_name:
Name of the hosted service.
deployment_slot:
The environment to which the hosted service is deployed. Valid
values are: staging, production
name:
The name for the deployment. The deployment name must be unique
among other deployments for the hosted service.
package_url:
A URL that refers to the location of the service package in the
Blob service. The service package can be located either in a
storage account beneath the same subscription or a Shared Access
Signature (SAS) URI from any storage account.
label:
A name for the hosted service. The name can be up to 100 characters
in length. It is recommended that the label be unique within the
subscription. The name can be used to identify the hosted service
for your tracking purposes.
configuration:
The base-64 encoded service configuration file for the deployment.
start_deployment:
Indicates whether to start the deployment immediately after it is
created. If false, the service model is still deployed to the
virtual machines but the code is not run immediately. Instead, the
service is Suspended until you call Update Deployment Status and
set the status to Running, at which time the service will be
started. A deployed service still incurs charges, even if it is
suspended.
treat_warnings_as_error:
Indicates whether to treat package validation warnings as errors.
If set to true, the Created Deployment operation fails if there
are validation warnings on the service package.
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_slot', deployment_slot)
_validate_not_none('name', name)
_validate_not_none('package_url', package_url)
_validate_not_none('label', label)
_validate_not_none('configuration', configuration)
return self._perform_post(
self._get_deployment_path_using_slot(
service_name, deployment_slot),
_XmlSerializer.create_deployment_to_xml(
name,
package_url,
label,
configuration,
start_deployment,
treat_warnings_as_error,
extended_properties),
async=True)
def delete_deployment(self, service_name, deployment_name,delete_vhd=False):
'''
Deletes the specified deployment.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
path= self._get_deployment_path_using_name(service_name, deployment_name)
if delete_vhd:
path += '?comp=media'
return self._perform_delete(
path,
async=True)
def swap_deployment(self, service_name, production, source_deployment):
'''
Initiates a virtual IP swap between the staging and production
deployment environments for a service. If the service is currently
running in the staging environment, it will be swapped to the
production environment. If it is running in the production
environment, it will be swapped to staging.
service_name:
Name of the hosted service.
production:
The name of the production deployment.
source_deployment:
The name of the source deployment.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('production', production)
_validate_not_none('source_deployment', source_deployment)
return self._perform_post(self._get_hosted_service_path(service_name),
_XmlSerializer.swap_deployment_to_xml(
production, source_deployment),
async=True)
def change_deployment_configuration(self, service_name, deployment_name,
configuration,
treat_warnings_as_error=False,
mode='Auto', extended_properties=None):
'''
Initiates a change to the deployment configuration.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
configuration:
The base-64 encoded service configuration file for the deployment.
treat_warnings_as_error:
Indicates whether to treat package validation warnings as errors.
If set to true, the Created Deployment operation fails if there
are validation warnings on the service package.
mode:
If set to Manual, WalkUpgradeDomain must be called to apply the
update. If set to Auto, the Windows Azure platform will
automatically apply the update To each upgrade domain for the
service. Possible values are: Auto, Manual
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('configuration', configuration)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + '/?comp=config',
_XmlSerializer.change_deployment_to_xml(
configuration,
treat_warnings_as_error,
mode,
extended_properties),
async=True)
def update_deployment_status(self, service_name, deployment_name, status):
'''
Initiates a change in deployment status.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
status:
The change to initiate to the deployment status. Possible values
include:
Running, Suspended
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('status', status)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + '/?comp=status',
_XmlSerializer.update_deployment_status_to_xml(
status),
async=True)
def upgrade_deployment(self, service_name, deployment_name, mode,
package_url, configuration, label, force,
role_to_upgrade=None, extended_properties=None):
'''
Initiates an upgrade.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
mode:
If set to Manual, WalkUpgradeDomain must be called to apply the
update. If set to Auto, the Windows Azure platform will
automatically apply the update To each upgrade domain for the
service. Possible values are: Auto, Manual
package_url:
A URL that refers to the location of the service package in the
Blob service. The service package can be located either in a
storage account beneath the same subscription or a Shared Access
Signature (SAS) URI from any storage account.
configuration:
The base-64 encoded service configuration file for the deployment.
label:
A name for the hosted service. The name can be up to 100 characters
in length. It is recommended that the label be unique within the
subscription. The name can be used to identify the hosted service
for your tracking purposes.
force:
Specifies whether the rollback should proceed even when it will
cause local data to be lost from some role instances. True if the
rollback should proceed; otherwise false if the rollback should
fail.
role_to_upgrade:
The name of the specific role to upgrade.
extended_properties:
Dictionary containing name/value pairs of storage account
properties. You can have a maximum of 50 extended property
name/value pairs. The maximum length of the Name element is 64
characters, only alphanumeric characters and underscores are valid
in the Name, and the name must start with a letter. The value has
a maximum length of 255 characters.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('mode', mode)
_validate_not_none('package_url', package_url)
_validate_not_none('configuration', configuration)
_validate_not_none('label', label)
_validate_not_none('force', force)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + '/?comp=upgrade',
_XmlSerializer.upgrade_deployment_to_xml(
mode,
package_url,
configuration,
label,
role_to_upgrade,
force,
extended_properties),
async=True)
def walk_upgrade_domain(self, service_name, deployment_name,
upgrade_domain):
'''
Specifies the next upgrade domain to be walked during manual in-place
upgrade or configuration change.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
upgrade_domain:
An integer value that identifies the upgrade domain to walk.
Upgrade domains are identified with a zero-based index: the first
upgrade domain has an ID of 0, the second has an ID of 1, and so on.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('upgrade_domain', upgrade_domain)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + '/?comp=walkupgradedomain',
_XmlSerializer.walk_upgrade_domain_to_xml(
upgrade_domain),
async=True)
def rollback_update_or_upgrade(self, service_name, deployment_name, mode,
force):
'''
Cancels an in progress configuration change (update) or upgrade and
returns the deployment to its state before the upgrade or
configuration change was started.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
mode:
Specifies whether the rollback should proceed automatically.
auto - The rollback proceeds without further user input.
manual - You must call the Walk Upgrade Domain operation to
apply the rollback to each upgrade domain.
force:
Specifies whether the rollback should proceed even when it will
cause local data to be lost from some role instances. True if the
rollback should proceed; otherwise false if the rollback should
fail.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('mode', mode)
_validate_not_none('force', force)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + '/?comp=rollback',
_XmlSerializer.rollback_upgrade_to_xml(
mode, force),
async=True)
def reboot_role_instance(self, service_name, deployment_name,
role_instance_name):
'''
Requests a reboot of a role instance that is running in a deployment.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
role_instance_name:
The name of the role instance.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('role_instance_name', role_instance_name)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + \
'/roleinstances/' + _str(role_instance_name) + \
'?comp=reboot',
'',
async=True)
def reimage_role_instance(self, service_name, deployment_name,
role_instance_name):
'''
Requests a reimage of a role instance that is running in a deployment.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
role_instance_name:
The name of the role instance.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('role_instance_name', role_instance_name)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + \
'/roleinstances/' + _str(role_instance_name) + \
'?comp=reimage',
'',
async=True)
def rebuild_role_instance(self, service_name, deployment_name,
role_instance_name):
'''
Reinstalls the operating system on instances of web roles or worker
roles and initializes the storage resources that are used by them. If
you do not want to initialize storage resources, you can use
reimage_role_instance.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
role_instance_name:
The name of the role instance.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('role_instance_name', role_instance_name)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + \
'/roleinstances/' + _str(role_instance_name) + \
'?comp=rebuild&resources=allLocalDrives',
'',
async=True)
def delete_role_instances(self, service_name, deployment_name,
role_instance_names):
'''
Reinstalls the operating system on instances of web roles or worker
roles and initializes the storage resources that are used by them. If
you do not want to initialize storage resources, you can use
reimage_role_instance.
service_name:
Name of the hosted service.
deployment_name:
The name of the deployment.
role_instance_names:
List of role instance names.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('deployment_name', deployment_name)
_validate_not_none('role_instance_names', role_instance_names)
return self._perform_post(
self._get_deployment_path_using_name(
service_name, deployment_name) + '/roleinstances/?comp=delete',
_XmlSerializer.role_instances_to_xml(role_instance_names),
async=True)
def check_hosted_service_name_availability(self, service_name):
'''
Checks to see if the specified hosted service name is available, or if
it has already been taken.
service_name:
Name of the hosted service.
'''
_validate_not_none('service_name', service_name)
return self._perform_get(
'/' + self.subscription_id +
'/services/hostedservices/operations/isavailable/' +
_str(service_name) + '',
AvailabilityResponse)
#--Operations for service certificates -------------------------------
def list_service_certificates(self, service_name):
'''
Lists all of the service certificates associated with the specified
hosted service.
service_name:
Name of the hosted service.
'''
_validate_not_none('service_name', service_name)
return self._perform_get(
'/' + self.subscription_id + '/services/hostedservices/' +
_str(service_name) + '/certificates',
Certificates)
def get_service_certificate(self, service_name, thumbalgorithm, thumbprint):
'''
Returns the public data for the specified X.509 certificate associated
with a hosted service.
service_name:
Name of the hosted service.
thumbalgorithm:
The algorithm for the certificate's thumbprint.
thumbprint:
The hexadecimal representation of the thumbprint.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('thumbalgorithm', thumbalgorithm)
_validate_not_none('thumbprint', thumbprint)
return self._perform_get(
'/' + self.subscription_id + '/services/hostedservices/' +
_str(service_name) + '/certificates/' +
_str(thumbalgorithm) + '-' + _str(thumbprint) + '',
Certificate)
def add_service_certificate(self, service_name, data, certificate_format,
password=None):
'''
Adds a certificate to a hosted service.
service_name:
Name of the hosted service.
data:
The base-64 encoded form of the pfx/cer file.
certificate_format:
The service certificate format.
password:
The certificate password. Default to None when using cer format.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('data', data)
_validate_not_none('certificate_format', certificate_format)
_validate_not_none('password', password)
return self._perform_post(
'/' + self.subscription_id + '/services/hostedservices/' +
_str(service_name) + '/certificates',
_XmlSerializer.certificate_file_to_xml(
data, certificate_format, password),
async=True)
def delete_service_certificate(self, service_name, thumbalgorithm,
thumbprint):
'''
Deletes a service certificate from the certificate store of a hosted
service.
service_name:
Name of the hosted service.
thumbalgorithm:
The algorithm for the certificate's thumbprint.
thumbprint:
The hexadecimal representation of the thumbprint.
'''
_validate_not_none('service_name', service_name)
_validate_not_none('thumbalgorithm', thumbalgorithm)
_validate_not_none('thumbprint', thumbprint)
return self._perform_delete(
'/' + self.subscription_id + '/services/hostedservices/' +
_str(service_name) + '/certificates/' +
_str(thumbalgorithm) + '-' + _str(thumbprint),
async=True)
#--Operations for management certificates ----------------------------
def list_management_certificates(self):
'''
The List Management Certificates operation lists and returns basic
information about all of the management certificates associated with
the specified subscription. Management certificates, which are also
known as subscription certificates, authenticate clients attempting to
connect to resources associated with your Windows Azure subscription.
'''
return self._perform_get('/' + self.subscription_id + '/certificates',
SubscriptionCertificates)
def get_management_certificate(self, thumbprint):
'''
The Get Management Certificate operation retrieves information about
the management certificate with the specified thumbprint. Management
certificates, which are also known as subscription certificates,
authenticate clients attempting to connect to resources associated
with your Windows Azure subscription.
thumbprint:
The thumbprint value of the certificate.
'''
_validate_not_none('thumbprint', thumbprint)
return self._perform_get(
'/' + self.subscription_id + '/certificates/' + _str(thumbprint),
SubscriptionCertificate)
def add_management_certificate(self, public_key, thumbprint, data):
'''
The Add Management Certificate operation adds a certificate to the
list of management certificates. Management certificates, which are
also known as subscription certificates, authenticate clients
attempting to connect to resources associated with your Windows Azure
subscription.
public_key:
A base64 representation of the management certificate public key.
thumbprint:
The thumb print that uniquely identifies the management
certificate.
data: