From 1ddc0b99fecb610b2ea0ecc523e1a2dfabba6d31 Mon Sep 17 00:00:00 2001 From: Anthony Xu Date: Tue, 10 Dec 2013 01:11:59 -0800 Subject: [PATCH] put CS/XS plugin log into seperate directory --- .../xen/resource/CitrixResourceBase.java | 2 +- scripts/vm/hypervisor/xenserver/cloudlog | 12 + scripts/vm/hypervisor/xenserver/ovs-pvlan | 6 +- scripts/vm/hypervisor/xenserver/ovstunnel | 6 +- scripts/vm/hypervisor/xenserver/s3xen | 6 +- scripts/vm/hypervisor/xenserver/storagePlugin | 10 +- scripts/vm/hypervisor/xenserver/swiftxen | 12 +- scripts/vm/hypervisor/xenserver/vmops | 236 +++++++++--------- scripts/vm/hypervisor/xenserver/vmopsSnapshot | 108 ++++---- scripts/vm/hypervisor/xenserver/vmopspremium | 8 +- scripts/vm/hypervisor/xenserver/xcposs/patch | 1 + .../vm/hypervisor/xenserver/xcpserver/patch | 1 + .../vm/hypervisor/xenserver/xenserver56/patch | 1 + .../hypervisor/xenserver/xenserver56fp1/patch | 2 +- .../vm/hypervisor/xenserver/xenserver60/patch | 1 + 15 files changed, 226 insertions(+), 186 deletions(-) create mode 100644 scripts/vm/hypervisor/xenserver/cloudlog diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index e9d42b44057..67b119bce7f 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -5379,7 +5379,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe com.trilead.ssh2.Session session = sshConnection.openSession(); - String cmd = "mkdir -p /opt/cloud/bin"; + String cmd = "mkdir -p /opt/cloud/bin /var/log/cloud"; if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) { throw new CloudRuntimeException("Cannot create directory /opt/cloud/bin on XenServer hosts"); } diff --git a/scripts/vm/hypervisor/xenserver/cloudlog b/scripts/vm/hypervisor/xenserver/cloudlog new file mode 100644 index 00000000000..19560ef50e2 --- /dev/null +++ b/scripts/vm/hypervisor/xenserver/cloudlog @@ -0,0 +1,12 @@ +/var/log/cloud/vmops.log { + daily + size 1M + rotate 20 +} + +/var/log/cloud/ovstunnel.log /var/log/cloud/ovs-pvlan.log /var/log/cloud/swiftxen.log /var/log/cloud/s3xen /var/log/cloud/storageplugin { + daily + size 1M + rotate 2 +} + diff --git a/scripts/vm/hypervisor/xenserver/ovs-pvlan b/scripts/vm/hypervisor/xenserver/ovs-pvlan index 8579b551d9d..c9280a57af7 100755 --- a/scripts/vm/hypervisor/xenserver/ovs-pvlan +++ b/scripts/vm/hypervisor/xenserver/ovs-pvlan @@ -31,7 +31,7 @@ import util from time import localtime as _localtime, asctime as _asctime xePath = "/opt/xensource/bin/xe" -lib.setup_logging("/var/log/ovs-pvlan.log") +lib.setup_logging("/var/log/cloud/ovs-pvlan.log") dhcpSetupPath = "/opt/cloud/bin/ovs-pvlan-dhcp-host.sh" vmSetupPath = "/opt/cloud/bin/ovs-pvlan-vm.sh" getDhcpIfacePath = "/opt/cloud/bin/ovs-get-dhcp-iface.sh" @@ -41,9 +41,9 @@ getBridgePath = "/opt/cloud/bin/ovs-get-bridge.sh" def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### VMOPS enter %s ####" % name) + logging.debug("#### VMOPS enter %s ####" % name) res = fn(*v, **k) - util.SMlog("#### VMOPS exit %s ####" % name) + logging.debug("#### VMOPS exit %s ####" % name) return res return wrapped diff --git a/scripts/vm/hypervisor/xenserver/ovstunnel b/scripts/vm/hypervisor/xenserver/ovstunnel index a38a0665522..6ecd8ea7757 100755 --- a/scripts/vm/hypervisor/xenserver/ovstunnel +++ b/scripts/vm/hypervisor/xenserver/ovstunnel @@ -35,7 +35,7 @@ import util from time import localtime as _localtime, asctime as _asctime xePath = "/opt/xensource/bin/xe" -lib.setup_logging("/var/log/ovstunnel.log") +lib.setup_logging("/var/log/cloud/ovstunnel.log") def block_ipv6_v5(bridge): @@ -54,9 +54,9 @@ block_ipv6_handlers = { def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### VMOPS enter %s ####" % name) + logging.debug("#### VMOPS enter %s ####" % name) res = fn(*v, **k) - util.SMlog("#### VMOPS exit %s ####" % name) + logging.debug("#### VMOPS exit %s ####" % name) return res return wrapped diff --git a/scripts/vm/hypervisor/xenserver/s3xen b/scripts/vm/hypervisor/xenserver/s3xen index bf81bbd34a6..ccd7ce51f27 100644 --- a/scripts/vm/hypervisor/xenserver/s3xen +++ b/scripts/vm/hypervisor/xenserver/s3xen @@ -39,6 +39,10 @@ from xml.dom.minidom import parseString import XenAPIPlugin sys.path.extend(["/opt/xensource/sm/"]) import util +import cloudstack_pluginlib as lib +import logging + +lib.setup_logging("/var/log/cloud/s3xen.log") NULL = 'null' @@ -102,7 +106,7 @@ def get_optional_key(map, key, default=''): def log(message): - util.SMlog('#### VMOPS %s ####' % message) + logging.debug('#### VMOPS %s ####' % message) def echo(fn): diff --git a/scripts/vm/hypervisor/xenserver/storagePlugin b/scripts/vm/hypervisor/xenserver/storagePlugin index bb033797620..ff00fa273c3 100755 --- a/scripts/vm/hypervisor/xenserver/storagePlugin +++ b/scripts/vm/hypervisor/xenserver/storagePlugin @@ -32,13 +32,17 @@ import subprocess import zlib import urllib2 import traceback +import cloudstack_pluginlib as lib +import logging + +lib.setup_logging("/var/log/cloud/storageplugin.log") def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### xen plugin enter %s ####" % name ) + logging.debug("#### xen plugin enter %s ####" % name ) res = fn(*v, **k) - util.SMlog("#### xen plugin exit %s ####" % name ) + logging.debug("#### xen plugin exit %s ####" % name ) return res return wrapped @@ -53,7 +57,7 @@ def downloadTemplateFromUrl(session, args): destFile.close() return "success" except: - util.SMlog("exception: " + str(sys.exc_info())) + logging.debug("exception: " + str(sys.exc_info())) return "" @echo diff --git a/scripts/vm/hypervisor/xenserver/swiftxen b/scripts/vm/hypervisor/xenserver/swiftxen index 46229e37262..8342238ad82 100644 --- a/scripts/vm/hypervisor/xenserver/swiftxen +++ b/scripts/vm/hypervisor/xenserver/swiftxen @@ -24,13 +24,17 @@ import os, sys, time import XenAPIPlugin sys.path.extend(["/opt/xensource/sm/"]) import util +import cloudstack_pluginlib as lib +import logging + +lib.setup_logging("/var/log/cloud/swiftxen.log") def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### VMOPS enter %s ####" % name ) + logging.debug("#### VMOPS enter %s ####" % name ) res = fn(*v, **k) - util.SMlog("#### VMOPS exit %s ####" % name ) + logging.debug("#### VMOPS exit %s ####" % name ) return res return wrapped @@ -48,7 +52,7 @@ def upload(args): lfilename = args['lfilename'] isISCSI = args['isISCSI'] segment = 0 - util.SMlog("#### VMOPS upload %s to swift ####", lfilename) + logging.debug("#### VMOPS upload %s to swift ####", lfilename) savedpath = os.getcwd() os.chdir(ldir) try : @@ -85,7 +89,7 @@ def swift(session, args): elif op == 'delete' : cmd = ["st", "-A https://" + hostname + ":8080/auth/v1.0 -U " + account + ":" + username + " -K " + token + " delete " + rfilename] else : - util.SMlog("doesn't support swift operation %s " % op ) + logging.debug("doesn't support swift operation %s " % op ) return 'false' try: util.pread2(cmd) diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index e4b3caf38a8..2e14fad5b9c 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -34,14 +34,18 @@ import tempfile import util import subprocess import zlib +import cloudstack_pluginlib as lib +import logging from util import CommandException +lib.setup_logging("/var/log/cloud/vmops.log") + def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### VMOPS enter %s ####" % name ) + logging.debug("#### VMOPS enter %s ####" % name ) res = fn(*v, **k) - util.SMlog("#### VMOPS exit %s ####" % name ) + logging.debug("#### VMOPS exit %s ####" % name ) return res return wrapped @@ -96,7 +100,7 @@ def preparemigration(session, args): util.pread2(cmd) txt = 'success' except: - util.SMlog("Catch prepare migration exception" ) + logging.debug("Catch prepare migration exception" ) txt = '' return txt @@ -108,7 +112,7 @@ def setIptables(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog(" setIptables execution failed " ) + logging.debug(" setIptables execution failed " ) txt = '' return txt @@ -153,7 +157,7 @@ def pingtest(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog(" pingtest failed " ) + logging.debug(" pingtest failed " ) txt = '' return txt @@ -168,7 +172,7 @@ def savePassword(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog(" save password to domr failed " ) + logging.debug(" save password to domr failed " ) txt = '' return txt @@ -183,7 +187,7 @@ def saveDhcpEntry(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog(" save dhcp entry failed " ) + logging.debug(" save dhcp entry failed " ) txt = '' return txt @@ -245,7 +249,7 @@ def setFirewallRule(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog(" set firewall rule failed " ) + logging.debug(" set firewall rule failed " ) txt = '' return txt @@ -261,7 +265,7 @@ def routerProxy(session, args): if txt is None or len(txt) == 0 : txt = 'success' except: - util.SMlog("routerProxy command " + sargs + " failed " ) + logging.debug("routerProxy command " + sargs + " failed " ) txt = '' return txt @@ -278,7 +282,7 @@ def setLoadBalancerRule(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog(" set loadbalancer rule failed " ) + logging.debug(" set loadbalancer rule failed " ) txt = '' return txt @@ -291,7 +295,7 @@ def configdnsmasq(session, args): util.pread2(['ssh','-p','3922','-q','-o','StrictHostKeyChecking=no','-i','/root/.ssh/id_rsa.cloud',target,'/root/dnsmasq.sh',args]) txt='success' except: - util.SMlog("failed to config dnsmasq server") + logging.debug("failed to config dnsmasq server") txt='' return txt @@ -305,7 +309,7 @@ def createipAlias(session, args): txt=util.pread2(cmd) txt='success' except: - util.SMlog("failed to create ip alias on router vm") + logging.debug("failed to create ip alias on router vm") txt='' return txt @@ -319,7 +323,7 @@ def deleteipAlias(session, args): txt=util.pread2(cmd) txt='success' except: - util.SMlog("failed to create ip alias on router vm") + logging.debug("failed to create ip alias on router vm") txt='' return txt @@ -334,7 +338,7 @@ def createFile(session, args): f.close() txt = 'success' except: - util.SMlog(" failed to create HA proxy cfg file ") + logging.debug(" failed to create HA proxy cfg file ") txt = '' return txt @@ -354,7 +358,7 @@ def createFileInDomr(session, args): util.pread2(['rm',tmpfile]) txt = 'success' except: - util.SMlog(" failed to create HA proxy cfg file ") + logging.debug(" failed to create HA proxy cfg file ") txt = '' return txt @@ -368,7 +372,7 @@ def deleteFile(session, args): os.remove(file_path) txt = 'success' except: - util.SMlog(" failed to remove HA proxy cfg file ") + logging.debug(" failed to remove HA proxy cfg file ") txt = '' return txt @@ -409,7 +413,7 @@ def can_bridge_firewall(session, args): util.pread2(['iptables', '-A', 'BRIDGE-FIREWALL', '-m', 'physdev', '--physdev-is-bridged', '-p', 'udp', '--dport', '68', '--sport', '67', '-j', 'ACCEPT']) util.pread2(['iptables', '-D', 'FORWARD', '-j', 'RH-Firewall-1-INPUT']) except: - util.SMlog('Chain BRIDGE-FIREWALL already exists') + logging.debug('Chain BRIDGE-FIREWALL already exists') try: util.pread2(['iptables', '-N', 'BRIDGE-DEFAULT-FIREWALL']) @@ -421,7 +425,7 @@ def can_bridge_firewall(session, args): util.pread2(['iptables', '-D', 'BRIDGE-FIREWALL', '-m', 'physdev', '--physdev-is-bridged', '-p', 'udp', '--dport', '67', '--sport', '68', '-j', 'ACCEPT']) util.pread2(['iptables', '-D', 'BRIDGE-FIREWALL', '-m', 'physdev', '--physdev-is-bridged', '-p', 'udp', '--dport', '68', '--sport', '67', '-j', 'ACCEPT']) except: - util.SMlog('Chain BRIDGE-DEFAULT-FIREWALL already exists') + logging.debug('Chain BRIDGE-DEFAULT-FIREWALL already exists') result = 'true' try: @@ -468,7 +472,7 @@ def default_ebtables_rules(): # deny all others (e.g., 802.1d, CDP) util.pread2(['ebtables', '-A', 'DEFAULT_EBTABLES', '-j', 'DROP']) except: - util.SMlog('Chain DEFAULT_EBTABLES already exists') + logging.debug('Chain DEFAULT_EBTABLES already exists') @echo @@ -485,7 +489,7 @@ def allow_egress_traffic(session): try: util.pread2(['iptables', '-I', 'FORWARD', '2', '-m', 'physdev', '--physdev-is-bridged', '--physdev-out', d, '-j', 'ACCEPT']) except: - util.SMlog("Failed to add FORWARD rule through to %s" % d) + logging.debug("Failed to add FORWARD rule through to %s" % d) return 'false' return 'true' @@ -494,7 +498,7 @@ def ipset(ipsetname, proto, start, end, ips): try: util.pread2(['ipset', '-N', ipsetname, 'iptreemap']) except: - util.SMlog("ipset chain already exists" + ipsetname) + logging.debug("ipset chain already exists" + ipsetname) result = True ipsettmp = ''.join(''.join(ipsetname.split('-')).split('_')) + str(int(time.time()) % 1000) @@ -502,11 +506,11 @@ def ipset(ipsetname, proto, start, end, ips): try: util.pread2(['ipset', '-N', ipsettmp, 'iptreemap']) except: - util.SMlog("Failed to create temp ipset, reusing old name= " + ipsettmp) + logging.debug("Failed to create temp ipset, reusing old name= " + ipsettmp) try: util.pread2(['ipset', '-F', ipsettmp]) except: - util.SMlog("Failed to clear old temp ipset name=" + ipsettmp) + logging.debug("Failed to clear old temp ipset name=" + ipsettmp) return False try: @@ -517,7 +521,7 @@ def ipset(ipsetname, proto, start, end, ips): if cex.reason.rfind('already in set') == -1: raise except: - util.SMlog("Failed to program ipset " + ipsetname) + logging.debug("Failed to program ipset " + ipsetname) util.pread2(['ipset', '-F', ipsettmp]) util.pread2(['ipset', '-X', ipsettmp]) return False @@ -525,7 +529,7 @@ def ipset(ipsetname, proto, start, end, ips): try: util.pread2(['ipset', '-W', ipsettmp, ipsetname]) except: - util.SMlog("Failed to swap ipset " + ipsetname) + logging.debug("Failed to swap ipset " + ipsetname) result = False try: @@ -533,7 +537,7 @@ def ipset(ipsetname, proto, start, end, ips): util.pread2(['ipset', '-X', ipsettmp]) except: # if the temporary name clashes next time we'll just reuse it - util.SMlog("Failed to delete temp ipset " + ipsettmp) + logging.debug("Failed to delete temp ipset " + ipsettmp) return result @@ -550,7 +554,7 @@ def destroy_network_rules_for_vm(session, args): util.pread2(['iptables', '-F', vmchain_default]) util.pread2(['iptables', '-X', vmchain_default]) except: - util.SMlog("Ignoring failure to delete chain " + vmchain_default) + logging.debug("Ignoring failure to delete chain " + vmchain_default) destroy_ebtables_rules(vmchain) destroy_arptables_rules(vmchain) @@ -559,14 +563,14 @@ def destroy_network_rules_for_vm(session, args): util.pread2(['iptables', '-F', vmchain]) util.pread2(['iptables', '-X', vmchain]) except: - util.SMlog("Ignoring failure to delete ingress chain " + vmchain) + logging.debug("Ignoring failure to delete ingress chain " + vmchain) try: util.pread2(['iptables', '-F', vmchain_egress]) util.pread2(['iptables', '-X', vmchain_egress]) except: - util.SMlog("Ignoring failure to delete egress chain " + vmchain_egress) + logging.debug("Ignoring failure to delete egress chain " + vmchain_egress) remove_rule_log_for_vm(vm_name) remove_secip_log_for_vm(vm_name) @@ -582,7 +586,7 @@ def destroy_network_rules_for_vm(session, args): util.pread2(['ipset', '-F', set]) util.pread2(['ipset', '-X', set]) except: - util.SMlog("Failed to destroy ipsets for %" % vm_name) + logging.debug("Failed to destroy ipsets for %" % vm_name) return 'true' @@ -599,12 +603,12 @@ def destroy_ebtables_rules(vm_chain): dc.insert(0, 'ebtables') util.pread2(dc) except: - util.SMlog("Ignoring failure to delete ebtables rules for vm " + vm_chain) + logging.debug("Ignoring failure to delete ebtables rules for vm " + vm_chain) try: util.pread2(['ebtables', '-F', vm_chain]) util.pread2(['ebtables', '-X', vm_chain]) except: - util.SMlog("Ignoring failure to delete ebtables chain for vm " + vm_chain) + logging.debug("Ignoring failure to delete ebtables chain for vm " + vm_chain) @echo def destroy_arptables_rules(vm_chain): @@ -619,18 +623,18 @@ def destroy_arptables_rules(vm_chain): dc.insert(2, 'FORWARD') util.pread2(dc) except: - util.SMlog("Ignoring failure to delete arptables rules for vm " + vm_chain) + logging.debug("Ignoring failure to delete arptables rules for vm " + vm_chain) try: util.pread2(['arptables', '-F', vm_chain]) util.pread2(['arptables', '-X', vm_chain]) except: - util.SMlog("Ignoring failure to delete arptables chain for vm " + vm_chain) + logging.debug("Ignoring failure to delete arptables chain for vm " + vm_chain) @echo def default_ebtables_antispoof_rules(vm_chain, vifs, vm_ip, vm_mac): if vm_mac == 'ff:ff:ff:ff:ff:ff': - util.SMlog("Ignoring since mac address is not valid") + logging.debug("Ignoring since mac address is not valid") return 'true' try: @@ -639,7 +643,7 @@ def default_ebtables_antispoof_rules(vm_chain, vifs, vm_ip, vm_mac): try: util.pread2(['ebtables', '-F', vm_chain]) except: - util.SMlog("Failed to create ebtables antispoof chain, skipping") + logging.debug("Failed to create ebtables antispoof chain, skipping") return 'true' # note all rules for packets into the bridge (-i) precede all output rules (-o) @@ -649,7 +653,7 @@ def default_ebtables_antispoof_rules(vm_chain, vifs, vm_ip, vm_mac): util.pread2(['ebtables', '-I', 'FORWARD', '2', '-i', vif, '-j', vm_chain]) util.pread2(['ebtables', '-A', 'FORWARD', '-o', vif, '-j', vm_chain]) except: - util.SMlog("Failed to program default ebtables FORWARD rules for %s" % vm_chain) + logging.debug("Failed to program default ebtables FORWARD rules for %s" % vm_chain) return 'false' try: @@ -665,7 +669,7 @@ def default_ebtables_antispoof_rules(vm_chain, vifs, vm_ip, vm_mac): # do not allow snooping of dhcp requests util.pread2(['ebtables', '-A', vm_chain, '-o', vif, '-p', 'IPv4', '--ip-proto', 'udp', '--ip-dport', '67', '-j', 'DROP']) except: - util.SMlog("Failed to program default ebtables antispoof rules for %s" % vm_chain) + logging.debug("Failed to program default ebtables antispoof rules for %s" % vm_chain) return 'false' return 'true' @@ -673,7 +677,7 @@ def default_ebtables_antispoof_rules(vm_chain, vifs, vm_ip, vm_mac): @echo def default_arp_antispoof(vm_chain, vifs, vm_ip, vm_mac): if vm_mac == 'ff:ff:ff:ff:ff:ff': - util.SMlog("Ignoring since mac address is not valid") + logging.debug("Ignoring since mac address is not valid") return 'true' try: @@ -682,7 +686,7 @@ def default_arp_antispoof(vm_chain, vifs, vm_ip, vm_mac): try: util.pread2(['arptables', '-F', vm_chain]) except: - util.SMlog("Failed to create arptables rule, skipping") + logging.debug("Failed to create arptables rule, skipping") return 'true' # note all rules for packets into the bridge (-i) precede all output rules (-o) @@ -691,7 +695,7 @@ def default_arp_antispoof(vm_chain, vifs, vm_ip, vm_mac): util.pread2(['arptables', '-I', 'FORWARD', '-i', vif, '-j', vm_chain]) util.pread2(['arptables', '-A', 'FORWARD', '-o', vif, '-j', vm_chain]) except: - util.SMlog("Failed to program default arptables rules in FORWARD chain vm=" + vm_chain) + logging.debug("Failed to program default arptables rules in FORWARD chain vm=" + vm_chain) return 'false' try: @@ -708,7 +712,7 @@ def default_arp_antispoof(vm_chain, vifs, vm_ip, vm_mac): util.pread2(['arptables', '-A', vm_chain, '-j', 'DROP']) except: - util.SMlog("Failed to program default arptables rules") + logging.debug("Failed to program default arptables rules") return 'false' return 'true' @@ -720,10 +724,10 @@ def network_rules_vmSecondaryIp(session, args): vm_mac = args.pop('vmMac') ip_secondary = args.pop('vmSecIp') action = args.pop('action') - util.SMlog("vmMac = "+ vm_mac) - util.SMlog("vmName = "+ vm_name) + logging.debug("vmMac = "+ vm_mac) + logging.debug("vmName = "+ vm_name) #action = "-A" - util.SMlog("action = "+ action) + logging.debug("action = "+ action) try: vm = session.xenapi.VM.get_by_name_label(vm_name) if len(vm) != 1: @@ -733,11 +737,11 @@ def network_rules_vmSecondaryIp(session, args): vifnums = [session.xenapi.VIF.get_record(vif).get('device') for vif in vm_vifs] domid = vm_rec.get('domid') except: - util.SMlog("### Failed to get domid or vif list for vm ##" + vm_name) + logging.debug("### Failed to get domid or vif list for vm ##" + vm_name) return 'false' if domid == '-1': - util.SMlog("### Failed to get domid for vm (-1): " + vm_name) + logging.debug("### Failed to get domid for vm (-1): " + vm_name) return 'false' vifs = ["vif" + domid + "." + v for v in vifnums] @@ -767,11 +771,11 @@ def default_network_rules_systemvm(session, args): vifnums = [session.xenapi.VIF.get_record(vif).get('device') for vif in vm_vifs] domid = vm_rec.get('domid') except: - util.SMlog("### Failed to get domid or vif list for vm ##" + vm_name) + logging.debug("### Failed to get domid or vif list for vm ##" + vm_name) return 'false' if domid == '-1': - util.SMlog("### Failed to get domid for vm (-1): " + vm_name) + logging.debug("### Failed to get domid for vm (-1): " + vm_name) return 'false' vifs = ["vif" + domid + "." + v for v in vifnums] @@ -792,26 +796,26 @@ def default_network_rules_systemvm(session, args): util.pread2(['iptables', '-I', 'BRIDGE-FIREWALL', '2', '-m', 'physdev', '--physdev-is-bridged', '--physdev-in', vif, '-j', vmchain]) util.pread2(['iptables', '-I', vmchain, '-m', 'physdev', '--physdev-is-bridged', '--physdev-in', vif, '-j', 'RETURN']) except: - util.SMlog("Failed to program default rules") + logging.debug("Failed to program default rules") return 'false' util.pread2(['iptables', '-A', vmchain, '-j', 'ACCEPT']) if write_rule_log_for_vm(vm_name, '-1', '_ignore_', domid, '_initial_', '-1') == False: - util.SMlog("Failed to log default network rules for systemvm, ignoring") + logging.debug("Failed to log default network rules for systemvm, ignoring") return 'true' @echo def create_ipset_forvm (ipsetname): result = True try: - util.SMlog("Creating ipset chain .... " + ipsetname) + logging.debug("Creating ipset chain .... " + ipsetname) util.pread2(['ipset', '-F', ipsetname]) util.pread2(['ipset', '-X', ipsetname]) util.pread2(['ipset', '-N', ipsetname, 'iphash']) except: - util.SMlog("ipset chain not exists creating.... " + ipsetname) + logging.debug("ipset chain not exists creating.... " + ipsetname) util.pread2(['ipset', '-N', ipsetname, 'iphash']) return result @@ -821,10 +825,10 @@ def add_to_ipset(ipsetname, ips, action): result = True for ip in ips: try: - util.SMlog("vm ip " + ip) + logging.debug("vm ip " + ip) util.pread2(['ipset', action, ipsetname, ip]) except: - util.SMlog("vm ip alreday in ip set" + ip) + logging.debug("vm ip alreday in ip set" + ip) continue return result @@ -846,7 +850,7 @@ def arp_rules_vmip (vm_chain, vifs, ips, vm_mac, action): #also important to restrict source ip and src mac in these requests as they can be used to update arp tables on destination util.pread2(['arptables', action, vm_chain, '-i', vif, '--opcode', 'Request', '--source-mac', vm_mac, '--source-ip', vm_ip, '-j', 'RETURN']) except: - util.SMlog("Failed to program arptables rules for ip") + logging.debug("Failed to program arptables rules for ip") return 'false' return 'true' @@ -864,15 +868,15 @@ def default_network_rules(session, args): try: vm = session.xenapi.VM.get_by_name_label(vm_name) if len(vm) != 1: - util.SMlog("### Failed to get record for vm " + vm_name) + logging.debug("### Failed to get record for vm " + vm_name) return 'false' vm_rec = session.xenapi.VM.get_record(vm[0]) domid = vm_rec.get('domid') except: - util.SMlog("### Failed to get domid for vm " + vm_name) + logging.debug("### Failed to get domid for vm " + vm_name) return 'false' if domid == '-1': - util.SMlog("### Failed to get domid for vm (-1): " + vm_name) + logging.debug("### Failed to get domid for vm (-1): " + vm_name) return 'false' vif = "vif" + domid + ".0" @@ -912,12 +916,12 @@ def default_network_rules(session, args): vmipset = vm_name #create ipset and add vm ips to that ip set if create_ipset_forvm(vmipset) == False: - util.SMlog(" failed to create ipset for rule " + str(tokens)) + logging.debug(" failed to create ipset for rule " + str(tokens)) return 'false' #add primary nic ip to ipset if add_to_ipset(vmipset, [vm_ip], action ) == False: - util.SMlog(" failed to add vm " + vm_ip + " ip to set ") + logging.debug(" failed to add vm " + vm_ip + " ip to set ") return 'false' #add secodnary nic ips to ipset @@ -928,10 +932,10 @@ def default_network_rules(session, args): secIpSet = "0"; if secIpSet == "1": - util.SMlog("Adding ipset for secondary ips") + logging.debug("Adding ipset for secondary ips") add_to_ipset(vmipset, ips, action) if write_secip_log_for_vm(vm_name, sec_ips, vm_id) == False: - util.SMlog("Failed to log default network rules, ignoring") + logging.debug("Failed to log default network rules, ignoring") keyword = '--' + get_ipset_keyword() @@ -949,21 +953,21 @@ def default_network_rules(session, args): util.pread2(['iptables', '-A', vmchain_default, '-m', 'physdev', '--physdev-is-bridged', '--physdev-in', v, '-m', 'set', keyword, vmipset, 'src', '-j', vmchain_egress]) util.pread2(['iptables', '-A', vmchain_default, '-m', 'physdev', '--physdev-is-bridged', '--physdev-out', v, '-j', vmchain]) except: - util.SMlog("Failed to program default rules for vm " + vm_name) + logging.debug("Failed to program default rules for vm " + vm_name) return 'false' default_arp_antispoof(vmchain, vifs, vm_ip, vm_mac) #add default arp rules for secondary ips; if secIpSet == "1": - util.SMlog("Adding arp rules for sec ip") + logging.debug("Adding arp rules for sec ip") arp_rules_vmip(vmchain, vifs, ips, vm_mac, action) default_ebtables_antispoof_rules(vmchain, vifs, vm_ip, vm_mac) if write_rule_log_for_vm(vm_name, vm_id, vm_ip, domid, '_initial_', '-1', vm_mac) == False: - util.SMlog("Failed to log default network rules, ignoring") + logging.debug("Failed to log default network rules, ignoring") - util.SMlog("Programmed default rules for vm " + vm_name) + logging.debug("Programmed default rules for vm " + vm_name) return 'true' @echo @@ -972,12 +976,12 @@ def check_domid_changed(session, vmName): try: vm = session.xenapi.VM.get_by_name_label(vmName) if len(vm) != 1: - util.SMlog("### Could not get record for vm ## " + vmName) + logging.debug("### Could not get record for vm ## " + vmName) else: vm_rec = session.xenapi.VM.get_record(vm[0]) curr_domid = vm_rec.get('domid') except: - util.SMlog("### Failed to get domid for vm ## " + vmName) + logging.debug("### Failed to get domid for vm ## " + vmName) logfilename = "/var/run/cloud/" + vmName +".log" @@ -1011,7 +1015,7 @@ def delete_rules_for_vm_in_bridge_firewall_chain(vmName): dc.pop() util.pread2(filter(None, dc)) except: - util.SMlog("Ignoring failure to delete rules for vm " + vmName) + logging.debug("Ignoring failure to delete rules for vm " + vmName) @echo @@ -1028,7 +1032,7 @@ def network_rules_for_rebooted_vm(session, vmName): if curr_domid == '-1': return True - util.SMlog("Found a rebooted VM -- reprogramming rules for " + vm_name) + logging.debug("Found a rebooted VM -- reprogramming rules for " + vm_name) delete_rules_for_vm_in_bridge_firewall_chain(vm_name) if 1 in [ vm_name.startswith(c) for c in ['r-', 's-', 'v-', 'l-'] ]: @@ -1073,9 +1077,9 @@ def network_rules_for_rebooted_vm(session, vmName): try: util.pread2(filter(None,ipt)) except: - util.SMlog("Failed to rewrite antispoofing rules for vm " + vm_name) + logging.debug("Failed to rewrite antispoofing rules for vm " + vm_name) except: - util.SMlog("No rules found for vm " + vm_name) + logging.debug("No rules found for vm " + vm_name) destroy_ebtables_rules(vmchain) destroy_arptables_rules(vmchain) @@ -1179,7 +1183,7 @@ def get_rule_logs_for_vms(session, args): hostrec = session.xenapi.host.get_record(thishost) vms = hostrec.get('resident_VMs') except: - util.SMlog("Failed to get host from uuid " + host_uuid) + logging.debug("Failed to get host from uuid " + host_uuid) return ' ' result = [] @@ -1192,7 +1196,7 @@ def get_rule_logs_for_vms(session, args): log = get_rule_log_for_vm(session, name) result.append(log) except: - util.SMlog("Failed to get rule logs, better luck next time!") + logging.debug("Failed to get rule logs, better luck next time!") return ";".join(result) @@ -1209,13 +1213,13 @@ def cleanup_rules_for_dead_vms(session): vm_rec = session.xenapi.VM.get_record(vm[0]) state = vm_rec.get('power_state') if state != 'Running' and state != 'Paused': - util.SMlog("vm " + vm_name + " is not running, cleaning up") + logging.debug("vm " + vm_name + " is not running, cleaning up") destroy_network_rules_for_vm(session, {'vmName':vm_name}) cleaned = cleaned+1 - util.SMlog("Cleaned up rules for " + str(cleaned) + " vms") + logging.debug("Cleaned up rules for " + str(cleaned) + " vms") except: - util.SMlog("Failed to cleanup rules for dead vms!") + logging.debug("Failed to cleanup rules for dead vms!") @echo @@ -1234,12 +1238,12 @@ def cleanup_rules(session, args): hostrec = session.xenapi.host.get_record(thishost[0]) vms = hostrec.get('resident_VMs') resident_vms = [session.xenapi.VM.get_name_label(x) for x in vms] - util.SMlog('cleanup_rules: found %s resident vms on this host %s' % (len(resident_vms)-1, hostname[0])) + logging.debug('cleanup_rules: found %s resident vms on this host %s' % (len(resident_vms)-1, hostname[0])) chainscmd = "iptables-save | grep '^:' | awk '{print $1}' | cut -d':' -f2 | sed 's/-def/-%s/'| sed 's/-eg//' | sort|uniq" % instance chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n') vmchains = [ch for ch in chains if 1 in [ ch.startswith(c) for c in ['r-', 'i-', 's-', 'v-', 'l-']]] - util.SMlog('cleanup_rules: found %s iptables chains for vms on this host %s' % (len(vmchains), hostname[0])) + logging.debug('cleanup_rules: found %s iptables chains for vms on this host %s' % (len(vmchains), hostname[0])) cleaned = 0 cleanup = [] for chain in vmchains: @@ -1247,16 +1251,16 @@ def cleanup_rules(session, args): if vmname not in resident_vms: vmname = chain + "-untagged" if vmname not in resident_vms: - util.SMlog("vm " + chain + " is not running on this host, cleaning up") + logging.debug("vm " + chain + " is not running on this host, cleaning up") cleanup.append(chain) for vm_name in cleanup: destroy_network_rules_for_vm(session, {'vmName':vm_name}) - util.SMlog("Cleaned up rules for " + str(len(cleanup)) + " chains") + logging.debug("Cleaned up rules for " + str(len(cleanup)) + " chains") return str(len(cleanup)) except Exception, ex: - util.SMlog("Failed to cleanup rules, reason= " + str(ex)) + logging.debug("Failed to cleanup rules, reason= " + str(ex)) return '-1'; @echo @@ -1264,7 +1268,7 @@ def check_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno): vm_name = vmName; logfilename = "/var/run/cloud/" + vm_name +".log" if not os.path.exists(logfilename): - util.SMlog("Failed to find logfile %s" %logfilename) + logging.debug("Failed to find logfile %s" %logfilename) return [True, True, True] lines = (line.rstrip() for line in open(logfilename)) @@ -1278,39 +1282,39 @@ def check_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno): [_vmName,_vmID,_vmIP,_domID,_signature,_seqno] = line.split(',') break except: - util.SMlog("Failed to parse log file for vm " + vmName) + logging.debug("Failed to parse log file for vm " + vmName) remove_rule_log_for_vm(vmName) return [True, True, True] reprogramDefault = False if (domID != _domID) or (vmID != _vmID) or (vmIP != _vmIP): - util.SMlog("Change in default info set of vm %s" % vmName) + logging.debug("Change in default info set of vm %s" % vmName) return [True, True, True] else: - util.SMlog("No change in default info set of vm %s" % vmName) + logging.debug("No change in default info set of vm %s" % vmName) reprogramChain = False rewriteLog = True if (int(seqno) > int(_seqno)): if (_signature != signature): reprogramChain = True - util.SMlog("Seqno increased from %s to %s: reprogamming "\ + logging.debug("Seqno increased from %s to %s: reprogamming "\ "ingress rules for vm %s" % (_seqno, seqno, vmName)) else: - util.SMlog("Seqno increased from %s to %s: but no change "\ + logging.debug("Seqno increased from %s to %s: but no change "\ "in signature for vm: skip programming ingress "\ "rules %s" % (_seqno, seqno, vmName)) elif (int(seqno) < int(_seqno)): - util.SMlog("Seqno decreased from %s to %s: ignoring these "\ + logging.debug("Seqno decreased from %s to %s: ignoring these "\ "ingress rules for vm %s" % (_seqno, seqno, vmName)) rewriteLog = False elif (signature != _signature): - util.SMlog("Seqno %s stayed the same but signature changed from "\ + logging.debug("Seqno %s stayed the same but signature changed from "\ "%s to %s for vm %s" % (seqno, _signature, signature, vmName)) rewriteLog = True reprogramChain = True else: - util.SMlog("Seqno and signature stayed the same: %s : ignoring these "\ + logging.debug("Seqno and signature stayed the same: %s : ignoring these "\ "ingress rules for vm %s" % (seqno, vmName)) rewriteLog = False @@ -1320,7 +1324,7 @@ def check_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno): def write_secip_log_for_vm (vmName, secIps, vmId): vm_name = vmName logfilename = "/var/run/cloud/"+vm_name+".ip" - util.SMlog("Writing log to " + logfilename) + logging.debug("Writing log to " + logfilename) logf = open(logfilename, 'w') output = ','.join([vmName, secIps, vmId]) result = True @@ -1329,7 +1333,7 @@ def write_secip_log_for_vm (vmName, secIps, vmId): logf.write(output) logf.write('\n') except: - util.SMlog("Failed to write to rule log file " + logfilename) + logging.debug("Failed to write to rule log file " + logfilename) result = False logf.close() @@ -1345,7 +1349,7 @@ def remove_secip_log_for_vm(vmName): try: os.remove(logfilename) except: - util.SMlog("Failed to delete rule log file " + logfilename) + logging.debug("Failed to delete rule log file " + logfilename) result = False return result @@ -1354,7 +1358,7 @@ def remove_secip_log_for_vm(vmName): def write_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno, vmMac='ff:ff:ff:ff:ff:ff'): vm_name = vmName logfilename = "/var/run/cloud/" + vm_name +".log" - util.SMlog("Writing log to " + logfilename) + logging.debug("Writing log to " + logfilename) logf = open(logfilename, 'w') output = ','.join([vmName, vmID, vmIP, domID, signature, seqno, vmMac]) result = True @@ -1362,7 +1366,7 @@ def write_rule_log_for_vm(vmName, vmID, vmIP, domID, signature, seqno, vmMac='ff logf.write(output) logf.write('\n') except: - util.SMlog("Failed to write to rule log file " + logfilename) + logging.debug("Failed to write to rule log file " + logfilename) result = False logf.close() @@ -1378,7 +1382,7 @@ def remove_rule_log_for_vm(vmName): try: os.remove(logfilename) except: - util.SMlog("Failed to delete rule log file " + logfilename) + logging.debug("Failed to delete rule log file " + logfilename) result = False return result @@ -1408,13 +1412,13 @@ def cache_ipset_keyword(): pass cachefile = "/var/cache/cloud/ipset.keyword" - util.SMlog("Writing ipset keyword to " + cachefile) + logging.debug("Writing ipset keyword to " + cachefile) cachef = open(cachefile, 'w') try: cachef.write(keyword) cachef.write('\n') except: - util.SMlog("Failed to write to cache file " + cachef) + logging.debug("Failed to write to cache file " + cachef) cachef.close() return keyword @@ -1425,7 +1429,7 @@ def get_ipset_keyword(): keyword = 'match-set' if not os.path.exists(cachefile): - util.SMlog("Failed to find ipset keyword cachefile %s" %cachefile) + logging.debug("Failed to find ipset keyword cachefile %s" %cachefile) keyword = cache_ipset_keyword() else: lines = (line.rstrip() for line in open(cachefile)) @@ -1458,15 +1462,15 @@ def network_rules(session, args): try: vm = session.xenapi.VM.get_by_name_label(vm_name) if len(vm) != 1: - util.SMlog("### Could not get record for vm ## " + vm_name) + logging.debug("### Could not get record for vm ## " + vm_name) return 'false' vm_rec = session.xenapi.VM.get_record(vm[0]) domid = vm_rec.get('domid') except: - util.SMlog("### Failed to get domid for vm ## " + vm_name) + logging.debug("### Failed to get domid for vm ## " + vm_name) return 'false' if domid == '-1': - util.SMlog("### Failed to get domid for vm (-1): " + vm_name) + logging.debug("### Failed to get domid for vm (-1): " + vm_name) return 'false' vif = "vif" + domid + ".0" @@ -1484,21 +1488,21 @@ def network_rules(session, args): check_rule_log_for_vm (vm_name, vm_id, vm_ip, domid, signature, seqno) if not reprogramDefault and not reprogramChain: - util.SMlog("No changes detected between current state and received state") + logging.debug("No changes detected between current state and received state") reason = 'seqno_same_sig_same' if rewriteLog: reason = 'seqno_increased_sig_same' write_rule_log_for_vm(vm_name, vm_id, vm_ip, domid, signature, seqno, vm_mac) - util.SMlog("Programming network rules for vm %s seqno=%s signature=%s guestIp=%s,"\ + logging.debug("Programming network rules for vm %s seqno=%s signature=%s guestIp=%s,"\ " do nothing, reason=%s" % (vm_name, seqno, signature, vm_ip, reason)) return 'true' if not reprogramChain: - util.SMlog("###Not programming any ingress rules since no changes detected?") + logging.debug("###Not programming any ingress rules since no changes detected?") return 'true' if reprogramDefault: - util.SMlog("Change detected in vmId or vmIp or domId, resetting default rules") + logging.debug("Change detected in vmId or vmIp or domId, resetting default rules") default_network_rules(session, args) reason = 'domid_change' @@ -1508,7 +1512,7 @@ def network_rules(session, args): keyword = '--' + get_ipset_keyword() lines = rules.split(' ') - util.SMlog("Programming network rules for vm %s seqno=%s numrules=%s signature=%s guestIp=%s,"\ + logging.debug("Programming network rules for vm %s seqno=%s numrules=%s signature=%s guestIp=%s,"\ " update iptables, reason=%s" % (vm_name, seqno, len(lines), signature, vm_ip, reason)) cmds = [] @@ -1546,7 +1550,7 @@ def network_rules(session, args): ipsetname = vmchain + "_" + protocol + "_any" if ipset(ipsetname, protocol, start, end, ips) == False: - util.SMlog(" failed to create ipset for rule " + str(tokens)) + logging.debug(" failed to create ipset for rule " + str(tokens)) if protocol == 'all': iptables = ['iptables', '-I', vmchain, '-m', 'state', '--state', 'NEW', '-m', 'set', keyword, ipsetname, direction, '-j', action] @@ -1559,7 +1563,7 @@ def network_rules(session, args): iptables = ['iptables', '-I', vmchain, '-p', 'icmp', '--icmp-type', range, '-m', 'set', keyword, ipsetname, direction, '-j', action] cmds.append(iptables) - util.SMlog(iptables) + logging.debug(iptables) if allow_any and protocol != 'all': if protocol != 'icmp': @@ -1570,20 +1574,20 @@ def network_rules(session, args): range = "any" iptables = ['iptables', '-I', vmchain, '-p', 'icmp', '--icmp-type', range, '-j', action] cmds.append(iptables) - util.SMlog(iptables) + logging.debug(iptables) vmchain = chain_name(vm_name) try: util.pread2(['iptables', '-F', vmchain]) except: - util.SMlog("Ignoring failure to delete chain " + vmchain) + logging.debug("Ignoring failure to delete chain " + vmchain) util.pread2(['iptables', '-N', vmchain]) egress_vmchain = egress_chain_name(vm_name) try: util.pread2(['iptables', '-F', egress_vmchain]) except: - util.SMlog("Ignoring failure to delete chain " + egress_vmchain) + logging.debug("Ignoring failure to delete chain " + egress_vmchain) util.pread2(['iptables', '-N', egress_vmchain]) @@ -1602,7 +1606,7 @@ def network_rules(session, args): return 'true' except: - util.SMlog("Failed to network rule !") + logging.debug("Failed to network rule !") @echo def bumpUpPriority(session, args): @@ -1614,7 +1618,7 @@ def bumpUpPriority(session, args): txt = util.pread2(cmd) txt = 'success' except: - util.SMlog("bump up priority fail! ") + logging.debug("bump up priority fail! ") txt = '' return txt diff --git a/scripts/vm/hypervisor/xenserver/vmopsSnapshot b/scripts/vm/hypervisor/xenserver/vmopsSnapshot index 00ed93af337..a9a5a72ea62 100755 --- a/scripts/vm/hypervisor/xenserver/vmopsSnapshot +++ b/scripts/vm/hypervisor/xenserver/vmopsSnapshot @@ -38,6 +38,10 @@ import xs_errors import cleanup import stat import random +import cloudstack_pluginlib as lib +import logging + +lib.setup_logging("/var/log/cloud/vmops.log") VHDUTIL = "vhd-util" VHD_PREFIX = 'VHD-' @@ -46,9 +50,9 @@ CLOUD_DIR = '/var/run/cloud_mount' def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### VMOPS enter %s ####" % name ) + logging.debug("#### VMOPS enter %s ####" % name ) res = fn(*v, **k) - util.SMlog("#### VMOPS exit %s ####" % name ) + logging.debug("#### VMOPS exit %s ####" % name ) return res return wrapped @@ -57,7 +61,7 @@ def echo(fn): def create_secondary_storage_folder(session, args): local_mount_path = None - util.SMlog("create_secondary_storage_folder, args: " + str(args)) + logging.debug("create_secondary_storage_folder, args: " + str(args)) try: try: @@ -74,11 +78,11 @@ def create_secondary_storage_folder(session, args): os.umask(current_umask) except OSError, (errno, strerror): errMsg = "create_secondary_storage_folder failed: errno: " + str(errno) + ", strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) except: errMsg = "create_secondary_storage_folder failed." - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) finally: if local_mount_path != None: @@ -93,7 +97,7 @@ def create_secondary_storage_folder(session, args): def delete_secondary_storage_folder(session, args): local_mount_path = None - util.SMlog("delete_secondary_storage_folder, args: " + str(args)) + logging.debug("delete_secondary_storage_folder, args: " + str(args)) try: try: @@ -109,11 +113,11 @@ def delete_secondary_storage_folder(session, args): os.system("rmdir " + folder) except OSError, (errno, strerror): errMsg = "delete_secondary_storage_folder failed: errno: " + str(errno) + ", strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) except: errMsg = "delete_secondary_storage_folder failed." - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) finally: if local_mount_path != None: @@ -159,16 +163,16 @@ def post_create_private_template(session, args): f.write("vhd.size=" + str(file_size) + "\n") f.write("size=" + str(file_size) + "\n") f.close() - util.SMlog("Created template.properties file") + logging.debug("Created template.properties file") # Set permissions permissions = stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH os.chmod(template_properties_install_path, permissions) - util.SMlog("Set permissions on template and template.properties") + logging.debug("Set permissions on template and template.properties") except: errMsg = "post_create_private_template failed." - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) finally: @@ -189,12 +193,12 @@ def isfile(path, isISCSI): if not exists: errMsg = "File " + path + " does not exist." - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return errMsg def copyfile(fromFile, toFile, isISCSI): - util.SMlog("Starting to copy " + fromFile + " to " + toFile) + logging.debug("Starting to copy " + fromFile + " to " + toFile) errMsg = '' try: cmd = ['dd', 'if=' + fromFile, 'of=' + toFile, 'bs=4M'] @@ -206,10 +210,10 @@ def copyfile(fromFile, toFile, isISCSI): txt = '' txt = '' errMsg = "Error while copying " + fromFile + " to " + toFile + " in secondary storage" - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) - util.SMlog("Successfully copied " + fromFile + " to " + toFile) + logging.debug("Successfully copied " + fromFile + " to " + toFile) return errMsg def chdir(path): @@ -217,9 +221,9 @@ def chdir(path): os.chdir(path) except OSError, (errno, strerror): errMsg = "Unable to chdir to " + path + " because of OSError with errno: " + str(errno) + " and strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) - util.SMlog("Chdired to " + path) + logging.debug("Chdired to " + path) return def scanParent(path): @@ -234,7 +238,7 @@ def scanParent(path): parentUUID = vhdInfo.parentUuid except: errMsg = "Could not get vhd parent of " + path - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return parentUUID @@ -247,7 +251,7 @@ def getParent(path, isISCSI): parentUUID = vhdutil.getParent(path, cleanup.FileVDI.extractUuid) except: errMsg = "Could not get vhd parent of " + path - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return parentUUID @@ -262,7 +266,7 @@ def getParentOfSnapshot(snapshotUuid, primarySRPath, isISCSI): else: baseCopyUuid = getParent(snapshotPath, isISCSI) - util.SMlog("Base copy of snapshotUuid: " + snapshotUuid + " is " + baseCopyUuid) + logging.debug("Base copy of snapshotUuid: " + snapshotUuid + " is " + baseCopyUuid) return baseCopyUuid def setParent(parent, child): @@ -271,9 +275,9 @@ def setParent(parent, child): txt = util.pread2(cmd) except: errMsg = "Unexpected error while trying to set parent of " + child + " to " + parent - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) - util.SMlog("Successfully set parent of " + child + " to " + parent) + logging.debug("Successfully set parent of " + child + " to " + parent) return def rename(originalVHD, newVHD): @@ -281,7 +285,7 @@ def rename(originalVHD, newVHD): os.rename(originalVHD, newVHD) except OSError, (errno, strerror): errMsg = "OSError while renaming " + origiinalVHD + " to " + newVHD + "with errno: " + str(errno) + " and strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return @@ -294,7 +298,7 @@ def makedirs(path): if os.path.isdir(path): return errMsg = "OSError while creating " + path + " with errno: " + str(errno) + " and strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return @@ -307,9 +311,9 @@ def mount(remoteDir, localDir): except: txt = '' errMsg = "Unexpected error while trying to mount " + remoteDir + " to " + localDir - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) - util.SMlog("Successfully mounted " + remoteDir + " to " + localDir) + logging.debug("Successfully mounted " + remoteDir + " to " + localDir) return @@ -319,10 +323,10 @@ def umount(localDir): util.pread2(cmd) except CommandException: errMsg = "CommandException raised while trying to umount " + localDir - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) - util.SMlog("Successfully unmounted " + localDir) + logging.debug("Successfully unmounted " + localDir) return def mountSnapshotsDir(secondaryStorageMountPath, localMountPointPath, path): @@ -344,7 +348,7 @@ def mountSnapshotsDir(secondaryStorageMountPath, localMountPointPath, path): # There is more than one secondary storage per zone. # And we are mounting each sec storage under a zone-specific directory # So two secondary storage snapshot dirs will never get mounted on the same point on the same XenServer. - util.SMlog("The remote snapshots directory has already been mounted on " + localMountPointPath) + logging.debug("The remote snapshots directory has already been mounted on " + localMountPointPath) else: mount(snapshotsDir, localMountPointPath) @@ -357,11 +361,11 @@ def unmountAll(path): try: for dir in os.listdir(path): if dir.isdigit(): - util.SMlog("Unmounting Sub-Directory: " + dir) + logging.debug("Unmounting Sub-Directory: " + dir) localMountPointPath = os.path.join(path, dir) umount(localMountPointPath) except: - util.SMlog("Ignoring the error while trying to unmount the snapshots dir") + logging.debug("Ignoring the error while trying to unmount the snapshots dir") @echo def unmountSnapshotsDir(session, args): @@ -372,7 +376,7 @@ def unmountSnapshotsDir(session, args): try: umount(localMountPointPath) except: - util.SMlog("Ignoring the error while trying to unmount the snapshots dir.") + logging.debug("Ignoring the error while trying to unmount the snapshots dir.") return "1" @@ -409,14 +413,14 @@ def makeUnavailable(uuid, primarySRPath, isISCSI): def manageAvailability(path, value): if path.__contains__("/var/run/sr-mount"): return - util.SMlog("Setting availability of " + path + " to " + value) + logging.debug("Setting availability of " + path + " to " + value) try: cmd = ['/usr/sbin/lvchange', value, path] util.pread2(cmd) except: #CommandException, (rc, cmdListStr, stderr): #errMsg = "CommandException thrown while executing: " + cmdListStr + " with return code: " + str(rc) + " and stderr: " + stderr errMsg = "Unexpected exception thrown by lvchange" - util.SMlog(errMsg) + logging.debug(errMsg) if value == "-ay": # Raise an error only if we are trying to make it available. # Just warn if we are trying to make it unavailable after the @@ -434,7 +438,7 @@ def checkVolumeAvailablility(path): manageAvailability(path, '-ay') except: errMsg = "Could not determine status of ISCSI path: " + path - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) success = False @@ -445,7 +449,7 @@ def checkVolumeAvailablility(path): # set isISCSI to true success = isVolumeAvailable(path) if success: - util.SMlog("Made vhd: " + path + " available and confirmed that it is visible") + logging.debug("Made vhd: " + path + " available and confirmed that it is visible") break # Sleep for 10 seconds before checking again. @@ -453,7 +457,7 @@ def checkVolumeAvailablility(path): # If not visible within 1 min fail if not success: - util.SMlog("Could not make vhd: " + path + " available despite waiting for 1 minute. Does it exist?") + logging.debug("Could not make vhd: " + path + " available despite waiting for 1 minute. Does it exist?") return success @@ -465,19 +469,19 @@ def isVolumeAvailable(path): status = p.communicate()[0].strip("\n") except: errMsg = "Could not determine status of ISCSI path: " + path - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return (status == "1") def getVhdParent(session, args): - util.SMlog("getParent with " + str(args)) + logging.debug("getParent with " + str(args)) primaryStorageSRUuid = args['primaryStorageSRUuid'] snapshotUuid = args['snapshotUuid'] isISCSI = getIsTrueString(args['isISCSI']) primarySRPath = getPrimarySRPath(primaryStorageSRUuid, isISCSI) - util.SMlog("primarySRPath: " + primarySRPath) + logging.debug("primarySRPath: " + primarySRPath) baseCopyUuid = getParentOfSnapshot(snapshotUuid, primarySRPath, isISCSI) @@ -485,7 +489,7 @@ def getVhdParent(session, args): def backupSnapshot(session, args): - util.SMlog("Called backupSnapshot with " + str(args)) + logging.debug("Called backupSnapshot with " + str(args)) primaryStorageSRUuid = args['primaryStorageSRUuid'] secondaryStorageMountPath = args['secondaryStorageMountPath'] snapshotUuid = args['snapshotUuid'] @@ -495,19 +499,19 @@ def backupSnapshot(session, args): path = args['path'] localMountPoint = args['localMountPoint'] primarySRPath = getPrimarySRPath(primaryStorageSRUuid, isISCSI) - util.SMlog("primarySRPath: " + primarySRPath) + logging.debug("primarySRPath: " + primarySRPath) baseCopyUuid = getParentOfSnapshot(snapshotUuid, primarySRPath, isISCSI) baseCopyVHD = getVHD(baseCopyUuid, isISCSI) baseCopyPath = os.path.join(primarySRPath, baseCopyVHD) - util.SMlog("Base copy path: " + baseCopyPath) + logging.debug("Base copy path: " + baseCopyPath) # Mount secondary storage mount path on XenServer along the path # /var/run/sr-mount//snapshots/ and create / dir # on it. backupsDir = mountSnapshotsDir(secondaryStorageMountPath, localMountPoint, path) - util.SMlog("Backups dir " + backupsDir) + logging.debug("Backups dir " + backupsDir) prevBackupUuid = prevBackupUuid.split("/")[-1] # Check existence of snapshot on primary storage isfile(baseCopyPath, isISCSI) @@ -520,7 +524,7 @@ def backupSnapshot(session, args): # copy baseCopyPath to backupsDir with new uuid backupVHD = getBackupVHD(backupUuid) backupFile = os.path.join(backupsDir, backupVHD) - util.SMlog("Back up " + baseCopyUuid + " to Secondary Storage as " + backupUuid) + logging.debug("Back up " + baseCopyUuid + " to Secondary Storage as " + backupUuid) copyfile(baseCopyPath, backupFile, isISCSI) vhdutil.setHidden(backupFile, False) @@ -536,7 +540,7 @@ def backupSnapshot(session, args): @echo def deleteSnapshotBackup(session, args): - util.SMlog("Calling deleteSnapshotBackup with " + str(args)) + logging.debug("Calling deleteSnapshotBackup with " + str(args)) secondaryStorageMountPath = args['secondaryStorageMountPath'] backupUUID = args['backupUUID'] path = args['path'] @@ -547,27 +551,27 @@ def deleteSnapshotBackup(session, args): chdir(backupsDir) backupVHD = getBackupVHD(backupUUID) - util.SMlog("checking existence of " + backupVHD) + logging.debug("checking existence of " + backupVHD) # The backupVHD is on secondary which is NFS and not ISCSI. if not os.path.isfile(backupVHD): - util.SMlog("backupVHD " + backupVHD + "does not exist. Not trying to delete it") + logging.debug("backupVHD " + backupVHD + "does not exist. Not trying to delete it") return "1" - util.SMlog("backupVHD " + backupVHD + " exists.") + logging.debug("backupVHD " + backupVHD + " exists.") # Just delete the backupVHD try: os.remove(backupVHD) except OSError, (errno, strerror): errMsg = "OSError while removing " + backupVHD + " with errno: " + str(errno) + " and strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return "1" @echo def revert_memory_snapshot(session, args): - util.SMlog("Calling revert_memory_snapshot with " + str(args)) + logging.debug("Calling revert_memory_snapshot with " + str(args)) vmName = args['vmName'] snapshotUUID = args['snapshotUUID'] oldVmUuid = args['oldVmUuid'] @@ -587,7 +591,7 @@ def revert_memory_snapshot(session, args): os.system("xe vdi-destroy uuid=" + vdiUuid) except OSError, (errno, strerror): errMsg = "OSError while reverting vm " + vmName + " to snapshot " + snapshotUUID + " with errno: " + str(errno) + " and strerr: " + strerror - util.SMlog(errMsg) + logging.debug(errMsg) raise xs_errors.XenError(errMsg) return "0" diff --git a/scripts/vm/hypervisor/xenserver/vmopspremium b/scripts/vm/hypervisor/xenserver/vmopspremium index 49349dd33a1..143aa922a8a 100755 --- a/scripts/vm/hypervisor/xenserver/vmopspremium +++ b/scripts/vm/hypervisor/xenserver/vmopspremium @@ -29,13 +29,17 @@ if os.path.exists("/usr/lib/xcp/sm"): import util import socket import perfmon +import cloudstack_pluginlib as lib +import logging + +lib.setup_logging("/var/log/cloud/vmops.log") def echo(fn): def wrapped(*v, **k): name = fn.__name__ - util.SMlog("#### VMOPS enter %s ####" % name ) + logging.debug("#### VMOPS enter %s ####" % name ) res = fn(*v, **k) - util.SMlog("#### VMOPS exit %s ####" % name ) + logging.debug("#### VMOPS exit %s ####" % name ) return res return wrapped diff --git a/scripts/vm/hypervisor/xenserver/xcposs/patch b/scripts/vm/hypervisor/xenserver/xcposs/patch index efb4a1814ec..2f902c23b44 100644 --- a/scripts/vm/hypervisor/xenserver/xcposs/patch +++ b/scripts/vm/hypervisor/xenserver/xcposs/patch @@ -70,3 +70,4 @@ deleteipAlias.sh=..,0755,/opt/cloud/bin ###add cloudstack plugin script for XCP cloudstack_plugins.conf=..,0644,/etc/xensource cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins +cloudlog=..,0644,/etc/logrotate.d diff --git a/scripts/vm/hypervisor/xenserver/xcpserver/patch b/scripts/vm/hypervisor/xenserver/xcpserver/patch index 45ff59d0618..01cd73b605c 100644 --- a/scripts/vm/hypervisor/xenserver/xcpserver/patch +++ b/scripts/vm/hypervisor/xenserver/xcpserver/patch @@ -68,3 +68,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin ###add cloudstack plugin script for XCP cloudstack_plugins.conf=..,0644,/etc/xensource cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins +cloudlog=..,0644,/etc/logrotate.d diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch index 602cb99a224..50116935789 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch @@ -69,3 +69,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin ###add cloudstack plugin script for XCP cloudstack_plugins.conf=..,0644,/etc/xensource cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins +cloudlog=..,0644,/etc/logrotate.d diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch index 8e72c0088e8..55d538edf4a 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch @@ -68,4 +68,4 @@ add_to_vcpus_params_live.sh=..,0755,/opt/cloud/bin ###add cloudstack plugin script for XCP cloudstack_plugins.conf=..,0644,/etc/xensource cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins - +cloudlog=..,0644,/etc/logrotate.d diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch index 8a0448a2009..5a648e0990f 100644 --- a/scripts/vm/hypervisor/xenserver/xenserver60/patch +++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch @@ -75,3 +75,4 @@ ovs-pvlan-vm.sh=../../../network,0755,/opt/cloud/bin ovs-pvlan-cleanup.sh=../../../network,0755,/opt/cloud/bin ovs-get-dhcp-iface.sh=..,0755,/opt/cloud/bin ovs-get-bridge.sh=..,0755,/opt/cloud/bin +cloudlog=..,0644,/etc/logrotate.d