~dooferlad/juju-ci-tools/juju-ci-tools-addressable-containers

« back to all changes in this revision

Viewing changes to azure-sdk-for-python-master/azure/servicemanagement/servicemanagementservice.py

  • Committer: Martin Packman
  • Date: 2015-07-01 17:17:25 UTC
  • mto: (997.1.8 trunk)
  • mto: This revision was merged to the branch mainline in revision 1004.
  • Revision ID: martin.packman@canonical.com-20150701171725-2haym60lsgvxldxg
Remove local copy of azure tools

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#-------------------------------------------------------------------------
2
 
# Copyright (c) Microsoft.  All rights reserved.
3
 
#
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
8
 
#
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
 
#--------------------------------------------------------------------------
15
 
from azure import (
16
 
    WindowsAzureError,
17
 
    MANAGEMENT_HOST,
18
 
    _str,
19
 
    _validate_not_none,
20
 
    )
21
 
from azure.servicemanagement import (
22
 
    AffinityGroups,
23
 
    AffinityGroup,
24
 
    AvailabilityResponse,
25
 
    Certificate,
26
 
    Certificates,
27
 
    DataVirtualHardDisk,
28
 
    Deployment,
29
 
    Disk,
30
 
    Disks,
31
 
    Locations,
32
 
    Operation,
33
 
    HostedService,
34
 
    HostedServices,
35
 
    Images,
36
 
    OperatingSystems,
37
 
    OperatingSystemFamilies,
38
 
    OSImage,
39
 
    PersistentVMRole,
40
 
    StorageService,
41
 
    StorageServices,
42
 
    Subscription,
43
 
    SubscriptionCertificate,
44
 
    SubscriptionCertificates,
45
 
    VirtualNetworkSites,
46
 
    _XmlSerializer,
47
 
    )
48
 
from azure.servicemanagement.servicemanagementclient import (
49
 
    _ServiceManagementClient,
50
 
    )
51
 
 
52
 
class ServiceManagementService(_ServiceManagementClient):
53
 
 
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)
58
 
 
59
 
    #--Operations for storage accounts -----------------------------------
60
 
    def list_storage_accounts(self):
61
 
        '''
62
 
        Lists the storage accounts available under the current subscription.
63
 
        '''
64
 
        return self._perform_get(self._get_storage_service_path(),
65
 
                                 StorageServices)
66
 
 
67
 
    def get_storage_account_properties(self, service_name):
68
 
        '''
69
 
        Returns system properties for the specified storage account.
70
 
 
71
 
        service_name: Name of the storage service account.
72
 
        '''
73
 
        _validate_not_none('service_name', service_name)
74
 
        return self._perform_get(self._get_storage_service_path(service_name),
75
 
                                 StorageService)
76
 
 
77
 
    def get_storage_account_keys(self, service_name):
78
 
        '''
79
 
        Returns the primary and secondary access keys for the specified
80
 
        storage account.
81
 
 
82
 
        service_name: Name of the storage service account.
83
 
        '''
84
 
        _validate_not_none('service_name', service_name)
85
 
        return self._perform_get(
86
 
            self._get_storage_service_path(service_name) + '/keys',
87
 
            StorageService)
88
 
 
89
 
    def regenerate_storage_account_keys(self, service_name, key_type):
90
 
        '''
91
 
        Regenerates the primary or secondary access key for the specified
92
 
        storage account.
93
 
 
94
 
        service_name: Name of the storage service account.
95
 
        key_type:
96
 
            Specifies which key to regenerate. Valid values are:
97
 
            Primary, Secondary
98
 
        '''
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(
105
 
                key_type),
106
 
            StorageService)
107
 
 
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):
112
 
        '''
113
 
        Creates a new storage account in Windows Azure.
114
 
 
115
 
        service_name:
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.
119
 
        description:
120
 
            A description for the storage account. The description may be up
121
 
            to 1024 characters in length.
122
 
        label:
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.
126
 
        affinity_group:
127
 
            The name of an existing affinity group in the specified
128
 
            subscription. You can specify either a location or affinity_group,
129
 
            but not both.
130
 
        location:
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.
140
 
        extended_properties:
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.
147
 
        '''
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(
160
 
                service_name,
161
 
                description,
162
 
                label,
163
 
                affinity_group,
164
 
                location,
165
 
                geo_replication_enabled,
166
 
                extended_properties),
167
 
            async=True)
168
 
 
169
 
    def update_storage_account(self, service_name, description=None,
170
 
                               label=None, geo_replication_enabled=None,
171
 
                               extended_properties=None):
172
 
        '''
173
 
        Updates the label, the description, and enables or disables the
174
 
        geo-replication status for a storage account in Windows Azure.
175
 
 
176
 
        service_name: Name of the storage service account.
177
 
        description:
178
 
            A description for the storage account. The description may be up
179
 
            to 1024 characters in length.
180
 
        label:
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.
191
 
        extended_properties:
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.
198
 
        '''
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(
203
 
                description,
204
 
                label,
205
 
                geo_replication_enabled,
206
 
                extended_properties))
207
 
 
208
 
    def delete_storage_account(self, service_name):
209
 
        '''
210
 
        Deletes the specified storage account from Windows Azure.
211
 
 
212
 
        service_name: Name of the storage service account.
213
 
        '''
214
 
        _validate_not_none('service_name', service_name)
215
 
        return self._perform_delete(
216
 
            self._get_storage_service_path(service_name))
217
 
 
218
 
    def check_storage_account_name_availability(self, service_name):
219
 
        '''
220
 
        Checks to see if the specified storage account name is available, or
221
 
        if it has already been taken.
222
 
 
223
 
        service_name: Name of the storage service account.
224
 
        '''
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)
231
 
 
232
 
    #--Operations for hosted services ------------------------------------
233
 
    def list_hosted_services(self):
234
 
        '''
235
 
        Lists the hosted services available under the current subscription.
236
 
        '''
237
 
        return self._perform_get(self._get_hosted_service_path(),
238
 
                                 HostedServices)
239
 
 
240
 
    def get_hosted_service_properties(self, service_name, embed_detail=False):
241
 
        '''
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.
247
 
 
248
 
        service_name: Name of the hosted service.
249
 
        embed_detail:
250
 
            When True, the management service returns properties for all
251
 
            deployments of the service, as well as for the service itself.
252
 
        '''
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) +
257
 
            '?embed-detail=' +
258
 
            _str(embed_detail).lower(),
259
 
            HostedService)
260
 
 
261
 
    def create_hosted_service(self, service_name, label, description=None,
262
 
                              location=None, affinity_group=None,
263
 
                              extended_properties=None):
264
 
        '''
265
 
        Creates a new hosted service in Windows Azure.
266
 
 
267
 
        service_name:
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
270
 
            hosted service.
271
 
        label:
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.
275
 
        description:
276
 
            A description for the hosted service. The description can be up to
277
 
            1024 characters in length.
278
 
        location:
279
 
            The location where the hosted service will be created. You can
280
 
            specify either a location or affinity_group, but not both.
281
 
        affinity_group:
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.
287
 
        extended_properties:
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.
294
 
        '''
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(
305
 
                                      service_name,
306
 
                                      label,
307
 
                                      description,
308
 
                                      location,
309
 
                                      affinity_group,
310
 
                                      extended_properties))
311
 
 
312
 
    def update_hosted_service(self, service_name, label=None, description=None,
313
 
                              extended_properties=None):
314
 
        '''
315
 
        Updates the label and/or the description for a hosted service in
316
 
        Windows Azure.
317
 
 
318
 
        service_name: Name of the hosted service.
319
 
        label:
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.
325
 
        description:
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.
329
 
        extended_properties:
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.
336
 
        '''
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(
340
 
                                     label,
341
 
                                     description,
342
 
                                     extended_properties))
343
 
 
344
 
    def delete_hosted_service(self, service_name):
345
 
        '''
346
 
        Deletes the specified hosted service from Windows Azure.
347
 
 
348
 
        service_name: Name of the hosted service.
349
 
        '''
350
 
        _validate_not_none('service_name', service_name)
351
 
        return self._perform_delete(self._get_hosted_service_path(service_name))
352
 
 
353
 
    def get_deployment_by_slot(self, service_name, deployment_slot):
354
 
        '''
355
 
        Returns configuration information, status, and system properties for
356
 
        a deployment.
357
 
 
358
 
        service_name: Name of the hosted service.
359
 
        deployment_slot:
360
 
            The environment to which the hosted service is deployed. Valid
361
 
            values are: staging, production
362
 
        '''
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),
368
 
            Deployment)
369
 
 
370
 
    def get_deployment_by_name(self, service_name, deployment_name):
371
 
        '''
372
 
        Returns configuration information, status, and system properties for a
373
 
        deployment.
374
 
 
375
 
        service_name: Name of the hosted service.
376
 
        deployment_name: The name of the deployment.
377
 
        '''
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),
383
 
            Deployment)
384
 
 
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):
390
 
        '''
391
 
        Uploads a new service package and creates a new deployment on staging
392
 
        or production.
393
 
 
394
 
        service_name: Name of the hosted service.
395
 
        deployment_slot:
396
 
            The environment to which the hosted service is deployed. Valid
397
 
            values are: staging, production
398
 
        name:
399
 
            The name for the deployment. The deployment name must be unique
400
 
            among other deployments for the hosted service.
401
 
        package_url:
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.
406
 
        label:
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.
411
 
        configuration:
412
 
            The base-64 encoded service configuration file for the deployment.
413
 
        start_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
420
 
            suspended.
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.
425
 
        extended_properties:
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.
432
 
        '''
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(
443
 
                name,
444
 
                package_url,
445
 
                label,
446
 
                configuration,
447
 
                start_deployment,
448
 
                treat_warnings_as_error,
449
 
                extended_properties),
450
 
            async=True)
451
 
 
452
 
    def delete_deployment(self, service_name, deployment_name):
453
 
        '''
454
 
        Deletes the specified deployment.
455
 
 
456
 
        service_name: Name of the hosted service.
457
 
        deployment_name: The name of the deployment.
458
 
        '''
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),
464
 
            async=True)
465
 
 
466
 
    def swap_deployment(self, service_name, production, source_deployment):
467
 
        '''
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.
473
 
 
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.
477
 
        '''
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),
484
 
                                  async=True)
485
 
 
486
 
    def change_deployment_configuration(self, service_name, deployment_name,
487
 
                                        configuration,
488
 
                                        treat_warnings_as_error=False,
489
 
                                        mode='Auto', extended_properties=None):
490
 
        '''
491
 
        Initiates a change to the deployment configuration.
492
 
 
493
 
        service_name: Name of the hosted service.
494
 
        deployment_name: The name of the deployment.
495
 
        configuration:
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.
501
 
        mode:
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
506
 
        extended_properties:
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.
513
 
        '''
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(
521
 
                configuration,
522
 
                treat_warnings_as_error,
523
 
                mode,
524
 
                extended_properties),
525
 
            async=True)
526
 
 
527
 
    def update_deployment_status(self, service_name, deployment_name, status):
528
 
        '''
529
 
        Initiates a change in deployment status.
530
 
 
531
 
        service_name: Name of the hosted service.
532
 
        deployment_name: The name of the deployment.
533
 
        status:
534
 
            The change to initiate to the deployment status. Possible values
535
 
            include: Running, Suspended
536
 
        '''
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(
544
 
                status),
545
 
            async=True)
546
 
 
547
 
    def upgrade_deployment(self, service_name, deployment_name, mode,
548
 
                           package_url, configuration, label, force,
549
 
                           role_to_upgrade=None, extended_properties=None):
550
 
        '''
551
 
        Initiates an upgrade.
552
 
 
553
 
        service_name: Name of the hosted service.
554
 
        deployment_name: The name of the deployment.
555
 
        mode:
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
560
 
        package_url:
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.
565
 
        configuration:
566
 
            The base-64 encoded service configuration file for the deployment.
567
 
        label:
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.
572
 
        force:
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
576
 
            fail.
577
 
        role_to_upgrade: The name of the specific role to upgrade.
578
 
        extended_properties:
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.
585
 
        '''
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(
597
 
                mode,
598
 
                package_url,
599
 
                configuration,
600
 
                label,
601
 
                role_to_upgrade,
602
 
                force,
603
 
                extended_properties),
604
 
            async=True)
605
 
 
606
 
    def walk_upgrade_domain(self, service_name, deployment_name,
607
 
                            upgrade_domain):
608
 
        '''
609
 
        Specifies the next upgrade domain to be walked during manual in-place
610
 
        upgrade or configuration change.
611
 
 
612
 
        service_name: Name of the hosted service.
613
 
        deployment_name: The name of the deployment.
614
 
        upgrade_domain:
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.
618
 
        '''
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(
626
 
                upgrade_domain),
627
 
            async=True)
628
 
 
629
 
    def rollback_update_or_upgrade(self, service_name, deployment_name, mode,
630
 
                                   force):
631
 
        '''
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.
635
 
 
636
 
        service_name: Name of the hosted service.
637
 
        deployment_name: The name of the deployment.
638
 
        mode:
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.
643
 
        force:
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
647
 
            fail.
648
 
        '''
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(
657
 
                mode, force),
658
 
            async=True)
659
 
 
660
 
    def reboot_role_instance(self, service_name, deployment_name,
661
 
                             role_instance_name):
662
 
        '''
663
 
        Requests a reboot of a role instance that is running in a deployment.
664
 
 
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.
668
 
        '''
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) + \
676
 
                    '?comp=reboot',
677
 
            '',
678
 
            async=True)
679
 
 
680
 
    def reimage_role_instance(self, service_name, deployment_name,
681
 
                              role_instance_name):
682
 
        '''
683
 
        Requests a reimage of a role instance that is running in a deployment.
684
 
 
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.
688
 
        '''
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) + \
696
 
                    '?comp=reimage',
697
 
            '',
698
 
            async=True)
699
 
 
700
 
    def check_hosted_service_name_availability(self, service_name):
701
 
        '''
702
 
        Checks to see if the specified hosted service name is available, or if
703
 
        it has already been taken.
704
 
 
705
 
        service_name: Name of the hosted service.
706
 
        '''
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)
713
 
 
714
 
    #--Operations for service certificates -------------------------------
715
 
    def list_service_certificates(self, service_name):
716
 
        '''
717
 
        Lists all of the service certificates associated with the specified
718
 
        hosted service.
719
 
 
720
 
        service_name: Name of the hosted service.
721
 
        '''
722
 
        _validate_not_none('service_name', service_name)
723
 
        return self._perform_get(
724
 
            '/' + self.subscription_id + '/services/hostedservices/' +
725
 
            _str(service_name) + '/certificates',
726
 
            Certificates)
727
 
 
728
 
    def get_service_certificate(self, service_name, thumbalgorithm, thumbprint):
729
 
        '''
730
 
        Returns the public data for the specified X.509 certificate associated
731
 
        with a hosted service.
732
 
 
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.
736
 
        '''
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) + '',
744
 
            Certificate)
745
 
 
746
 
    def add_service_certificate(self, service_name, data, certificate_format,
747
 
                                password):
748
 
        '''
749
 
        Adds a certificate to a hosted service.
750
 
 
751
 
        service_name: Name of the hosted service.
752
 
        data: The base-64 encoded form of the pfx file.
753
 
        certificate_format:
754
 
            The service certificate format. The only supported value is pfx.
755
 
        password: The certificate password.
756
 
        '''
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),
766
 
            async=True)
767
 
 
768
 
    def delete_service_certificate(self, service_name, thumbalgorithm,
769
 
                                   thumbprint):
770
 
        '''
771
 
        Deletes a service certificate from the certificate store of a hosted
772
 
        service.
773
 
 
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.
777
 
        '''
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),
785
 
            async=True)
786
 
 
787
 
    #--Operations for management certificates ----------------------------
788
 
    def list_management_certificates(self):
789
 
        '''
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.
795
 
        '''
796
 
        return self._perform_get('/' + self.subscription_id + '/certificates',
797
 
                                 SubscriptionCertificates)
798
 
 
799
 
    def get_management_certificate(self, thumbprint):
800
 
        '''
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.
806
 
 
807
 
        thumbprint: The thumbprint value of the certificate.
808
 
        '''
809
 
        _validate_not_none('thumbprint', thumbprint)
810
 
        return self._perform_get(
811
 
            '/' + self.subscription_id + '/certificates/' + _str(thumbprint),
812
 
            SubscriptionCertificate)
813
 
 
814
 
    def add_management_certificate(self, public_key, thumbprint, data):
815
 
        '''
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
820
 
        subscription.
821
 
 
822
 
        public_key:
823
 
            A base64 representation of the management certificate public key.
824
 
        thumbprint:
825
 
            The thumb print that uniquely identifies the management
826
 
            certificate.
827
 
        data: The certificate's raw data in base-64 encoded .cer format.
828
 
        '''
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))
836
 
 
837
 
    def delete_management_certificate(self, thumbprint):
838
 
        '''
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
843
 
        subscription.
844
 
 
845
 
        thumbprint:
846
 
            The thumb print that uniquely identifies the management
847
 
            certificate.
848
 
        '''
849
 
        _validate_not_none('thumbprint', thumbprint)
850
 
        return self._perform_delete(
851
 
            '/' + self.subscription_id + '/certificates/' + _str(thumbprint))
852
 
 
853
 
    #--Operations for affinity groups ------------------------------------
854
 
    def list_affinity_groups(self):
855
 
        '''
856
 
        Lists the affinity groups associated with the specified subscription.
857
 
        '''
858
 
        return self._perform_get(
859
 
            '/' + self.subscription_id + '/affinitygroups',
860
 
            AffinityGroups)
861
 
 
862
 
    def get_affinity_group_properties(self, affinity_group_name):
863
 
        '''
864
 
        Returns the system properties associated with the specified affinity
865
 
        group.
866
 
 
867
 
        affinity_group_name: The name of the affinity group.
868
 
        '''
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) + '',
873
 
            AffinityGroup)
874
 
 
875
 
    def create_affinity_group(self, name, label, location, description=None):
876
 
        '''
877
 
        Creates a new affinity group for the specified subscription.
878
 
 
879
 
        name: A name for the affinity group that is unique to the subscription.
880
 
        label:
881
 
            A name for the affinity group. The name can be up to 100 characters
882
 
            in length.
883
 
        location:
884
 
            The data center location where the affinity group will be created.
885
 
            To list available locations, use the list_location function.
886
 
        description:
887
 
            A description for the affinity group. The description can be up to
888
 
            1024 characters in length.
889
 
        '''
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,
896
 
                                                        label,
897
 
                                                        description,
898
 
                                                        location))
899
 
 
900
 
    def update_affinity_group(self, affinity_group_name, label,
901
 
                              description=None):
902
 
        '''
903
 
        Updates the label and/or the description for an affinity group for the
904
 
        specified subscription.
905
 
 
906
 
        affinity_group_name: The name of the affinity group.
907
 
        label:
908
 
            A name for the affinity group. The name can be up to 100 characters
909
 
            in length.
910
 
        description:
911
 
            A description for the affinity group. The description can be up to
912
 
            1024 characters in length.
913
 
        '''
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))
920
 
 
921
 
    def delete_affinity_group(self, affinity_group_name):
922
 
        '''
923
 
        Deletes an affinity group in the specified subscription.
924
 
 
925
 
        affinity_group_name: The name of the affinity group.
926
 
        '''
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))
931
 
 
932
 
    #--Operations for locations ------------------------------------------
933
 
    def list_locations(self):
934
 
        '''
935
 
        Lists all of the data center locations that are valid for your
936
 
        subscription.
937
 
        '''
938
 
        return self._perform_get('/' + self.subscription_id + '/locations',
939
 
                                 Locations)
940
 
 
941
 
    #--Operations for tracking asynchronous requests ---------------------
942
 
    def get_operation_status(self, request_id):
943
 
        '''
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.
947
 
 
948
 
        request_id: The request ID for the request you wish to track.
949
 
        '''
950
 
        _validate_not_none('request_id', request_id)
951
 
        return self._perform_get(
952
 
            '/' + self.subscription_id + '/operations/' + _str(request_id),
953
 
            Operation)
954
 
 
955
 
    #--Operations for retrieving operating system information ------------
956
 
    def list_operating_systems(self):
957
 
        '''
958
 
        Lists the versions of the guest operating system that are currently
959
 
        available in Windows Azure.
960
 
        '''
961
 
        return self._perform_get(
962
 
            '/' + self.subscription_id + '/operatingsystems',
963
 
            OperatingSystems)
964
 
 
965
 
    def list_operating_system_families(self):
966
 
        '''
967
 
        Lists the guest operating system families available in Windows Azure,
968
 
        and also lists the operating system versions available for each family.
969
 
        '''
970
 
        return self._perform_get(
971
 
            '/' + self.subscription_id + '/operatingsystemfamilies',
972
 
            OperatingSystemFamilies)
973
 
 
974
 
    #--Operations for retrieving subscription history --------------------
975
 
    def get_subscription(self):
976
 
        '''
977
 
        Returns account and resource allocation information on the specified
978
 
        subscription.
979
 
        '''
980
 
        return self._perform_get('/' + self.subscription_id + '',
981
 
                                 Subscription)
982
 
 
983
 
    #--Operations for virtual machines -----------------------------------
984
 
    def get_role(self, service_name, deployment_name, role_name):
985
 
        '''
986
 
        Retrieves the specified virtual machine.
987
 
 
988
 
        service_name: The name of the service.
989
 
        deployment_name: The name of the deployment.
990
 
        role_name: The name of the role.
991
 
        '''
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),
997
 
            PersistentVMRole)
998
 
 
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,
1005
 
                                          role_size=None,
1006
 
                                          role_type='PersistentVMRole',
1007
 
                                          virtual_network_name=None):
1008
 
        '''
1009
 
        Provisions a virtual machine based on the supplied configuration.
1010
 
 
1011
 
        service_name: Name of the hosted service.
1012
 
        deployment_name:
1013
 
            The name for the deployment. The deployment name must be unique
1014
 
            among other deployments for the hosted service.
1015
 
        deployment_slot:
1016
 
            The environment to which the hosted service is deployed. Valid
1017
 
            values are: staging, production
1018
 
        label:
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.
1022
 
        system_config:
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.
1029
 
        network_config:
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
1035
 
            it resides under.
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.
1045
 
        role_size:
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.
1050
 
        role_type:
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.
1056
 
        '''
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(
1067
 
                deployment_name,
1068
 
                deployment_slot,
1069
 
                label,
1070
 
                role_name,
1071
 
                system_config,
1072
 
                os_virtual_hard_disk,
1073
 
                role_type,
1074
 
                network_config,
1075
 
                availability_set_name,
1076
 
                data_virtual_hard_disks,
1077
 
                role_size,
1078
 
                virtual_network_name),
1079
 
            async=True)
1080
 
 
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'):
1085
 
        '''
1086
 
        Adds a virtual machine to an existing deployment.
1087
 
 
1088
 
        service_name: The name of the service.
1089
 
        deployment_name: The name of the deployment.
1090
 
        role_name: The name of the role.
1091
 
        system_config:
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.
1098
 
        network_config:
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
1104
 
            it resides under.
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
1110
 
            availability.
1111
 
        data_virtual_hard_disks:
1112
 
            Contains the parameters Windows Azure uses to create a data disk
1113
 
            for a virtual machine.
1114
 
        role_size:
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.
1119
 
        role_type:
1120
 
            The type of the role for the virtual machine. The only supported
1121
 
            value is PersistentVMRole.
1122
 
        '''
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(
1131
 
                role_name,
1132
 
                system_config,
1133
 
                os_virtual_hard_disk,
1134
 
                role_type,
1135
 
                network_config,
1136
 
                availability_set_name,
1137
 
                data_virtual_hard_disks,
1138
 
                role_size),
1139
 
            async=True)
1140
 
 
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'):
1145
 
        '''
1146
 
        Updates the specified virtual machine.
1147
 
 
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.
1154
 
        network_config:
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
1160
 
            it resides under.
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
1166
 
            availability.
1167
 
        data_virtual_hard_disks:
1168
 
            Contains the parameters Windows Azure uses to create a data disk
1169
 
            for a virtual machine.
1170
 
        role_size:
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.
1175
 
        role_type:
1176
 
            The type of the role for the virtual machine. The only supported
1177
 
            value is PersistentVMRole.
1178
 
        '''
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(
1185
 
                role_name,
1186
 
                os_virtual_hard_disk,
1187
 
                role_type,
1188
 
                network_config,
1189
 
                availability_set_name,
1190
 
                data_virtual_hard_disks,
1191
 
                role_size),
1192
 
            async=True)
1193
 
 
1194
 
    def delete_role(self, service_name, deployment_name, role_name):
1195
 
        '''
1196
 
        Deletes the specified virtual machine.
1197
 
 
1198
 
        service_name: The name of the service.
1199
 
        deployment_name: The name of the deployment.
1200
 
        role_name: The name of the role.
1201
 
        '''
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),
1207
 
            async=True)
1208
 
 
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):
1212
 
        '''
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.
1216
 
 
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.
1223
 
        target_image_name:
1224
 
            Specifies the image name of the captured virtual machine.
1225
 
        target_image_label:
1226
 
            Specifies the friendly name of the captured virtual machine.
1227
 
        provisioning_configuration:
1228
 
            Use an instance of WindowsConfigurationSet or LinuxConfigurationSet.
1229
 
        '''
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,
1241
 
                target_image_name,
1242
 
                target_image_label,
1243
 
                provisioning_configuration),
1244
 
            async=True)
1245
 
 
1246
 
    def start_role(self, service_name, deployment_name, role_name):
1247
 
        '''
1248
 
        Starts the specified virtual machine.
1249
 
 
1250
 
        service_name: The name of the service.
1251
 
        deployment_name: The name of the deployment.
1252
 
        role_name: The name of the role.
1253
 
        '''
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(),
1261
 
            async=True)
1262
 
 
1263
 
    def start_roles(self, service_name, deployment_name, role_names):
1264
 
        '''
1265
 
        Starts the specified virtual machines.
1266
 
 
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.
1270
 
        '''
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),
1277
 
            async=True)
1278
 
 
1279
 
    def restart_role(self, service_name, deployment_name, role_name):
1280
 
        '''
1281
 
        Restarts the specified virtual machine.
1282
 
 
1283
 
        service_name: The name of the service.
1284
 
        deployment_name: The name of the deployment.
1285
 
        role_name: The name of the role.
1286
 
        '''
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(
1294
 
            ),
1295
 
            async=True)
1296
 
 
1297
 
    def shutdown_role(self, service_name, deployment_name, role_name,
1298
 
                      post_shutdown_action='Stopped'):
1299
 
        '''
1300
 
        Shuts down the specified virtual machine.
1301
 
 
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:
1307
 
                Stopped
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.
1311
 
                StoppedDeallocated
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.
1316
 
        '''
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),
1325
 
            async=True)
1326
 
 
1327
 
    def shutdown_roles(self, service_name, deployment_name, role_names,
1328
 
                       post_shutdown_action='Stopped'):
1329
 
        '''
1330
 
        Shuts down the specified virtual machines.
1331
 
 
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:
1337
 
                Stopped
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.
1341
 
                StoppedDeallocated
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.
1346
 
        '''
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),
1355
 
            async=True)
1356
 
 
1357
 
    #--Operations for virtual machine images -----------------------------
1358
 
    def list_os_images(self):
1359
 
        '''
1360
 
        Retrieves a list of the OS images from the image repository.
1361
 
        '''
1362
 
        return self._perform_get(self._get_image_path(),
1363
 
                                 Images)
1364
 
 
1365
 
    def get_os_image(self, image_name):
1366
 
        '''
1367
 
        Retrieves an OS image from the image repository.
1368
 
        '''
1369
 
        return self._perform_get(self._get_image_path(image_name),
1370
 
                                 OSImage)
1371
 
 
1372
 
    def add_os_image(self, label, media_link, name, os):
1373
 
        '''
1374
 
        Adds an OS image that is currently stored in a storage account in your
1375
 
        subscription to the image repository.
1376
 
 
1377
 
        label: Specifies the friendly name of the image.
1378
 
        media_link:
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
1384
 
        name:
1385
 
            Specifies a name for the OS image that Windows Azure uses to
1386
 
            identify the image when creating one or more virtual machines.
1387
 
        os:
1388
 
            The operating system type of the OS image. Possible values are:
1389
 
            Linux, Windows
1390
 
        '''
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),
1398
 
                                  async=True)
1399
 
 
1400
 
    def update_os_image(self, image_name, label, media_link, name, os):
1401
 
        '''
1402
 
        Updates an OS image that in your image repository.
1403
 
 
1404
 
        image_name: The name of the image to update.
1405
 
        label:
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
1408
 
            platform.
1409
 
        media_link:
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
1415
 
        name:
1416
 
            Specifies a name for the OS image that Windows Azure uses to
1417
 
            identify the image when creating one or more VM Roles.
1418
 
        os:
1419
 
            The operating system type of the OS image. Possible values are:
1420
 
            Linux, Windows
1421
 
        '''
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),
1430
 
                                 async=True)
1431
 
 
1432
 
    def delete_os_image(self, image_name, delete_vhd=False):
1433
 
        '''
1434
 
        Deletes the specified OS image from your image repository.
1435
 
 
1436
 
        image_name: The name of the image.
1437
 
        delete_vhd: Deletes the underlying vhd blob in Azure storage.
1438
 
        '''
1439
 
        _validate_not_none('image_name', image_name)
1440
 
        path = self._get_image_path(image_name)
1441
 
        if delete_vhd:
1442
 
            path += '?comp=media'
1443
 
        return self._perform_delete(path, async=True)
1444
 
 
1445
 
    #--Operations for virtual machine disks ------------------------------
1446
 
    def get_data_disk(self, service_name, deployment_name, role_name, lun):
1447
 
        '''
1448
 
        Retrieves the specified data disk from a virtual machine.
1449
 
 
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.
1454
 
        '''
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)
1463
 
 
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):
1468
 
        '''
1469
 
        Adds a data disk to a virtual machine.
1470
 
 
1471
 
        service_name: The name of the service.
1472
 
        deployment_name: The name of the deployment.
1473
 
        role_name: The name of the role.
1474
 
        lun:
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.
1478
 
        host_caching:
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
1482
 
        media_link:
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
1488
 
        disk_label:
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.
1493
 
        disk_name:
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.
1503
 
        source_media_link:
1504
 
            Specifies the location of a blob in account storage which is
1505
 
            mounted as a data disk when the virtual machine is created.
1506
 
        '''
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(
1514
 
                host_caching,
1515
 
                disk_label,
1516
 
                disk_name,
1517
 
                lun,
1518
 
                logical_disk_size_in_gb,
1519
 
                media_link,
1520
 
                source_media_link),
1521
 
            async=True)
1522
 
 
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):
1527
 
        '''
1528
 
        Updates the specified data disk attached to the specified virtual
1529
 
        machine.
1530
 
 
1531
 
        service_name: The name of the service.
1532
 
        deployment_name: The name of the deployment.
1533
 
        role_name: The name of the role.
1534
 
        lun:
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
1538
 
            15.
1539
 
        host_caching:
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
1543
 
        media_link:
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
1549
 
        updated_lun:
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.
1553
 
        disk_label:
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.
1558
 
        disk_name:
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.
1568
 
        '''
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(
1577
 
                host_caching,
1578
 
                disk_label,
1579
 
                disk_name,
1580
 
                updated_lun,
1581
 
                logical_disk_size_in_gb,
1582
 
                media_link,
1583
 
                None),
1584
 
            async=True)
1585
 
 
1586
 
    def delete_data_disk(self, service_name, deployment_name, role_name, lun, delete_vhd=False):
1587
 
        '''
1588
 
        Removes the specified data disk from a virtual machine.
1589
 
 
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.
1595
 
        '''
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)
1601
 
        if delete_vhd:
1602
 
            path += '?comp=media'
1603
 
        return self._perform_delete(path, async=True)
1604
 
 
1605
 
    #--Operations for virtual machine disks ------------------------------
1606
 
    def list_disks(self):
1607
 
        '''
1608
 
        Retrieves a list of the disks in your image repository.
1609
 
        '''
1610
 
        return self._perform_get(self._get_disk_path(),
1611
 
                                 Disks)
1612
 
 
1613
 
    def get_disk(self, disk_name):
1614
 
        '''
1615
 
        Retrieves a disk from your image repository.
1616
 
        '''
1617
 
        return self._perform_get(self._get_disk_path(disk_name),
1618
 
                                 Disk)
1619
 
 
1620
 
    def add_disk(self, has_operating_system, label, media_link, name, os):
1621
 
        '''
1622
 
        Adds a disk to the user image repository. The disk can be an OS disk
1623
 
        or a data disk.
1624
 
 
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.
1629
 
        media_link:
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
1635
 
        name:
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
1639
 
        '''
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,
1648
 
                                      label,
1649
 
                                      media_link,
1650
 
                                      name,
1651
 
                                      os))
1652
 
 
1653
 
    def update_disk(self, disk_name, has_operating_system, label, media_link,
1654
 
                    name, os):
1655
 
        '''
1656
 
        Updates an existing disk in your image repository.
1657
 
 
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.
1663
 
        media_link:
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
1669
 
        name:
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
1673
 
        '''
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,
1683
 
                                     label,
1684
 
                                     media_link,
1685
 
                                     name,
1686
 
                                     os))
1687
 
 
1688
 
    def delete_disk(self, disk_name, delete_vhd=False):
1689
 
        '''
1690
 
        Deletes the specified data or operating system disk from your image
1691
 
        repository.
1692
 
 
1693
 
        disk_name: The name of the disk to delete.
1694
 
        delete_vhd: Deletes the underlying vhd blob in Azure storage.
1695
 
        '''
1696
 
        _validate_not_none('disk_name', disk_name)
1697
 
        path = self._get_disk_path(disk_name)
1698
 
        if delete_vhd:
1699
 
            path += '?comp=media'
1700
 
        return self._perform_delete(path)
1701
 
 
1702
 
    #--Operations for virtual networks  ------------------------------
1703
 
    def list_virtual_network_sites(self):
1704
 
        '''
1705
 
        Retrieves a list of the virtual networks.
1706
 
        '''
1707
 
        return self._perform_get(self._get_virtual_network_site_path(), VirtualNetworkSites)
1708
 
  
1709
 
      #--Helper functions --------------------------------------------------
1710
 
    def _get_virtual_network_site_path(self):
1711
 
        return self._get_path('services/networking/virtualnetwork', None)
1712
 
 
1713
 
    def _get_storage_service_path(self, service_name=None):
1714
 
        return self._get_path('services/storageservices', service_name)
1715
 
 
1716
 
    def _get_hosted_service_path(self, service_name=None):
1717
 
        return self._get_path('services/hostedservices', service_name)
1718
 
 
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)
1722
 
 
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)
1727
 
 
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)
1732
 
 
1733
 
    def _get_role_instance_operations_path(self, service_name, deployment_name,
1734
 
                                           role_name=None):
1735
 
        return self._get_path('services/hostedservices/' + _str(service_name) +
1736
 
                              '/deployments/' + deployment_name +
1737
 
                              '/roleinstances', role_name) + '/Operations'
1738
 
 
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)
1743
 
 
1744
 
    def _get_data_disk_path(self, service_name, deployment_name, role_name,
1745
 
                            lun=None):
1746
 
        return self._get_path('services/hostedservices/' + _str(service_name) +
1747
 
                              '/deployments/' + _str(deployment_name) +
1748
 
                              '/roles/' + _str(role_name) + '/DataDisks', lun)
1749
 
 
1750
 
    def _get_disk_path(self, disk_name=None):
1751
 
        return self._get_path('services/disks', disk_name)
1752
 
 
1753
 
    def _get_image_path(self, image_name=None):
1754
 
        return self._get_path('services/images', image_name)