mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 18:43:26 +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 XenAPIPlugin
|
||||
import XenAPI
|
||||
sys.path.append("/opt/xensource/sm/")
|
||||
import SR, VDI, SRCommand, util, lvutil
|
||||
import util
|
||||
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 socket
|
||||
import stat
|
||||
import random
|
||||
import base64
|
||||
import tempfile
|
||||
|
||||
|
||||
def echo(fn):
|
||||
def wrapped(*v, **k):
|
||||
name = fn.__name__
|
||||
@ -36,23 +22,15 @@ def echo(fn):
|
||||
return res
|
||||
return wrapped
|
||||
|
||||
|
||||
def get_xapi_session():
|
||||
session = XenAPI.xapi_local();
|
||||
session.login_with_password("","")
|
||||
return session
|
||||
|
||||
@echo
|
||||
def gethostvmstats(session, args):
|
||||
collect_host_stats = args['collectHostStats']
|
||||
consolidation_function = args['consolidationFunction']
|
||||
interval = args['interval']
|
||||
start_time = args['startTime']
|
||||
session = get_xapi_session()
|
||||
result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
|
||||
return result
|
||||
|
||||
|
||||
@echo
|
||||
def setup_iscsi(session, args):
|
||||
uuid=args['uuid']
|
||||
@ -63,7 +41,6 @@ def setup_iscsi(session, args):
|
||||
txt = ''
|
||||
return txt
|
||||
|
||||
|
||||
@echo
|
||||
def getvncport(session, args):
|
||||
domid = args['domID']
|
||||
@ -77,7 +54,6 @@ def getvncport(session, args):
|
||||
txt = util.pread2(cmd)
|
||||
except:
|
||||
txt = ''
|
||||
|
||||
return txt
|
||||
|
||||
@echo
|
||||
@ -354,8 +330,7 @@ def networkUsage(session, args):
|
||||
|
||||
return txt
|
||||
|
||||
def get_private_nic( args):
|
||||
session = get_xapi_session()
|
||||
def get_private_nic(session, args):
|
||||
vms = session.xenapi.VM.get_all()
|
||||
host_uuid = args.get('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'])
|
||||
except:
|
||||
util.SMlog('Chain BRIDGE-FIREWALL already exists')
|
||||
privnic = get_private_nic(args)
|
||||
privnic = get_private_nic(session,args)
|
||||
result = 'true'
|
||||
try:
|
||||
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'):
|
||||
os.makedirs('/var/run/cloud')
|
||||
|
||||
cleanup_rules_for_dead_vms()
|
||||
cleanup_rules()
|
||||
cleanup_rules_for_dead_vms(session)
|
||||
cleanup_rules(session)
|
||||
|
||||
return result
|
||||
|
||||
@ -804,8 +779,6 @@ def get_rule_log_for_vm(session, vmName):
|
||||
def get_rule_logs_for_vms(session, args):
|
||||
host_uuid = args.pop('host_uuid')
|
||||
try:
|
||||
session = get_xapi_session()
|
||||
|
||||
thishost = session.xenapi.host.get_by_uuid(host_uuid)
|
||||
hostrec = session.xenapi.host.get_record(thishost)
|
||||
vms = hostrec.get('resident_VMs')
|
||||
@ -828,9 +801,8 @@ def get_rule_logs_for_vms(session, args):
|
||||
return ";".join(result)
|
||||
|
||||
@echo
|
||||
def cleanup_rules_for_dead_vms():
|
||||
def cleanup_rules_for_dead_vms(session):
|
||||
try:
|
||||
session = get_xapi_session()
|
||||
vms = session.xenapi.VM.get_all()
|
||||
cleaned = 0
|
||||
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
|
||||
def cleanup_rules():
|
||||
def cleanup_rules(session):
|
||||
try:
|
||||
session = get_xapi_session()
|
||||
|
||||
chainscmd = "iptables-save | grep '^:' | grep -v '.*-def' | awk '{print $1}' | cut -d':' -f2"
|
||||
chains = util.pread2(['/bin/bash', '-c', chainscmd]).split('\n')
|
||||
cleaned = 0
|
||||
@ -948,7 +918,6 @@ def remove_rule_log_for_vm(vmName):
|
||||
@echo
|
||||
def network_rules(session, args):
|
||||
try:
|
||||
session = get_xapi_session()
|
||||
vm_name = args.get('vmName')
|
||||
vmName = vm_name
|
||||
vm_ip = args.get('vmIP')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user