1
#-------------------------------------------------------------------------
2
# Copyright (c) Microsoft. All rights reserved.
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
#--------------------------------------------------------------------------
21
from azure.servicemanagement import (
37
OperatingSystemFamilies,
43
SubscriptionCertificate,
44
SubscriptionCertificates,
48
from azure.servicemanagement.servicemanagementclient import (
49
_ServiceManagementClient,
52
class ServiceManagementService(_ServiceManagementClient):
54
def __init__(self, subscription_id=None, cert_file=None,
55
host=MANAGEMENT_HOST):
56
super(ServiceManagementService, self).__init__(
57
subscription_id, cert_file, host)
59
#--Operations for storage accounts -----------------------------------
60
def list_storage_accounts(self):
62
Lists the storage accounts available under the current subscription.
64
return self._perform_get(self._get_storage_service_path(),
67
def get_storage_account_properties(self, service_name):
69
Returns system properties for the specified storage account.
71
service_name: Name of the storage service account.
73
_validate_not_none('service_name', service_name)
74
return self._perform_get(self._get_storage_service_path(service_name),
77
def get_storage_account_keys(self, service_name):
79
Returns the primary and secondary access keys for the specified
82
service_name: Name of the storage service account.
84
_validate_not_none('service_name', service_name)
85
return self._perform_get(
86
self._get_storage_service_path(service_name) + '/keys',
89
def regenerate_storage_account_keys(self, service_name, key_type):
91
Regenerates the primary or secondary access key for the specified
94
service_name: Name of the storage service account.
96
Specifies which key to regenerate. Valid values are:
99
_validate_not_none('service_name', service_name)
100
_validate_not_none('key_type', key_type)
101
return self._perform_post(
102
self._get_storage_service_path(
103
service_name) + '/keys?action=regenerate',
104
_XmlSerializer.regenerate_keys_to_xml(
108
def create_storage_account(self, service_name, description, label,
109
affinity_group=None, location=None,
110
geo_replication_enabled=True,
111
extended_properties=None):
113
Creates a new storage account in Windows Azure.
116
A name for the storage account that is unique within Windows Azure.
117
Storage account names must be between 3 and 24 characters in length
118
and use numbers and lower-case letters only.
120
A description for the storage account. The description may be up
121
to 1024 characters in length.
123
A name for the storage account. The name may be up to 100
124
characters in length. The name can be used to identify the storage
125
account for your tracking purposes.
127
The name of an existing affinity group in the specified
128
subscription. You can specify either a location or affinity_group,
131
The location where the storage account is created. You can specify
132
either a location or affinity_group, but not both.
133
geo_replication_enabled:
134
Specifies whether the storage account is created with the
135
geo-replication enabled. If the element is not included in the
136
request body, the default value is true. If set to true, the data
137
in the storage account is replicated across more than one
138
geographic location so as to enable resilience in the face of
139
catastrophic service loss.
141
Dictionary containing name/value pairs of storage account
142
properties. You can have a maximum of 50 extended property
143
name/value pairs. The maximum length of the Name element is 64
144
characters, only alphanumeric characters and underscores are valid
145
in the Name, and the name must start with a letter. The value has
146
a maximum length of 255 characters.
148
_validate_not_none('service_name', service_name)
149
_validate_not_none('description', description)
150
_validate_not_none('label', label)
151
if affinity_group is None and location is None:
152
raise WindowsAzureError(
153
'location or affinity_group must be specified')
154
if affinity_group is not None and location is not None:
155
raise WindowsAzureError(
156
'Only one of location or affinity_group needs to be specified')
157
return self._perform_post(
158
self._get_storage_service_path(),
159
_XmlSerializer.create_storage_service_input_to_xml(
165
geo_replication_enabled,
166
extended_properties),
169
def update_storage_account(self, service_name, description=None,
170
label=None, geo_replication_enabled=None,
171
extended_properties=None):
173
Updates the label, the description, and enables or disables the
174
geo-replication status for a storage account in Windows Azure.
176
service_name: Name of the storage service account.
178
A description for the storage account. The description may be up
179
to 1024 characters in length.
181
A name for the storage account. The name may be up to 100
182
characters in length. The name can be used to identify the storage
183
account for your tracking purposes.
184
geo_replication_enabled:
185
Specifies whether the storage account is created with the
186
geo-replication enabled. If the element is not included in the
187
request body, the default value is true. If set to true, the data
188
in the storage account is replicated across more than one
189
geographic location so as to enable resilience in the face of
190
catastrophic service loss.
192
Dictionary containing name/value pairs of storage account
193
properties. You can have a maximum of 50 extended property
194
name/value pairs. The maximum length of the Name element is 64
195
characters, only alphanumeric characters and underscores are valid
196
in the Name, and the name must start with a letter. The value has
197
a maximum length of 255 characters.
199
_validate_not_none('service_name', service_name)
200
return self._perform_put(
201
self._get_storage_service_path(service_name),
202
_XmlSerializer.update_storage_service_input_to_xml(
205
geo_replication_enabled,
206
extended_properties))
208
def delete_storage_account(self, service_name):
210
Deletes the specified storage account from Windows Azure.
212
service_name: Name of the storage service account.
214
_validate_not_none('service_name', service_name)
215
return self._perform_delete(
216
self._get_storage_service_path(service_name))
218
def check_storage_account_name_availability(self, service_name):
220
Checks to see if the specified storage account name is available, or
221
if it has already been taken.
223
service_name: Name of the storage service account.
225
_validate_not_none('service_name', service_name)
226
return self._perform_get(
227
self._get_storage_service_path() +
228
'/operations/isavailable/' +
229
_str(service_name) + '',
230
AvailabilityResponse)
232
#--Operations for hosted services ------------------------------------
233
def list_hosted_services(self):
235
Lists the hosted services available under the current subscription.
237
return self._perform_get(self._get_hosted_service_path(),
240
def get_hosted_service_properties(self, service_name, embed_detail=False):
242
Retrieves system properties for the specified hosted service. These
243
properties include the service name and service type; the name of the
244
affinity group to which the service belongs, or its location if it is
245
not part of an affinity group; and optionally, information on the
246
service's deployments.
248
service_name: Name of the hosted service.
250
When True, the management service returns properties for all
251
deployments of the service, as well as for the service itself.
253
_validate_not_none('service_name', service_name)
254
_validate_not_none('embed_detail', embed_detail)
255
return self._perform_get(
256
self._get_hosted_service_path(service_name) +
258
_str(embed_detail).lower(),
261
def create_hosted_service(self, service_name, label, description=None,
262
location=None, affinity_group=None,
263
extended_properties=None):
265
Creates a new hosted service in Windows Azure.
268
A name for the hosted service that is unique within Windows Azure.
269
This name is the DNS prefix name and can be used to access the
272
A name for the hosted service. The name can be up to 100 characters
273
in length. The name can be used to identify the storage account for
274
your tracking purposes.
276
A description for the hosted service. The description can be up to
277
1024 characters in length.
279
The location where the hosted service will be created. You can
280
specify either a location or affinity_group, but not both.
282
The name of an existing affinity group associated with this
283
subscription. This name is a GUID and can be retrieved by examining
284
the name element of the response body returned by
285
list_affinity_groups. You can specify either a location or
286
affinity_group, but not both.
288
Dictionary containing name/value pairs of storage account
289
properties. You can have a maximum of 50 extended property
290
name/value pairs. The maximum length of the Name element is 64
291
characters, only alphanumeric characters and underscores are valid
292
in the Name, and the name must start with a letter. The value has
293
a maximum length of 255 characters.
295
_validate_not_none('service_name', service_name)
296
_validate_not_none('label', label)
297
if affinity_group is None and location is None:
298
raise WindowsAzureError(
299
'location or affinity_group must be specified')
300
if affinity_group is not None and location is not None:
301
raise WindowsAzureError(
302
'Only one of location or affinity_group needs to be specified')
303
return self._perform_post(self._get_hosted_service_path(),
304
_XmlSerializer.create_hosted_service_to_xml(
310
extended_properties))
312
def update_hosted_service(self, service_name, label=None, description=None,
313
extended_properties=None):
315
Updates the label and/or the description for a hosted service in
318
service_name: Name of the hosted service.
320
A name for the hosted service. The name may be up to 100 characters
321
in length. You must specify a value for either Label or
322
Description, or for both. It is recommended that the label be
323
unique within the subscription. The name can be used
324
identify the hosted service for your tracking purposes.
326
A description for the hosted service. The description may be up to
327
1024 characters in length. You must specify a value for either
328
Label or Description, or for both.
330
Dictionary containing name/value pairs of storage account
331
properties. You can have a maximum of 50 extended property
332
name/value pairs. The maximum length of the Name element is 64
333
characters, only alphanumeric characters and underscores are valid
334
in the Name, and the name must start with a letter. The value has
335
a maximum length of 255 characters.
337
_validate_not_none('service_name', service_name)
338
return self._perform_put(self._get_hosted_service_path(service_name),
339
_XmlSerializer.update_hosted_service_to_xml(
342
extended_properties))
344
def delete_hosted_service(self, service_name):
346
Deletes the specified hosted service from Windows Azure.
348
service_name: Name of the hosted service.
350
_validate_not_none('service_name', service_name)
351
return self._perform_delete(self._get_hosted_service_path(service_name))
353
def get_deployment_by_slot(self, service_name, deployment_slot):
355
Returns configuration information, status, and system properties for
358
service_name: Name of the hosted service.
360
The environment to which the hosted service is deployed. Valid
361
values are: staging, production
363
_validate_not_none('service_name', service_name)
364
_validate_not_none('deployment_slot', deployment_slot)
365
return self._perform_get(
366
self._get_deployment_path_using_slot(
367
service_name, deployment_slot),
370
def get_deployment_by_name(self, service_name, deployment_name):
372
Returns configuration information, status, and system properties for a
375
service_name: Name of the hosted service.
376
deployment_name: The name of the deployment.
378
_validate_not_none('service_name', service_name)
379
_validate_not_none('deployment_name', deployment_name)
380
return self._perform_get(
381
self._get_deployment_path_using_name(
382
service_name, deployment_name),
385
def create_deployment(self, service_name, deployment_slot, name,
386
package_url, label, configuration,
387
start_deployment=False,
388
treat_warnings_as_error=False,
389
extended_properties=None):
391
Uploads a new service package and creates a new deployment on staging
394
service_name: Name of the hosted service.
396
The environment to which the hosted service is deployed. Valid
397
values are: staging, production
399
The name for the deployment. The deployment name must be unique
400
among other deployments for the hosted service.
402
A URL that refers to the location of the service package in the
403
Blob service. The service package can be located either in a
404
storage account beneath the same subscription or a Shared Access
405
Signature (SAS) URI from any storage account.
407
A name for the hosted service. The name can be up to 100 characters
408
in length. It is recommended that the label be unique within the
409
subscription. The name can be used to identify the hosted service
410
for your tracking purposes.
412
The base-64 encoded service configuration file for the deployment.
414
Indicates whether to start the deployment immediately after it is
415
created. If false, the service model is still deployed to the
416
virtual machines but the code is not run immediately. Instead, the
417
service is Suspended until you call Update Deployment Status and
418
set the status to Running, at which time the service will be
419
started. A deployed service still incurs charges, even if it is
421
treat_warnings_as_error:
422
Indicates whether to treat package validation warnings as errors.
423
If set to true, the Created Deployment operation fails if there
424
are validation warnings on the service package.
426
Dictionary containing name/value pairs of storage account
427
properties. You can have a maximum of 50 extended property
428
name/value pairs. The maximum length of the Name element is 64
429
characters, only alphanumeric characters and underscores are valid
430
in the Name, and the name must start with a letter. The value has
431
a maximum length of 255 characters.
433
_validate_not_none('service_name', service_name)
434
_validate_not_none('deployment_slot', deployment_slot)
435
_validate_not_none('name', name)
436
_validate_not_none('package_url', package_url)
437
_validate_not_none('label', label)
438
_validate_not_none('configuration', configuration)
439
return self._perform_post(
440
self._get_deployment_path_using_slot(
441
service_name, deployment_slot),
442
_XmlSerializer.create_deployment_to_xml(
448
treat_warnings_as_error,
449
extended_properties),
452
def delete_deployment(self, service_name, deployment_name):
454
Deletes the specified deployment.
456
service_name: Name of the hosted service.
457
deployment_name: The name of the deployment.
459
_validate_not_none('service_name', service_name)
460
_validate_not_none('deployment_name', deployment_name)
461
return self._perform_delete(
462
self._get_deployment_path_using_name(
463
service_name, deployment_name),
466
def swap_deployment(self, service_name, production, source_deployment):
468
Initiates a virtual IP swap between the staging and production
469
deployment environments for a service. If the service is currently
470
running in the staging environment, it will be swapped to the
471
production environment. If it is running in the production
472
environment, it will be swapped to staging.
474
service_name: Name of the hosted service.
475
production: The name of the production deployment.
476
source_deployment: The name of the source deployment.
478
_validate_not_none('service_name', service_name)
479
_validate_not_none('production', production)
480
_validate_not_none('source_deployment', source_deployment)
481
return self._perform_post(self._get_hosted_service_path(service_name),
482
_XmlSerializer.swap_deployment_to_xml(
483
production, source_deployment),
486
def change_deployment_configuration(self, service_name, deployment_name,
488
treat_warnings_as_error=False,
489
mode='Auto', extended_properties=None):
491
Initiates a change to the deployment configuration.
493
service_name: Name of the hosted service.
494
deployment_name: The name of the deployment.
496
The base-64 encoded service configuration file for the deployment.
497
treat_warnings_as_error:
498
Indicates whether to treat package validation warnings as errors.
499
If set to true, the Created Deployment operation fails if there
500
are validation warnings on the service package.
502
If set to Manual, WalkUpgradeDomain must be called to apply the
503
update. If set to Auto, the Windows Azure platform will
504
automatically apply the update To each upgrade domain for the
505
service. Possible values are: Auto, Manual
507
Dictionary containing name/value pairs of storage account
508
properties. You can have a maximum of 50 extended property
509
name/value pairs. The maximum length of the Name element is 64
510
characters, only alphanumeric characters and underscores are valid
511
in the Name, and the name must start with a letter. The value has
512
a maximum length of 255 characters.
514
_validate_not_none('service_name', service_name)
515
_validate_not_none('deployment_name', deployment_name)
516
_validate_not_none('configuration', configuration)
517
return self._perform_post(
518
self._get_deployment_path_using_name(
519
service_name, deployment_name) + '/?comp=config',
520
_XmlSerializer.change_deployment_to_xml(
522
treat_warnings_as_error,
524
extended_properties),
527
def update_deployment_status(self, service_name, deployment_name, status):
529
Initiates a change in deployment status.
531
service_name: Name of the hosted service.
532
deployment_name: The name of the deployment.
534
The change to initiate to the deployment status. Possible values
535
include: Running, Suspended
537
_validate_not_none('service_name', service_name)
538
_validate_not_none('deployment_name', deployment_name)
539
_validate_not_none('status', status)
540
return self._perform_post(
541
self._get_deployment_path_using_name(
542
service_name, deployment_name) + '/?comp=status',
543
_XmlSerializer.update_deployment_status_to_xml(
547
def upgrade_deployment(self, service_name, deployment_name, mode,
548
package_url, configuration, label, force,
549
role_to_upgrade=None, extended_properties=None):
551
Initiates an upgrade.
553
service_name: Name of the hosted service.
554
deployment_name: The name of the deployment.
556
If set to Manual, WalkUpgradeDomain must be called to apply the
557
update. If set to Auto, the Windows Azure platform will
558
automatically apply the update To each upgrade domain for the
559
service. Possible values are: Auto, Manual
561
A URL that refers to the location of the service package in the
562
Blob service. The service package can be located either in a
563
storage account beneath the same subscription or a Shared Access
564
Signature (SAS) URI from any storage account.
566
The base-64 encoded service configuration file for the deployment.
568
A name for the hosted service. The name can be up to 100 characters
569
in length. It is recommended that the label be unique within the
570
subscription. The name can be used to identify the hosted service
571
for your tracking purposes.
573
Specifies whether the rollback should proceed even when it will
574
cause local data to be lost from some role instances. True if the
575
rollback should proceed; otherwise false if the rollback should
577
role_to_upgrade: The name of the specific role to upgrade.
579
Dictionary containing name/value pairs of storage account
580
properties. You can have a maximum of 50 extended property
581
name/value pairs. The maximum length of the Name element is 64
582
characters, only alphanumeric characters and underscores are valid
583
in the Name, and the name must start with a letter. The value has
584
a maximum length of 255 characters.
586
_validate_not_none('service_name', service_name)
587
_validate_not_none('deployment_name', deployment_name)
588
_validate_not_none('mode', mode)
589
_validate_not_none('package_url', package_url)
590
_validate_not_none('configuration', configuration)
591
_validate_not_none('label', label)
592
_validate_not_none('force', force)
593
return self._perform_post(
594
self._get_deployment_path_using_name(
595
service_name, deployment_name) + '/?comp=upgrade',
596
_XmlSerializer.upgrade_deployment_to_xml(
603
extended_properties),
606
def walk_upgrade_domain(self, service_name, deployment_name,
609
Specifies the next upgrade domain to be walked during manual in-place
610
upgrade or configuration change.
612
service_name: Name of the hosted service.
613
deployment_name: The name of the deployment.
615
An integer value that identifies the upgrade domain to walk.
616
Upgrade domains are identified with a zero-based index: the first
617
upgrade domain has an ID of 0, the second has an ID of 1, and so on.
619
_validate_not_none('service_name', service_name)
620
_validate_not_none('deployment_name', deployment_name)
621
_validate_not_none('upgrade_domain', upgrade_domain)
622
return self._perform_post(
623
self._get_deployment_path_using_name(
624
service_name, deployment_name) + '/?comp=walkupgradedomain',
625
_XmlSerializer.walk_upgrade_domain_to_xml(
629
def rollback_update_or_upgrade(self, service_name, deployment_name, mode,
632
Cancels an in progress configuration change (update) or upgrade and
633
returns the deployment to its state before the upgrade or
634
configuration change was started.
636
service_name: Name of the hosted service.
637
deployment_name: The name of the deployment.
639
Specifies whether the rollback should proceed automatically.
640
auto - The rollback proceeds without further user input.
641
manual - You must call the Walk Upgrade Domain operation to
642
apply the rollback to each upgrade domain.
644
Specifies whether the rollback should proceed even when it will
645
cause local data to be lost from some role instances. True if the
646
rollback should proceed; otherwise false if the rollback should
649
_validate_not_none('service_name', service_name)
650
_validate_not_none('deployment_name', deployment_name)
651
_validate_not_none('mode', mode)
652
_validate_not_none('force', force)
653
return self._perform_post(
654
self._get_deployment_path_using_name(
655
service_name, deployment_name) + '/?comp=rollback',
656
_XmlSerializer.rollback_upgrade_to_xml(
660
def reboot_role_instance(self, service_name, deployment_name,
663
Requests a reboot of a role instance that is running in a deployment.
665
service_name: Name of the hosted service.
666
deployment_name: The name of the deployment.
667
role_instance_name: The name of the role instance.
669
_validate_not_none('service_name', service_name)
670
_validate_not_none('deployment_name', deployment_name)
671
_validate_not_none('role_instance_name', role_instance_name)
672
return self._perform_post(
673
self._get_deployment_path_using_name(
674
service_name, deployment_name) + \
675
'/roleinstances/' + _str(role_instance_name) + \
680
def reimage_role_instance(self, service_name, deployment_name,
683
Requests a reimage of a role instance that is running in a deployment.
685
service_name: Name of the hosted service.
686
deployment_name: The name of the deployment.
687
role_instance_name: The name of the role instance.
689
_validate_not_none('service_name', service_name)
690
_validate_not_none('deployment_name', deployment_name)
691
_validate_not_none('role_instance_name', role_instance_name)
692
return self._perform_post(
693
self._get_deployment_path_using_name(
694
service_name, deployment_name) + \
695
'/roleinstances/' + _str(role_instance_name) + \
700
def check_hosted_service_name_availability(self, service_name):
702
Checks to see if the specified hosted service name is available, or if
703
it has already been taken.
705
service_name: Name of the hosted service.
707
_validate_not_none('service_name', service_name)
708
return self._perform_get(
709
'/' + self.subscription_id +
710
'/services/hostedservices/operations/isavailable/' +
711
_str(service_name) + '',
712
AvailabilityResponse)
714
#--Operations for service certificates -------------------------------
715
def list_service_certificates(self, service_name):
717
Lists all of the service certificates associated with the specified
720
service_name: Name of the hosted service.
722
_validate_not_none('service_name', service_name)
723
return self._perform_get(
724
'/' + self.subscription_id + '/services/hostedservices/' +
725
_str(service_name) + '/certificates',
728
def get_service_certificate(self, service_name, thumbalgorithm, thumbprint):
730
Returns the public data for the specified X.509 certificate associated
731
with a hosted service.
733
service_name: Name of the hosted service.
734
thumbalgorithm: The algorithm for the certificate's thumbprint.
735
thumbprint: The hexadecimal representation of the thumbprint.
737
_validate_not_none('service_name', service_name)
738
_validate_not_none('thumbalgorithm', thumbalgorithm)
739
_validate_not_none('thumbprint', thumbprint)
740
return self._perform_get(
741
'/' + self.subscription_id + '/services/hostedservices/' +
742
_str(service_name) + '/certificates/' +
743
_str(thumbalgorithm) + '-' + _str(thumbprint) + '',
746
def add_service_certificate(self, service_name, data, certificate_format,
749
Adds a certificate to a hosted service.
751
service_name: Name of the hosted service.
752
data: The base-64 encoded form of the pfx file.
754
The service certificate format. The only supported value is pfx.
755
password: The certificate password.
757
_validate_not_none('service_name', service_name)
758
_validate_not_none('data', data)
759
_validate_not_none('certificate_format', certificate_format)
760
_validate_not_none('password', password)
761
return self._perform_post(
762
'/' + self.subscription_id + '/services/hostedservices/' +
763
_str(service_name) + '/certificates',
764
_XmlSerializer.certificate_file_to_xml(
765
data, certificate_format, password),
768
def delete_service_certificate(self, service_name, thumbalgorithm,
771
Deletes a service certificate from the certificate store of a hosted
774
service_name: Name of the hosted service.
775
thumbalgorithm: The algorithm for the certificate's thumbprint.
776
thumbprint: The hexadecimal representation of the thumbprint.
778
_validate_not_none('service_name', service_name)
779
_validate_not_none('thumbalgorithm', thumbalgorithm)
780
_validate_not_none('thumbprint', thumbprint)
781
return self._perform_delete(
782
'/' + self.subscription_id + '/services/hostedservices/' +
783
_str(service_name) + '/certificates/' +
784
_str(thumbalgorithm) + '-' + _str(thumbprint),
787
#--Operations for management certificates ----------------------------
788
def list_management_certificates(self):
790
The List Management Certificates operation lists and returns basic
791
information about all of the management certificates associated with
792
the specified subscription. Management certificates, which are also
793
known as subscription certificates, authenticate clients attempting to
794
connect to resources associated with your Windows Azure subscription.
796
return self._perform_get('/' + self.subscription_id + '/certificates',
797
SubscriptionCertificates)
799
def get_management_certificate(self, thumbprint):
801
The Get Management Certificate operation retrieves information about
802
the management certificate with the specified thumbprint. Management
803
certificates, which are also known as subscription certificates,
804
authenticate clients attempting to connect to resources associated
805
with your Windows Azure subscription.
807
thumbprint: The thumbprint value of the certificate.
809
_validate_not_none('thumbprint', thumbprint)
810
return self._perform_get(
811
'/' + self.subscription_id + '/certificates/' + _str(thumbprint),
812
SubscriptionCertificate)
814
def add_management_certificate(self, public_key, thumbprint, data):
816
The Add Management Certificate operation adds a certificate to the
817
list of management certificates. Management certificates, which are
818
also known as subscription certificates, authenticate clients
819
attempting to connect to resources associated with your Windows Azure
823
A base64 representation of the management certificate public key.
825
The thumb print that uniquely identifies the management
827
data: The certificate's raw data in base-64 encoded .cer format.
829
_validate_not_none('public_key', public_key)
830
_validate_not_none('thumbprint', thumbprint)
831
_validate_not_none('data', data)
832
return self._perform_post(
833
'/' + self.subscription_id + '/certificates',
834
_XmlSerializer.subscription_certificate_to_xml(
835
public_key, thumbprint, data))
837
def delete_management_certificate(self, thumbprint):
839
The Delete Management Certificate operation deletes a certificate from
840
the list of management certificates. Management certificates, which
841
are also known as subscription certificates, authenticate clients
842
attempting to connect to resources associated with your Windows Azure
846
The thumb print that uniquely identifies the management
849
_validate_not_none('thumbprint', thumbprint)
850
return self._perform_delete(
851
'/' + self.subscription_id + '/certificates/' + _str(thumbprint))
853
#--Operations for affinity groups ------------------------------------
854
def list_affinity_groups(self):
856
Lists the affinity groups associated with the specified subscription.
858
return self._perform_get(
859
'/' + self.subscription_id + '/affinitygroups',
862
def get_affinity_group_properties(self, affinity_group_name):
864
Returns the system properties associated with the specified affinity
867
affinity_group_name: The name of the affinity group.
869
_validate_not_none('affinity_group_name', affinity_group_name)
870
return self._perform_get(
871
'/' + self.subscription_id + '/affinitygroups/' +
872
_str(affinity_group_name) + '',
875
def create_affinity_group(self, name, label, location, description=None):
877
Creates a new affinity group for the specified subscription.
879
name: A name for the affinity group that is unique to the subscription.
881
A name for the affinity group. The name can be up to 100 characters
884
The data center location where the affinity group will be created.
885
To list available locations, use the list_location function.
887
A description for the affinity group. The description can be up to
888
1024 characters in length.
890
_validate_not_none('name', name)
891
_validate_not_none('label', label)
892
_validate_not_none('location', location)
893
return self._perform_post(
894
'/' + self.subscription_id + '/affinitygroups',
895
_XmlSerializer.create_affinity_group_to_xml(name,
900
def update_affinity_group(self, affinity_group_name, label,
903
Updates the label and/or the description for an affinity group for the
904
specified subscription.
906
affinity_group_name: The name of the affinity group.
908
A name for the affinity group. The name can be up to 100 characters
911
A description for the affinity group. The description can be up to
912
1024 characters in length.
914
_validate_not_none('affinity_group_name', affinity_group_name)
915
_validate_not_none('label', label)
916
return self._perform_put(
917
'/' + self.subscription_id + '/affinitygroups/' +
918
_str(affinity_group_name),
919
_XmlSerializer.update_affinity_group_to_xml(label, description))
921
def delete_affinity_group(self, affinity_group_name):
923
Deletes an affinity group in the specified subscription.
925
affinity_group_name: The name of the affinity group.
927
_validate_not_none('affinity_group_name', affinity_group_name)
928
return self._perform_delete('/' + self.subscription_id + \
929
'/affinitygroups/' + \
930
_str(affinity_group_name))
932
#--Operations for locations ------------------------------------------
933
def list_locations(self):
935
Lists all of the data center locations that are valid for your
938
return self._perform_get('/' + self.subscription_id + '/locations',
941
#--Operations for tracking asynchronous requests ---------------------
942
def get_operation_status(self, request_id):
944
Returns the status of the specified operation. After calling an
945
asynchronous operation, you can call Get Operation Status to determine
946
whether the operation has succeeded, failed, or is still in progress.
948
request_id: The request ID for the request you wish to track.
950
_validate_not_none('request_id', request_id)
951
return self._perform_get(
952
'/' + self.subscription_id + '/operations/' + _str(request_id),
955
#--Operations for retrieving operating system information ------------
956
def list_operating_systems(self):
958
Lists the versions of the guest operating system that are currently
959
available in Windows Azure.
961
return self._perform_get(
962
'/' + self.subscription_id + '/operatingsystems',
965
def list_operating_system_families(self):
967
Lists the guest operating system families available in Windows Azure,
968
and also lists the operating system versions available for each family.
970
return self._perform_get(
971
'/' + self.subscription_id + '/operatingsystemfamilies',
972
OperatingSystemFamilies)
974
#--Operations for retrieving subscription history --------------------
975
def get_subscription(self):
977
Returns account and resource allocation information on the specified
980
return self._perform_get('/' + self.subscription_id + '',
983
#--Operations for virtual machines -----------------------------------
984
def get_role(self, service_name, deployment_name, role_name):
986
Retrieves the specified virtual machine.
988
service_name: The name of the service.
989
deployment_name: The name of the deployment.
990
role_name: The name of the role.
992
_validate_not_none('service_name', service_name)
993
_validate_not_none('deployment_name', deployment_name)
994
_validate_not_none('role_name', role_name)
995
return self._perform_get(
996
self._get_role_path(service_name, deployment_name, role_name),
999
def create_virtual_machine_deployment(self, service_name, deployment_name,
1000
deployment_slot, label, role_name,
1001
system_config, os_virtual_hard_disk,
1002
network_config=None,
1003
availability_set_name=None,
1004
data_virtual_hard_disks=None,
1006
role_type='PersistentVMRole',
1007
virtual_network_name=None):
1009
Provisions a virtual machine based on the supplied configuration.
1011
service_name: Name of the hosted service.
1013
The name for the deployment. The deployment name must be unique
1014
among other deployments for the hosted service.
1016
The environment to which the hosted service is deployed. Valid
1017
values are: staging, production
1019
Specifies an identifier for the deployment. The label can be up to
1020
100 characters long. The label can be used for tracking purposes.
1021
role_name: The name of the role.
1023
Contains the metadata required to provision a virtual machine from
1024
a Windows or Linux OS image. Use an instance of
1025
WindowsConfigurationSet or LinuxConfigurationSet.
1026
os_virtual_hard_disk:
1027
Contains the parameters Windows Azure uses to create the operating
1028
system disk for the virtual machine.
1030
Encapsulates the metadata required to create the virtual network
1031
configuration for a virtual machine. If you do not include a
1032
network configuration set you will not be able to access the VM
1033
through VIPs over the internet. If your virtual machine belongs to
1034
a virtual network you can not specify which subnet address space
1036
availability_set_name:
1037
Specifies the name of an availability set to which to add the
1038
virtual machine. This value controls the virtual machine
1039
allocation in the Windows Azure environment. Virtual machines
1040
specified in the same availability set are allocated to different
1041
nodes to maximize availability.
1042
data_virtual_hard_disks:
1043
Contains the parameters Windows Azure uses to create a data disk
1044
for a virtual machine.
1046
The size of the virtual machine to allocate. The default value is
1047
Small. Possible values are: ExtraSmall, Small, Medium, Large,
1048
ExtraLarge. The specified value must be compatible with the disk
1049
selected in the OSVirtualHardDisk values.
1051
The type of the role for the virtual machine. The only supported
1052
value is PersistentVMRole.
1053
virtual_network_name:
1054
Specifies the name of an existing virtual network to which the
1055
deployment will belong.
1057
_validate_not_none('service_name', service_name)
1058
_validate_not_none('deployment_name', deployment_name)
1059
_validate_not_none('deployment_slot', deployment_slot)
1060
_validate_not_none('label', label)
1061
_validate_not_none('role_name', role_name)
1062
_validate_not_none('system_config', system_config)
1063
_validate_not_none('os_virtual_hard_disk', os_virtual_hard_disk)
1064
return self._perform_post(
1065
self._get_deployment_path_using_name(service_name),
1066
_XmlSerializer.virtual_machine_deployment_to_xml(
1072
os_virtual_hard_disk,
1075
availability_set_name,
1076
data_virtual_hard_disks,
1078
virtual_network_name),
1081
def add_role(self, service_name, deployment_name, role_name, system_config,
1082
os_virtual_hard_disk, network_config=None,
1083
availability_set_name=None, data_virtual_hard_disks=None,
1084
role_size=None, role_type='PersistentVMRole'):
1086
Adds a virtual machine to an existing deployment.
1088
service_name: The name of the service.
1089
deployment_name: The name of the deployment.
1090
role_name: The name of the role.
1092
Contains the metadata required to provision a virtual machine from
1093
a Windows or Linux OS image. Use an instance of
1094
WindowsConfigurationSet or LinuxConfigurationSet.
1095
os_virtual_hard_disk:
1096
Contains the parameters Windows Azure uses to create the operating
1097
system disk for the virtual machine.
1099
Encapsulates the metadata required to create the virtual network
1100
configuration for a virtual machine. If you do not include a
1101
network configuration set you will not be able to access the VM
1102
through VIPs over the internet. If your virtual machine belongs to
1103
a virtual network you can not specify which subnet address space
1105
availability_set_name:
1106
Specifies the name of an availability set to which to add the
1107
virtual machine. This value controls the virtual machine allocation
1108
in the Windows Azure environment. Virtual machines specified in the
1109
same availability set are allocated to different nodes to maximize
1111
data_virtual_hard_disks:
1112
Contains the parameters Windows Azure uses to create a data disk
1113
for a virtual machine.
1115
The size of the virtual machine to allocate. The default value is
1116
Small. Possible values are: ExtraSmall, Small, Medium, Large,
1117
ExtraLarge. The specified value must be compatible with the disk
1118
selected in the OSVirtualHardDisk values.
1120
The type of the role for the virtual machine. The only supported
1121
value is PersistentVMRole.
1123
_validate_not_none('service_name', service_name)
1124
_validate_not_none('deployment_name', deployment_name)
1125
_validate_not_none('role_name', role_name)
1126
_validate_not_none('system_config', system_config)
1127
_validate_not_none('os_virtual_hard_disk', os_virtual_hard_disk)
1128
return self._perform_post(
1129
self._get_role_path(service_name, deployment_name),
1130
_XmlSerializer.add_role_to_xml(
1133
os_virtual_hard_disk,
1136
availability_set_name,
1137
data_virtual_hard_disks,
1141
def update_role(self, service_name, deployment_name, role_name,
1142
os_virtual_hard_disk=None, network_config=None,
1143
availability_set_name=None, data_virtual_hard_disks=None,
1144
role_size=None, role_type='PersistentVMRole'):
1146
Updates the specified virtual machine.
1148
service_name: The name of the service.
1149
deployment_name: The name of the deployment.
1150
role_name: The name of the role.
1151
os_virtual_hard_disk:
1152
Contains the parameters Windows Azure uses to create the operating
1153
system disk for the virtual machine.
1155
Encapsulates the metadata required to create the virtual network
1156
configuration for a virtual machine. If you do not include a
1157
network configuration set you will not be able to access the VM
1158
through VIPs over the internet. If your virtual machine belongs to
1159
a virtual network you can not specify which subnet address space
1161
availability_set_name:
1162
Specifies the name of an availability set to which to add the
1163
virtual machine. This value controls the virtual machine allocation
1164
in the Windows Azure environment. Virtual machines specified in the
1165
same availability set are allocated to different nodes to maximize
1167
data_virtual_hard_disks:
1168
Contains the parameters Windows Azure uses to create a data disk
1169
for a virtual machine.
1171
The size of the virtual machine to allocate. The default value is
1172
Small. Possible values are: ExtraSmall, Small, Medium, Large,
1173
ExtraLarge. The specified value must be compatible with the disk
1174
selected in the OSVirtualHardDisk values.
1176
The type of the role for the virtual machine. The only supported
1177
value is PersistentVMRole.
1179
_validate_not_none('service_name', service_name)
1180
_validate_not_none('deployment_name', deployment_name)
1181
_validate_not_none('role_name', role_name)
1182
return self._perform_put(
1183
self._get_role_path(service_name, deployment_name, role_name),
1184
_XmlSerializer.update_role_to_xml(
1186
os_virtual_hard_disk,
1189
availability_set_name,
1190
data_virtual_hard_disks,
1194
def delete_role(self, service_name, deployment_name, role_name):
1196
Deletes the specified virtual machine.
1198
service_name: The name of the service.
1199
deployment_name: The name of the deployment.
1200
role_name: The name of the role.
1202
_validate_not_none('service_name', service_name)
1203
_validate_not_none('deployment_name', deployment_name)
1204
_validate_not_none('role_name', role_name)
1205
return self._perform_delete(
1206
self._get_role_path(service_name, deployment_name, role_name),
1209
def capture_role(self, service_name, deployment_name, role_name,
1210
post_capture_action, target_image_name,
1211
target_image_label, provisioning_configuration=None):
1213
The Capture Role operation captures a virtual machine image to your
1214
image gallery. From the captured image, you can create additional
1215
customized virtual machines.
1217
service_name: The name of the service.
1218
deployment_name: The name of the deployment.
1219
role_name: The name of the role.
1220
post_capture_action:
1221
Specifies the action after capture operation completes. Possible
1222
values are: Delete, Reprovision.
1224
Specifies the image name of the captured virtual machine.
1226
Specifies the friendly name of the captured virtual machine.
1227
provisioning_configuration:
1228
Use an instance of WindowsConfigurationSet or LinuxConfigurationSet.
1230
_validate_not_none('service_name', service_name)
1231
_validate_not_none('deployment_name', deployment_name)
1232
_validate_not_none('role_name', role_name)
1233
_validate_not_none('post_capture_action', post_capture_action)
1234
_validate_not_none('target_image_name', target_image_name)
1235
_validate_not_none('target_image_label', target_image_label)
1236
return self._perform_post(
1237
self._get_role_instance_operations_path(
1238
service_name, deployment_name, role_name),
1239
_XmlSerializer.capture_role_to_xml(
1240
post_capture_action,
1243
provisioning_configuration),
1246
def start_role(self, service_name, deployment_name, role_name):
1248
Starts the specified virtual machine.
1250
service_name: The name of the service.
1251
deployment_name: The name of the deployment.
1252
role_name: The name of the role.
1254
_validate_not_none('service_name', service_name)
1255
_validate_not_none('deployment_name', deployment_name)
1256
_validate_not_none('role_name', role_name)
1257
return self._perform_post(
1258
self._get_role_instance_operations_path(
1259
service_name, deployment_name, role_name),
1260
_XmlSerializer.start_role_operation_to_xml(),
1263
def start_roles(self, service_name, deployment_name, role_names):
1265
Starts the specified virtual machines.
1267
service_name: The name of the service.
1268
deployment_name: The name of the deployment.
1269
role_names: The names of the roles, as an enumerable of strings.
1271
_validate_not_none('service_name', service_name)
1272
_validate_not_none('deployment_name', deployment_name)
1273
_validate_not_none('role_names', role_names)
1274
return self._perform_post(
1275
self._get_roles_operations_path(service_name, deployment_name),
1276
_XmlSerializer.start_roles_operation_to_xml(role_names),
1279
def restart_role(self, service_name, deployment_name, role_name):
1281
Restarts the specified virtual machine.
1283
service_name: The name of the service.
1284
deployment_name: The name of the deployment.
1285
role_name: The name of the role.
1287
_validate_not_none('service_name', service_name)
1288
_validate_not_none('deployment_name', deployment_name)
1289
_validate_not_none('role_name', role_name)
1290
return self._perform_post(
1291
self._get_role_instance_operations_path(
1292
service_name, deployment_name, role_name),
1293
_XmlSerializer.restart_role_operation_to_xml(
1297
def shutdown_role(self, service_name, deployment_name, role_name,
1298
post_shutdown_action='Stopped'):
1300
Shuts down the specified virtual machine.
1302
service_name: The name of the service.
1303
deployment_name: The name of the deployment.
1304
role_name: The name of the role.
1305
post_shutdown_action:
1306
Specifies how the Virtual Machine should be shut down. Values are:
1308
Shuts down the Virtual Machine but retains the compute
1309
resources. You will continue to be billed for the resources
1310
that the stopped machine uses.
1312
Shuts down the Virtual Machine and releases the compute
1313
resources. You are not billed for the compute resources that
1314
this Virtual Machine uses. If a static Virtual Network IP
1315
address is assigned to the Virtual Machine, it is reserved.
1317
_validate_not_none('service_name', service_name)
1318
_validate_not_none('deployment_name', deployment_name)
1319
_validate_not_none('role_name', role_name)
1320
_validate_not_none('post_shutdown_action', post_shutdown_action)
1321
return self._perform_post(
1322
self._get_role_instance_operations_path(
1323
service_name, deployment_name, role_name),
1324
_XmlSerializer.shutdown_role_operation_to_xml(post_shutdown_action),
1327
def shutdown_roles(self, service_name, deployment_name, role_names,
1328
post_shutdown_action='Stopped'):
1330
Shuts down the specified virtual machines.
1332
service_name: The name of the service.
1333
deployment_name: The name of the deployment.
1334
role_names: The names of the roles, as an enumerable of strings.
1335
post_shutdown_action:
1336
Specifies how the Virtual Machine should be shut down. Values are:
1338
Shuts down the Virtual Machine but retains the compute
1339
resources. You will continue to be billed for the resources
1340
that the stopped machine uses.
1342
Shuts down the Virtual Machine and releases the compute
1343
resources. You are not billed for the compute resources that
1344
this Virtual Machine uses. If a static Virtual Network IP
1345
address is assigned to the Virtual Machine, it is reserved.
1347
_validate_not_none('service_name', service_name)
1348
_validate_not_none('deployment_name', deployment_name)
1349
_validate_not_none('role_names', role_names)
1350
_validate_not_none('post_shutdown_action', post_shutdown_action)
1351
return self._perform_post(
1352
self._get_roles_operations_path(service_name, deployment_name),
1353
_XmlSerializer.shutdown_roles_operation_to_xml(
1354
role_names, post_shutdown_action),
1357
#--Operations for virtual machine images -----------------------------
1358
def list_os_images(self):
1360
Retrieves a list of the OS images from the image repository.
1362
return self._perform_get(self._get_image_path(),
1365
def get_os_image(self, image_name):
1367
Retrieves an OS image from the image repository.
1369
return self._perform_get(self._get_image_path(image_name),
1372
def add_os_image(self, label, media_link, name, os):
1374
Adds an OS image that is currently stored in a storage account in your
1375
subscription to the image repository.
1377
label: Specifies the friendly name of the image.
1379
Specifies the location of the blob in Windows Azure blob store
1380
where the media for the image is located. The blob location must
1381
belong to a storage account in the subscription specified by the
1382
<subscription-id> value in the operation call. Example:
1383
http://example.blob.core.windows.net/disks/mydisk.vhd
1385
Specifies a name for the OS image that Windows Azure uses to
1386
identify the image when creating one or more virtual machines.
1388
The operating system type of the OS image. Possible values are:
1391
_validate_not_none('label', label)
1392
_validate_not_none('media_link', media_link)
1393
_validate_not_none('name', name)
1394
_validate_not_none('os', os)
1395
return self._perform_post(self._get_image_path(),
1396
_XmlSerializer.os_image_to_xml(
1397
label, media_link, name, os),
1400
def update_os_image(self, image_name, label, media_link, name, os):
1402
Updates an OS image that in your image repository.
1404
image_name: The name of the image to update.
1406
Specifies the friendly name of the image to be updated. You cannot
1407
use this operation to update images provided by the Windows Azure
1410
Specifies the location of the blob in Windows Azure blob store
1411
where the media for the image is located. The blob location must
1412
belong to a storage account in the subscription specified by the
1413
<subscription-id> value in the operation call. Example:
1414
http://example.blob.core.windows.net/disks/mydisk.vhd
1416
Specifies a name for the OS image that Windows Azure uses to
1417
identify the image when creating one or more VM Roles.
1419
The operating system type of the OS image. Possible values are:
1422
_validate_not_none('image_name', image_name)
1423
_validate_not_none('label', label)
1424
_validate_not_none('media_link', media_link)
1425
_validate_not_none('name', name)
1426
_validate_not_none('os', os)
1427
return self._perform_put(self._get_image_path(image_name),
1428
_XmlSerializer.os_image_to_xml(
1429
label, media_link, name, os),
1432
def delete_os_image(self, image_name, delete_vhd=False):
1434
Deletes the specified OS image from your image repository.
1436
image_name: The name of the image.
1437
delete_vhd: Deletes the underlying vhd blob in Azure storage.
1439
_validate_not_none('image_name', image_name)
1440
path = self._get_image_path(image_name)
1442
path += '?comp=media'
1443
return self._perform_delete(path, async=True)
1445
#--Operations for virtual machine disks ------------------------------
1446
def get_data_disk(self, service_name, deployment_name, role_name, lun):
1448
Retrieves the specified data disk from a virtual machine.
1450
service_name: The name of the service.
1451
deployment_name: The name of the deployment.
1452
role_name: The name of the role.
1453
lun: The Logical Unit Number (LUN) for the disk.
1455
_validate_not_none('service_name', service_name)
1456
_validate_not_none('deployment_name', deployment_name)
1457
_validate_not_none('role_name', role_name)
1458
_validate_not_none('lun', lun)
1459
return self._perform_get(
1460
self._get_data_disk_path(
1461
service_name, deployment_name, role_name, lun),
1462
DataVirtualHardDisk)
1464
def add_data_disk(self, service_name, deployment_name, role_name, lun,
1465
host_caching=None, media_link=None, disk_label=None,
1466
disk_name=None, logical_disk_size_in_gb=None,
1467
source_media_link=None):
1469
Adds a data disk to a virtual machine.
1471
service_name: The name of the service.
1472
deployment_name: The name of the deployment.
1473
role_name: The name of the role.
1475
Specifies the Logical Unit Number (LUN) for the disk. The LUN
1476
specifies the slot in which the data drive appears when mounted
1477
for usage by the virtual machine. Valid LUN values are 0 through 15.
1479
Specifies the platform caching behavior of data disk blob for
1480
read/write efficiency. The default vault is ReadOnly. Possible
1481
values are: None, ReadOnly, ReadWrite
1483
Specifies the location of the blob in Windows Azure blob store
1484
where the media for the disk is located. The blob location must
1485
belong to the storage account in the subscription specified by the
1486
<subscription-id> value in the operation call. Example:
1487
http://example.blob.core.windows.net/disks/mydisk.vhd
1489
Specifies the description of the data disk. When you attach a disk,
1490
either by directly referencing a media using the MediaLink element
1491
or specifying the target disk size, you can use the DiskLabel
1492
element to customize the name property of the target data disk.
1494
Specifies the name of the disk. Windows Azure uses the specified
1495
disk to create the data disk for the machine and populates this
1496
field with the disk name.
1497
logical_disk_size_in_gb:
1498
Specifies the size, in GB, of an empty disk to be attached to the
1499
role. The disk can be created as part of disk attach or create VM
1500
role call by specifying the value for this property. Windows Azure
1501
creates the empty disk based on size preference and attaches the
1502
newly created disk to the Role.
1504
Specifies the location of a blob in account storage which is
1505
mounted as a data disk when the virtual machine is created.
1507
_validate_not_none('service_name', service_name)
1508
_validate_not_none('deployment_name', deployment_name)
1509
_validate_not_none('role_name', role_name)
1510
_validate_not_none('lun', lun)
1511
return self._perform_post(
1512
self._get_data_disk_path(service_name, deployment_name, role_name),
1513
_XmlSerializer.data_virtual_hard_disk_to_xml(
1518
logical_disk_size_in_gb,
1523
def update_data_disk(self, service_name, deployment_name, role_name, lun,
1524
host_caching=None, media_link=None, updated_lun=None,
1525
disk_label=None, disk_name=None,
1526
logical_disk_size_in_gb=None):
1528
Updates the specified data disk attached to the specified virtual
1531
service_name: The name of the service.
1532
deployment_name: The name of the deployment.
1533
role_name: The name of the role.
1535
Specifies the Logical Unit Number (LUN) for the disk. The LUN
1536
specifies the slot in which the data drive appears when mounted
1537
for usage by the virtual machine. Valid LUN values are 0 through
1540
Specifies the platform caching behavior of data disk blob for
1541
read/write efficiency. The default vault is ReadOnly. Possible
1542
values are: None, ReadOnly, ReadWrite
1544
Specifies the location of the blob in Windows Azure blob store
1545
where the media for the disk is located. The blob location must
1546
belong to the storage account in the subscription specified by
1547
the <subscription-id> value in the operation call. Example:
1548
http://example.blob.core.windows.net/disks/mydisk.vhd
1550
Specifies the Logical Unit Number (LUN) for the disk. The LUN
1551
specifies the slot in which the data drive appears when mounted
1552
for usage by the virtual machine. Valid LUN values are 0 through 15.
1554
Specifies the description of the data disk. When you attach a disk,
1555
either by directly referencing a media using the MediaLink element
1556
or specifying the target disk size, you can use the DiskLabel
1557
element to customize the name property of the target data disk.
1559
Specifies the name of the disk. Windows Azure uses the specified
1560
disk to create the data disk for the machine and populates this
1561
field with the disk name.
1562
logical_disk_size_in_gb:
1563
Specifies the size, in GB, of an empty disk to be attached to the
1564
role. The disk can be created as part of disk attach or create VM
1565
role call by specifying the value for this property. Windows Azure
1566
creates the empty disk based on size preference and attaches the
1567
newly created disk to the Role.
1569
_validate_not_none('service_name', service_name)
1570
_validate_not_none('deployment_name', deployment_name)
1571
_validate_not_none('role_name', role_name)
1572
_validate_not_none('lun', lun)
1573
return self._perform_put(
1574
self._get_data_disk_path(
1575
service_name, deployment_name, role_name, lun),
1576
_XmlSerializer.data_virtual_hard_disk_to_xml(
1581
logical_disk_size_in_gb,
1586
def delete_data_disk(self, service_name, deployment_name, role_name, lun, delete_vhd=False):
1588
Removes the specified data disk from a virtual machine.
1590
service_name: The name of the service.
1591
deployment_name: The name of the deployment.
1592
role_name: The name of the role.
1593
lun: The Logical Unit Number (LUN) for the disk.
1594
delete_vhd: Deletes the underlying vhd blob in Azure storage.
1596
_validate_not_none('service_name', service_name)
1597
_validate_not_none('deployment_name', deployment_name)
1598
_validate_not_none('role_name', role_name)
1599
_validate_not_none('lun', lun)
1600
path = self._get_data_disk_path(service_name, deployment_name, role_name, lun)
1602
path += '?comp=media'
1603
return self._perform_delete(path, async=True)
1605
#--Operations for virtual machine disks ------------------------------
1606
def list_disks(self):
1608
Retrieves a list of the disks in your image repository.
1610
return self._perform_get(self._get_disk_path(),
1613
def get_disk(self, disk_name):
1615
Retrieves a disk from your image repository.
1617
return self._perform_get(self._get_disk_path(disk_name),
1620
def add_disk(self, has_operating_system, label, media_link, name, os):
1622
Adds a disk to the user image repository. The disk can be an OS disk
1625
has_operating_system:
1626
Specifies whether the disk contains an operation system. Only a
1627
disk with an operating system installed can be mounted as OS Drive.
1628
label: Specifies the description of the disk.
1630
Specifies the location of the blob in Windows Azure blob store
1631
where the media for the disk is located. The blob location must
1632
belong to the storage account in the current subscription specified
1633
by the <subscription-id> value in the operation call. Example:
1634
http://example.blob.core.windows.net/disks/mydisk.vhd
1636
Specifies a name for the disk. Windows Azure uses the name to
1637
identify the disk when creating virtual machines from the disk.
1638
os: The OS type of the disk. Possible values are: Linux, Windows
1640
_validate_not_none('has_operating_system', has_operating_system)
1641
_validate_not_none('label', label)
1642
_validate_not_none('media_link', media_link)
1643
_validate_not_none('name', name)
1644
_validate_not_none('os', os)
1645
return self._perform_post(self._get_disk_path(),
1646
_XmlSerializer.disk_to_xml(
1647
has_operating_system,
1653
def update_disk(self, disk_name, has_operating_system, label, media_link,
1656
Updates an existing disk in your image repository.
1658
disk_name: The name of the disk to update.
1659
has_operating_system:
1660
Specifies whether the disk contains an operation system. Only a
1661
disk with an operating system installed can be mounted as OS Drive.
1662
label: Specifies the description of the disk.
1664
Specifies the location of the blob in Windows Azure blob store
1665
where the media for the disk is located. The blob location must
1666
belong to the storage account in the current subscription specified
1667
by the <subscription-id> value in the operation call. Example:
1668
http://example.blob.core.windows.net/disks/mydisk.vhd
1670
Specifies a name for the disk. Windows Azure uses the name to
1671
identify the disk when creating virtual machines from the disk.
1672
os: The OS type of the disk. Possible values are: Linux, Windows
1674
_validate_not_none('disk_name', disk_name)
1675
_validate_not_none('has_operating_system', has_operating_system)
1676
_validate_not_none('label', label)
1677
_validate_not_none('media_link', media_link)
1678
_validate_not_none('name', name)
1679
_validate_not_none('os', os)
1680
return self._perform_put(self._get_disk_path(disk_name),
1681
_XmlSerializer.disk_to_xml(
1682
has_operating_system,
1688
def delete_disk(self, disk_name, delete_vhd=False):
1690
Deletes the specified data or operating system disk from your image
1693
disk_name: The name of the disk to delete.
1694
delete_vhd: Deletes the underlying vhd blob in Azure storage.
1696
_validate_not_none('disk_name', disk_name)
1697
path = self._get_disk_path(disk_name)
1699
path += '?comp=media'
1700
return self._perform_delete(path)
1702
#--Operations for virtual networks ------------------------------
1703
def list_virtual_network_sites(self):
1705
Retrieves a list of the virtual networks.
1707
return self._perform_get(self._get_virtual_network_site_path(), VirtualNetworkSites)
1709
#--Helper functions --------------------------------------------------
1710
def _get_virtual_network_site_path(self):
1711
return self._get_path('services/networking/virtualnetwork', None)
1713
def _get_storage_service_path(self, service_name=None):
1714
return self._get_path('services/storageservices', service_name)
1716
def _get_hosted_service_path(self, service_name=None):
1717
return self._get_path('services/hostedservices', service_name)
1719
def _get_deployment_path_using_slot(self, service_name, slot=None):
1720
return self._get_path('services/hostedservices/' + _str(service_name) +
1721
'/deploymentslots', slot)
1723
def _get_deployment_path_using_name(self, service_name,
1724
deployment_name=None):
1725
return self._get_path('services/hostedservices/' + _str(service_name) +
1726
'/deployments', deployment_name)
1728
def _get_role_path(self, service_name, deployment_name, role_name=None):
1729
return self._get_path('services/hostedservices/' + _str(service_name) +
1730
'/deployments/' + deployment_name +
1731
'/roles', role_name)
1733
def _get_role_instance_operations_path(self, service_name, deployment_name,
1735
return self._get_path('services/hostedservices/' + _str(service_name) +
1736
'/deployments/' + deployment_name +
1737
'/roleinstances', role_name) + '/Operations'
1739
def _get_roles_operations_path(self, service_name, deployment_name):
1740
return self._get_path('services/hostedservices/' + _str(service_name) +
1741
'/deployments/' + deployment_name +
1742
'/roles/Operations', None)
1744
def _get_data_disk_path(self, service_name, deployment_name, role_name,
1746
return self._get_path('services/hostedservices/' + _str(service_name) +
1747
'/deployments/' + _str(deployment_name) +
1748
'/roles/' + _str(role_name) + '/DataDisks', lun)
1750
def _get_disk_path(self, disk_name=None):
1751
return self._get_path('services/disks', disk_name)
1753
def _get_image_path(self, image_name=None):
1754
return self._get_path('services/images', image_name)