Commit c947ae5b by Szabolcs Gelencser

Add azure pip module. Implement install diagnostics task.

parent 27c25960
......@@ -7,6 +7,30 @@ from os import getenv
from socket import gethostname
from threading import Event
import logging
import base64
from azure.common.credentials import ServicePrincipalCredentials
import azure.mgmt.compute
import azure.mgmt.storage
SUBSCRIPTION_ID = getenv('SUBSCRIPTION_ID')
CLIENT_ID = getenv('CLIENT_ID')
SECRET = getenv('SECRET')
TENANT = getenv('TENANT')
GROUP_NAME = getenv('GROUP_NAME')
REGION = getenv('REGION')
STORAGE_NAME = getenv('STORAGE_NAME')
credentials = ServicePrincipalCredentials(
client_id = CLIENT_ID,
secret = SECRET,
tenant = TENANT,
)
compute_client = azure.mgmt.compute.ComputeManagementClient(
credentials,
SUBSCRIPTION_ID
)
logger = logging.getLogger()
......@@ -48,6 +72,70 @@ def send_command(vm, command, *args, **kwargs):
return retval
@celery.task(name='agent.install_diagnostics_extension')
def install_diagnostics_extension(vm_name):
"""
Install diagnostics extension on already running vm
"""
with open("miscellaneous/linux_diagnostics.xml", "rt") as linuxdf:
XmlCfg = linuxdf.read()
b64encodedXmlCfg = base64.b64encode(
XmlCfg.replace(
"$SUBSCRIPTION_ID",
SUBSCRIPTION_ID,
).replace(
"$GROUP_NAME",
GROUP_NAME,
).replace(
"$VM_NAME",
vm_name,
)
)
storage_client = azure.mgmt.storage.StorageManagementClient(
credentials,
SUBSCRIPTION_ID,
)
key_result = storage_client.storage_accounts.list_keys(
GROUP_NAME,
STORAGE_NAME,
)
settings = {
'StorageAccount': STORAGE_NAME,
'xmlCfg': b64encodedXmlCfg,
}
protected_settings = {
'storageAccountName': STORAGE_NAME,
'storageAccountKey': key_result.keys[0].value,
'storageAccountEndPoint': 'https://core.windows.net',
}
poller = compute_client.virtual_machine_extensions.create_or_update(
GROUP_NAME,
vm_name,
"LinuxDiagnostic",
azure.mgmt.compute.models.VirtualMachineExtension(
location=REGION,
publisher="Microsoft.OSTCExtensions",
virtual_machine_extension_type="LinuxDiagnostic",
type_handler_version="2.3",
auto_upgrade_minor_version=True,
protected_settings=protected_settings,
settings=settings,
),
)
try:
poller.wait()
logging.info("installed diagnostics on: '%s'" % vm_name)
except Exception, e:
logging.error("cloud not install diagnostics on '%s'" % vm_name)
raise e
@celery.task(name='agent.change_password')
def change_password(vm, password):
......
<WadCfg>
<DiagnosticMonitorConfiguration overallQuotaInMB="4096">
<DiagnosticInfrastructureLogs scheduledTransferLogLevelFilter="Warning" scheduledTransferPeriod="PT1M"/>
<PerformanceCounters scheduledTransferPeriod="PT1M">
<PerformanceCounterConfiguration counterSpecifier="\Memory\PercentUsedMemory" sampleRate="PT15S" unit="Percent">
<annotation displayName="Memory percentage" locale="en-us"/>
</PerformanceCounterConfiguration>
<PerformanceCounterConfiguration counterSpecifier="\Processor\PercentProcessorTime" sampleRate="PT15S" unit="Percent">
<annotation displayName="CPU percentage guest OS" locale="en-us"/>
</PerformanceCounterConfiguration>
<PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\BytesTransmitted" sampleRate="PT15S" unit="Bytes">
<annotation displayName="Network out guest OS" locale="en-us"/>
</PerformanceCounterConfiguration>
<PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\BytesReceived" sampleRate="PT15S" unit="Bytes">
<annotation displayName="Network in guest OS" locale="en-us"/>
</PerformanceCounterConfiguration>
<PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\PacketsTransmitted" sampleRate="PT15S" unit="Count">
<annotation displayName="Packets sent" locale="en-us"/>
</PerformanceCounterConfiguration>
<PerformanceCounterConfiguration counterSpecifier="\NetworkInterface\PacketsReceived" sampleRate="PT15S" unit="Count">
<annotation displayName="Packets received" locale="en-us"/>
</PerformanceCounterConfiguration>
</PerformanceCounters>
<Metrics resourceId="/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$GROUP_NAME/providers/Microsoft.Compute/virtualMachines/$VM_NAME">
<MetricAggregation scheduledTransferPeriod="PT1H"/>
<MetricAggregation scheduledTransferPeriod="PT1M"/>
</Metrics>
</DiagnosticMonitorConfiguration>
</WadCfg>
celery==3.1.17
Twisted==13.1.0
amqp==1.4.9
anyjson==0.3.3
azure==2.0.0rc6
azure-batch==1.0.0
azure-common==1.1.4
azure-mgmt==0.30.0rc6
azure-mgmt-batch==1.0.0
azure-mgmt-compute==0.30.0rc6
azure-mgmt-keyvault==0.30.0rc6
azure-mgmt-logic==1.0.0
azure-mgmt-network==0.30.0rc6
azure-mgmt-nspkg==1.0.0
azure-mgmt-redis==1.0.0
azure-mgmt-resource==0.30.0rc6
azure-mgmt-scheduler==1.0.0
azure-mgmt-storage==0.30.0rc6
azure-nspkg==1.0.0
azure-servicebus==0.20.3
azure-servicemanagement-legacy==0.20.4
azure-storage==0.33.0
billiard==3.3.0.23
celery==3.1.17
certifi==2016.9.26
cffi==1.8.3
chardet==2.3.0
cryptography==1.5.2
enum34==1.1.6
futures==3.0.5
idna==2.1
ipaddress==1.0.17
isodate==0.5.4
keyring==10.0.2
kombu==3.0.35
msrest==0.4.4
msrestazure==0.4.4
oauthlib==2.0.0
pyasn1==0.1.9
pycparser==2.17
python-dateutil==2.5.3
pytz==2016.6.1
requests==2.11.1
requests-oauthlib==0.7.0
six==1.10.0
threadpool==1.2.7
wsgiref==0.1.2
zope.interface==4.3.2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment