summaryrefslogtreecommitdiff
path: root/azurelinuxagent/common/protocol/restapi.py
diff options
context:
space:
mode:
Diffstat (limited to 'azurelinuxagent/common/protocol/restapi.py')
-rw-r--r--azurelinuxagent/common/protocol/restapi.py74
1 files changed, 54 insertions, 20 deletions
diff --git a/azurelinuxagent/common/protocol/restapi.py b/azurelinuxagent/common/protocol/restapi.py
index 7f00488..5f71cf2 100644
--- a/azurelinuxagent/common/protocol/restapi.py
+++ b/azurelinuxagent/common/protocol/restapi.py
@@ -16,15 +16,12 @@
#
# Requires Python 2.4+ and Openssl 1.0+
#
-import os
-import copy
-import re
-import json
-import xml.dom.minidom
+
import azurelinuxagent.common.logger as logger
+import azurelinuxagent.common.utils.restutil as restutil
from azurelinuxagent.common.exception import ProtocolError, HttpError
from azurelinuxagent.common.future import ustr
-import azurelinuxagent.common.utils.restutil as restutil
+
def validate_param(name, val, expected_type):
if val is None:
@@ -33,13 +30,14 @@ def validate_param(name, val, expected_type):
raise ProtocolError(("{0} type should be {1} not {2}"
"").format(name, expected_type, type(val)))
+
def set_properties(name, obj, data):
if isinstance(obj, DataContract):
validate_param("Property '{0}'".format(name), data, dict)
for prob_name, prob_val in data.items():
prob_full_name = "{0}.{1}".format(name, prob_name)
try:
- prob = getattr(obj, prob_name)
+ prob = getattr(obj, prob_name)
except AttributeError:
logger.warn("Unknown property: {0}", prob_full_name)
continue
@@ -56,6 +54,7 @@ def set_properties(name, obj, data):
else:
return data
+
def get_properties(obj):
if isinstance(obj, DataContract):
data = {}
@@ -72,16 +71,21 @@ def get_properties(obj):
else:
return obj
+
class DataContract(object):
pass
+
class DataContractList(list):
def __init__(self, item_cls):
self.item_cls = item_cls
+
"""
Data contract between guest and host
"""
+
+
class VMInfo(DataContract):
def __init__(self, subscriptionId=None, vmName=None, containerId=None,
roleName=None, roleInstanceName=None, tenantName=None):
@@ -92,30 +96,40 @@ class VMInfo(DataContract):
self.roleInstanceName = roleInstanceName
self.tenantName = tenantName
+class CertificateData(DataContract):
+ def __init__(self, certificateData=None):
+ self.certificateData = certificateData
+
class Cert(DataContract):
- def __init__(self, name=None, thumbprint=None, certificateDataUri=None):
+ def __init__(self, name=None, thumbprint=None, certificateDataUri=None, storeName=None, storeLocation=None):
self.name = name
self.thumbprint = thumbprint
self.certificateDataUri = certificateDataUri
+ self.storeLocation = storeLocation
+ self.storeName = storeName
class CertList(DataContract):
def __init__(self):
self.certificates = DataContractList(Cert)
-#TODO: confirm vmagent manifest schema
+
+# TODO: confirm vmagent manifest schema
class VMAgentManifestUri(DataContract):
def __init__(self, uri=None):
self.uri = uri
+
class VMAgentManifest(DataContract):
def __init__(self, family=None):
self.family = family
self.versionsManifestUris = DataContractList(VMAgentManifestUri)
+
class VMAgentManifestList(DataContract):
def __init__(self):
self.vmAgentManifests = DataContractList(VMAgentManifest)
+
class Extension(DataContract):
def __init__(self, name=None, sequenceNumber=None, publicSettings=None,
protectedSettings=None, certificateThumbprint=None):
@@ -125,6 +139,7 @@ class Extension(DataContract):
self.protectedSettings = protectedSettings
self.certificateThumbprint = certificateThumbprint
+
class ExtHandlerProperties(DataContract):
def __init__(self):
self.version = None
@@ -132,40 +147,49 @@ class ExtHandlerProperties(DataContract):
self.state = None
self.extensions = DataContractList(Extension)
+
class ExtHandlerVersionUri(DataContract):
def __init__(self):
self.uri = None
+
class ExtHandler(DataContract):
def __init__(self, name=None):
self.name = name
self.properties = ExtHandlerProperties()
self.versionUris = DataContractList(ExtHandlerVersionUri)
+
class ExtHandlerList(DataContract):
def __init__(self):
self.extHandlers = DataContractList(ExtHandler)
+
class ExtHandlerPackageUri(DataContract):
def __init__(self, uri=None):
self.uri = uri
+
class ExtHandlerPackage(DataContract):
- def __init__(self, version = None):
+ def __init__(self, version=None):
self.version = version
self.uris = DataContractList(ExtHandlerPackageUri)
# TODO update the naming to align with metadata protocol
self.isinternal = False
+ self.disallow_major_upgrade = False
+
class ExtHandlerPackageList(DataContract):
def __init__(self):
self.versions = DataContractList(ExtHandlerPackage)
+
class VMProperties(DataContract):
def __init__(self, certificateThumbprint=None):
- #TODO need to confirm the property name
+ # TODO need to confirm the property name
self.certificateThumbprint = certificateThumbprint
+
class ProvisionStatus(DataContract):
def __init__(self, status=None, subStatus=None, description=None):
self.status = status
@@ -173,6 +197,7 @@ class ProvisionStatus(DataContract):
self.description = description
self.properties = VMProperties()
+
class ExtensionSubStatus(DataContract):
def __init__(self, name=None, status=None, code=None, message=None):
self.name = name
@@ -180,6 +205,7 @@ class ExtensionSubStatus(DataContract):
self.code = code
self.message = message
+
class ExtensionStatus(DataContract):
def __init__(self, configurationAppliedTime=None, operation=None,
status=None, seq_no=None, code=None, message=None):
@@ -191,8 +217,9 @@ class ExtensionStatus(DataContract):
self.message = message
self.substatusList = DataContractList(ExtensionSubStatus)
+
class ExtHandlerStatus(DataContract):
- def __init__(self, name=None, version=None, status=None, code=0,
+ def __init__(self, name=None, version=None, status=None, code=0,
message=None):
self.name = name
self.version = version
@@ -201,6 +228,7 @@ class ExtHandlerStatus(DataContract):
self.message = message
self.extensions = DataContractList(ustr)
+
class VMAgentStatus(DataContract):
def __init__(self, version=None, status=None, message=None):
self.version = version
@@ -208,27 +236,31 @@ class VMAgentStatus(DataContract):
self.message = message
self.extensionHandlers = DataContractList(ExtHandlerStatus)
+
class VMStatus(DataContract):
def __init__(self):
self.vmAgent = VMAgentStatus()
+
class TelemetryEventParam(DataContract):
def __init__(self, name=None, value=None):
self.name = name
self.value = value
+
class TelemetryEvent(DataContract):
def __init__(self, eventId=None, providerId=None):
self.eventId = eventId
self.providerId = providerId
self.parameters = DataContractList(TelemetryEventParam)
+
class TelemetryEventList(DataContract):
def __init__(self):
self.events = DataContractList(TelemetryEvent)
-class Protocol(DataContract):
+class Protocol(DataContract):
def detect(self):
raise NotImplementedError()
@@ -240,8 +272,8 @@ class Protocol(DataContract):
def get_vmagent_manifests(self):
raise NotImplementedError()
-
- def get_vmagent_pkgs(self):
+
+ def get_vmagent_pkgs(self, manifest):
raise NotImplementedError()
def get_ext_handlers(self):
@@ -250,13 +282,16 @@ class Protocol(DataContract):
def get_ext_handler_pkgs(self, extension):
raise NotImplementedError()
- def download_ext_handler_pkg(self, uri):
+ def get_artifacts_profile(self):
+ raise NotImplementedError()
+
+ def download_ext_handler_pkg(self, uri, headers=None):
try:
- resp = restutil.http_get(uri, chk_proxy=True)
+ resp = restutil.http_get(uri, chk_proxy=True, headers=headers)
if resp.status == restutil.httpclient.OK:
return resp.read()
- except HttpError as e:
- raise ProtocolError("Failed to download from: {0}".format(uri), e)
+ except Exception as e:
+ logger.warn("Failed to download from: {0}".format(uri), e)
def report_provision_status(self, provision_status):
raise NotImplementedError()
@@ -269,4 +304,3 @@ class Protocol(DataContract):
def report_event(self, event):
raise NotImplementedError()
-