mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-17 02:53:18 +01:00
reuse session passed to plugin
This commit is contained in:
parent
0ecff8b5a2
commit
ad305ff6ac
@ -4,29 +4,15 @@
|
|||||||
|
|
||||||
import os, sys, time
|
import os, sys, time
|
||||||
import XenAPIPlugin
|
import XenAPIPlugin
|
||||||
import XenAPI
|
|
||||||
sys.path.append("/opt/xensource/sm/")
|
sys.path.append("/opt/xensource/sm/")
|
||||||
import SR, VDI, SRCommand, util, lvutil
|
import util
|
||||||
from util import CommandException
|
from util import CommandException
|
||||||
import shutil
|
|
||||||
import vhdutil
|
|
||||||
import lvhdutil
|
|
||||||
import subprocess
|
|
||||||
from lvmcache import LVMCache
|
|
||||||
from journaler import Journaler
|
|
||||||
from lock import Lock
|
|
||||||
import errno
|
|
||||||
import subprocess
|
|
||||||
import xs_errors
|
|
||||||
import cleanup
|
|
||||||
import hostvmstats
|
import hostvmstats
|
||||||
import socket
|
import socket
|
||||||
import stat
|
import stat
|
||||||
import random
|
|
||||||
import base64
|
import base64
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
def echo(fn):
|
def echo(fn):
|
||||||
def wrapped(*v, **k):
|
def wrapped(*v, **k):
|
||||||
name = fn.__name__
|
name = fn.__name__
|
||||||
@ -36,23 +22,15 @@ def echo(fn):
|
|||||||
return res
|
return res
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def get_xapi_session():
|
|
||||||
session = XenAPI.xapi_local();
|
|
||||||
session.login_with_password("","")
|
|
||||||
return session
|
|
||||||
|
|
||||||
@echo
|
@echo
|
||||||
def gethostvmstats(session, args):
|
def gethostvmstats(session, args):
|
||||||
collect_host_stats = args['collectHostStats']
|
collect_host_stats = args['collectHostStats']
|
||||||
consolidation_function = args['consolidationFunction']
|
consolidation_function = args['consolidationFunction']
|
||||||
interval = args['interval']
|
interval = args['interval']
|
||||||
start_time = args['startTime']
|
start_time = args['startTime']
|
||||||
session = get_xapi_session()
|
|
||||||
result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
|
result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@echo
|
@echo
|
||||||
def setup_iscsi(session, args):
|
def setup_iscsi(session, args):
|
||||||
uuid=args['uuid']
|
uuid=args['uuid']
|
||||||
@ -63,7 +41,6 @@ def setup_iscsi(session, args):
|
|||||||
txt = ''
|
txt = ''
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
|
||||||
@echo
|
@echo
|
||||||
def getvncport(session, args):
|
def getvncport(session, args):
|
||||||
domid = args['domID']
|
domid = args['domID']
|
||||||
@ -77,7 +54,6 @@ def getvncport(session, args):
|
|||||||
txt = util.pread2(cmd)
|
txt = util.pread2(cmd)
|
||||||
except:
|
except:
|
||||||
txt = ''
|
txt = ''
|
||||||
|
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
@echo
|
@echo
|
||||||
@ -354,8 +330,7 @@ def networkUsage(session, args):
|
|||||||
|
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def get_private_nic( args):
|
def get_private_nic(session, args):
|
||||||
session = get_xapi_session()
|
|
||||||
vms = session.xenapi.VM.get_all()
|
vms = session.xenapi.VM.get_all()
|
||||||
host_uuid = args.get('host_uuid')
|
host_uuid = args.get('host_uuid')
|
||||||
host = session.xenapi.host.get_by_uuid(host_uuid)
|
host = session.xenapi.host.get_by_uuid(host_uuid)
|
||||||
@ -383,7 +358,7 @@ def can_bridge_firewall(session, args):
|
|||||||
util.pread2(['iptables', '-D', 'FORWARD', '-j', 'RH-Firewall-1-INPUT'])
|
util.pread2(['iptables', '-D', 'FORWARD', '-j', 'RH-Firewall-1-INPUT'])
|
||||||
except:
|
except:
|
||||||
util.SMlog('Chain BRIDGE-FIREWALL already exists')
|
util.SMlog('Chain BRIDGE-FIREWALL already exists')
|
||||||
privnic = get_private_nic(args)
|
privnic = get_private_nic(session,args)
|
||||||
result = 'true'
|
result = 'true'
|
||||||
try:
|
try:
|
||||||
util.pread2(['/bin/bash', '-c', 'iptables -n -L FORWARD | grep BRIDGE-FIREWALL'])
|
util.pread2(['/bin/bash', '-c', 'iptables -n -L FORWARD | grep BRIDGE-FIREWALL'])
|
||||||
@ -398,8 +373,8 @@ def can_bridge_firewall(session, args):
|
|||||||
if not os.path.exists('/var/run/cloud'):
|
if not os.path.exists('/var/run/cloud'):
|
||||||
os.makedirs('/var/run/cloud')
|
os.makedirs('/var/run/cloud')
|
||||||
|
|
||||||
cleanup_rules_for_dead_vms()
|
cleanup_rules_for_dead_vms(session)
|
||||||
cleanup_rules()
|
cleanup_rules(session)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -804,8 +779,6 @@ def get_rule_log_for_vm(session, vmName):
|
|||||||
def get_rule_logs_for_vms(session, args):
|
def get_rule_logs_for_vms(session, args):
|
||||||
host_uuid = args.pop('host_uuid')
|
host_uuid = args.pop('host_uuid')
|
||||||
try:
|
try:
|
||||||
session = get_xapi_session()
|
|
||||||
|
|
||||||
thishost = session.xenapi.host.get_by_uuid(host_uuid)
|
thishost = session.xenapi.host.get_by_uuid(host_uuid)
|
||||||
hostrec = session.xenapi.host.get_record(thishost)
|
hostrec = session.xenapi.host.get_record(thishost)
|
||||||
vms = hostrec.get('resident_VMs')
|
vms = hostrec.get('resident_VMs')
|
||||||
@ -828,9 +801,8 @@ def get_rule_logs_for_vms(session, args):
|
|||||||
return ";".join(result)
|
return ";".join(result)
|
||||||
|
|
||||||
@echo
|
@echo
|
||||||
def cleanup_rules_for_dead_vms():
|
def cleanup_rules_for_dead_vms(session):
|
||||||
try:
|
try:
|
||||||
session = get_xapi_session()
|
|
||||||
vms = session.xenapi.VM.get_all()
|
vms = session.xenapi.VM.get_all()
|
||||||
cleaned = 0
|
cleaned = 0
|
||||||
for vm_name in [session.xenapi.VM.get_name_label(x) for x in vms]:
|
for vm_name in [session.xenapi.VM.get_name_label(x) for x in vms]:
|
||||||
@ -852,10 +824,8 @@ def cleanup_rules_for_dead_vms():
|
|||||||
|
|
||||||
|
|
||||||
@echo
|
@echo
|
||||||
def cleanup_rules():
|
def cleanup_rules(session):
|
||||||
try:
|
try:
|
||||||
session = get_xapi_session()
|
|
||||||
|
|
||||||
chainscmd = "iptables-save | grep '^:' | grep -v '.*-def' | awk '{print $1}' | cut -d':' -f2"
|
chainscmd = "iptables-save | grep '^:' | grep -v '.*-def' | awk '{print $1}' | cut -d':' -f2"
|
||||||
chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n')
|
chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n')
|
||||||
cleaned = 0
|
cleaned = 0
|
||||||
@ -948,7 +918,6 @@ def remove_rule_log_for_vm(vmName):
|
|||||||
@echo
|
@echo
|
||||||
def network_rules(session, args):
|
def network_rules(session, args):
|
||||||
try:
|
try:
|
||||||
session = get_xapi_session()
|
|
||||||
vm_name = args.get('vmName')
|
vm_name = args.get('vmName')
|
||||||
vmName = vm_name
|
vmName = vm_name
|
||||||
vm_ip = args.get('vmIP')
|
vm_ip = args.get('vmIP')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user