本文整理汇总了Python中azure.servicemanagement.ServiceManagementService.add_service_certificate方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManagementService.add_service_certificate方法的具体用法?Python ServiceManagementService.add_service_certificate怎么用?Python ServiceManagementService.add_service_certificate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicemanagement.ServiceManagementService
的用法示例。
在下文中一共展示了ServiceManagementService.add_service_certificate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Deployment
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import add_service_certificate [as 别名]
#.........这里部分代码省略.........
"""
Creates the specified cloud service host if it does not exist.
service_name: Name of the cloud service.
affinity_group_name: Name of the affinity group (which should exists).
"""
logger.info("Checking for existence of cloud service (name=%s).", service_name)
if self._resource_exists(lambda: self.sms.get_hosted_service_properties(service_name)):
logger.warn("A cloud service named %s already exists.", service_name)
else:
self.sms.create_hosted_service(service_name, service_name, affinity_group=affinity_group_name)
logger.info("Created cloud service %s.", service_name)
def _ensureServiceCertificateExists(self, service_name):
"""
Adds certificate to the specified cloud service.
service_name: Name of the target cloud service (which should exist).
"""
cert_format = self.config.getServiceCertificateFormat()
cert_algorithm = self.config.getServiceCertificateAlgorithm()
cert_thumbprint = self.config.getServiceCertificateThumbprint()
cert_path = self.config.getServiceCertificateFilename()
cert_password = self.config.getServiceCertificatePassword()
logger.info("Checking for existence of cloud service certificate for service %s.", service_name)
get_cert = lambda: self.sms.get_service_certificate(service_name, cert_algorithm, cert_thumbprint)
if self._resource_exists(get_cert):
logger.info("Found expected cloud service certificate.")
else:
with open(cert_path, 'rb') as f:
cert_data = base64.b64encode(f.read())
if len(cert_data) <= 0:
raise Exception("Detected invalid certificate data.")
result = self.sms.add_service_certificate(service_name, cert_data, cert_format, cert_password)
self._wait_for_operation_success(result.request_id, timeout=self.config.getAzureOperationTimeout())
logger.info("Added service certificate.")
def _assertOsImageExists(self, os_image_name):
"""
Asserts that the named OS image exists.
"""
logger.info("Checking for availability of OS image (name=%s).", os_image_name)
if self.sms.get_os_image(os_image_name) is None:
raise Exception("Unable to find OS Image '{0}'.".format(os_image_name))
def _ensureVirtualMachinesExist(self):
"""
Creates the VMs for the web site.
"""
service_name = self.config.getServiceName()
cert_thumbprint = self.config.getServiceCertificateThumbprint()
vm_username = self.config.getVirtualMachineLogonUsername()
vm_password = self.config.getVirtualMachineLogonPassword()
vm_role_size = self.config.getServiceInstanceRoleSize()
vm_numbers = self.config.getServiceInstanceCount()
if vm_numbers < 1:
raise Exception("Detected an invalid number of instances: {0}.".format(vm_numbers))
self._assertOsImageExists(self.config.getServiceOSImageName())
role_instances = self._getRoleInstances(service_name)
for vm_number in range(1, vm_numbers+1):
vm_hostname = '{0}-{1}'.format(service_name, vm_number)
if vm_hostname in role_instances:
logger.warn("Role instance %s already exists: skipping creation.", vm_hostname)
continue
示例2: open
# 需要导入模块: from azure.servicemanagement import ServiceManagementService [as 别名]
# 或者: from azure.servicemanagement.ServiceManagementService import add_service_certificate [as 别名]
if account.service_name == storage_acc_name:
storageServiceObj = sms.get_storage_account_keys(account.service_name)
storage_acc_key = storageServiceObj.storage_service_keys.primary
# cert_path = "/home/rohan/temp2/myCert.pem"
cert_path = config_params["vm_cert_path"]
with open(cert_path, "rb") as bfile:
# decode to make sure this is a str and not a bstr
cert_data = base64.b64encode(bfile.read()).decode()
cert_format = 'pfx'
cert_password = ''
cert_res = sms.add_service_certificate(service_name=hosted_service_name,
data=cert_data,
certificate_format=cert_format,
password=cert_password)
operation_result = sms.get_operation_status(cert_res.request_id)
# Create a container
blob_service = BlobService(account_name=storage_acc_name,
account_key=storage_acc_key)
container_name = "vm-container"
result = blob_service.create_container(container_name)
container_url_template = "http://{}.blob.core.windows.net/{}"
container_url = container_url_template.format(storage_acc_name, container_name)