mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 01:32:18 +02:00
Add Python flake8 linting for W291 trailing whitespace with Super-Linter (#4687)
* refactor: remove trailing whitespace from Python files * Add the GitHub Super-Linter Add Python flake8 linting for W291 trailing whitespace * Add licenses
This commit is contained in:
parent
add657a899
commit
182899d0b5
19
.github/linters/.flake8
vendored
Normal file
19
.github/linters/.flake8
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
[flake8]
|
||||
select = W291
|
||||
31
.github/workflows/linter.yml
vendored
Normal file
31
.github/workflows/linter.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
name: Lint Code Base
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: GitHub Super Linter
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: github/super-linter@v4
|
||||
env:
|
||||
VALIDATE_PYTHON_FLAKE8: true
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Created on Aug 2, 2010
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Created on Aug 2, 2010
|
||||
@ -26,16 +26,16 @@ import sys
|
||||
import cloudapis as apis
|
||||
import cloudtool.utils as utils
|
||||
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
|
||||
|
||||
#import ipdb; ipdb.set_trace()
|
||||
if argv == None:
|
||||
argv = sys.argv
|
||||
|
||||
prelim_args = [ x for x in argv[0:] if not x.startswith('-') ]
|
||||
parser = utils.get_parser()
|
||||
|
||||
|
||||
api = __import__("cloudapis")
|
||||
apis = getattr(api, "implementor")
|
||||
if len(prelim_args) == 1:
|
||||
@ -44,20 +44,20 @@ def main(argv=None):
|
||||
|
||||
command = utils.lookup_command_in_api(apis,prelim_args[1])
|
||||
if not command: parser.error("command %r not supported by the %s API"%(prelim_args[1],prelim_args[0]))
|
||||
|
||||
argv = argv[1:]
|
||||
|
||||
argv = argv[1:]
|
||||
if len(argv) == 1:
|
||||
argv.append("--help")
|
||||
|
||||
parser = utils.get_parser(apis.__init__,command)
|
||||
opts,args,api_optionsdict,cmd_optionsdict = parser.parse_args(argv)
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
api = apis(**api_optionsdict)
|
||||
except utils.OptParseError as e:
|
||||
parser.error(str(e))
|
||||
|
||||
|
||||
command = utils.lookup_command_in_api(api,args[0])
|
||||
|
||||
# we now discard the first two arguments as those necessarily are the api and command names
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Created on Aug 2, 2010
|
||||
@ -48,28 +48,28 @@ class MyOptionParser(OptionParser):
|
||||
error("%s: %s\n" % (self.get_prog_name(),msg))
|
||||
self.print_usage(sys.stderr)
|
||||
self.exit(os.EX_USAGE)
|
||||
|
||||
|
||||
def parse_args(self,*args,**kwargs):
|
||||
options,arguments = OptionParser.parse_args(self,*args,**kwargs)
|
||||
|
||||
|
||||
def prune_options(options,alist):
|
||||
"""Given 'options' -- a list of arguments to OptionParser.add_option,
|
||||
and a set of optparse Values, return a dictionary of only those values
|
||||
that apply exclusively to 'options'"""
|
||||
return dict( [ (k,getattr(options,k)) for k in dir(options) if k in alist ] )
|
||||
|
||||
|
||||
api_options = prune_options(options,self.api_dests)
|
||||
cmd_options = prune_options(options,self.cmd_dests)
|
||||
|
||||
|
||||
return options,arguments,api_options,cmd_options
|
||||
|
||||
|
||||
def get_parser(api_callable=None,cmd_callable=None): # this should probably be the __init__ method of myoptionparser
|
||||
|
||||
|
||||
def getdefaulttag(default):
|
||||
if default is not None: return " [Default: %default]"
|
||||
return ''
|
||||
|
||||
|
||||
def get_arguments_and_options(callable):
|
||||
"""Infers and returns arguments and options based on a callable's signature.
|
||||
Cooperates with decorator @describe"""
|
||||
@ -96,18 +96,18 @@ def get_parser(api_callable=None,cmd_callable=None): # this should probably be t
|
||||
return arguments,options
|
||||
|
||||
basic_usage = "usage: %prog [options...] "
|
||||
|
||||
|
||||
api_name = "<api>"
|
||||
cmd_name = "<command>"
|
||||
description = "%prog is a command-line tool to access several cloud APIs."
|
||||
arguments = ''
|
||||
argexp = ""
|
||||
|
||||
|
||||
if api_callable:
|
||||
api_name = api_callable.__module__.split(".")[-1].replace("_","-")
|
||||
api_arguments,api_options = get_arguments_and_options(api_callable)
|
||||
assert len(api_arguments) is 0 # no mandatory arguments for class initializers
|
||||
|
||||
|
||||
if cmd_callable:
|
||||
cmd_name = cmd_callable.__name__.replace("_","-")
|
||||
cmd_arguments,cmd_options = get_arguments_and_options(cmd_callable)
|
||||
@ -115,18 +115,18 @@ def get_parser(api_callable=None,cmd_callable=None): # this should probably be t
|
||||
arguments = " " + " ".join( [ s[0].upper() for s in cmd_arguments ] )
|
||||
argexp = "\n\nArguments:\n" + "\n".join ( " %s\n %s"%(s.upper(),u) for s,u in cmd_arguments )
|
||||
description = cmd_callable.__doc__
|
||||
|
||||
|
||||
api_command = "%s %s"%(api_name,cmd_name)
|
||||
|
||||
if description: description = "\n\n" + description
|
||||
else: description = ''
|
||||
|
||||
|
||||
usage = basic_usage + api_command + arguments + description + argexp
|
||||
|
||||
parser = MyOptionParser(usage=usage, add_help_option=False)
|
||||
|
||||
|
||||
parser.add_option('--help', action="help")
|
||||
|
||||
|
||||
group = parser.add_option_group("General options")
|
||||
group.add_option('-v', '--verbose', dest="verbose", help="Print extra output")
|
||||
|
||||
@ -136,14 +136,14 @@ def get_parser(api_callable=None,cmd_callable=None): # this should probably be t
|
||||
for a in api_options:
|
||||
group.add_option(a[0][0],**a[1])
|
||||
parser.api_dests.append(a[1]["dest"])
|
||||
|
||||
|
||||
parser.cmd_dests = []
|
||||
if cmd_callable and cmd_options:
|
||||
group = parser.add_option_group("Options for the %s command"%cmd_name)
|
||||
for a in cmd_options:
|
||||
group.add_option(a[0][0],**a[1])
|
||||
parser.cmd_dests.append(a[1]["dest"])
|
||||
|
||||
|
||||
return parser
|
||||
|
||||
def lookup_command_in_api(api,command_name):
|
||||
@ -155,7 +155,7 @@ def get_api_list(api):
|
||||
for cmd_name in dir(api):
|
||||
cmd = getattr(api,cmd_name)
|
||||
if callable(cmd) and not cmd_name.startswith("_"):
|
||||
apilist.append(cmd_name)
|
||||
apilist.append(cmd_name)
|
||||
return apilist
|
||||
|
||||
def get_command_list(api):
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Automatically generated by addcopyright.py at 01/29/2013
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Automatically generated by addcopyright.py at 01/29/2013
|
||||
'''
|
||||
Created on Jan 2, 2013
|
||||
|
||||
@ -42,14 +42,14 @@ class IPSet(object):
|
||||
def __init__(self, setname, ips):
|
||||
self.ips = ips
|
||||
self.name = setname
|
||||
|
||||
|
||||
def create(self):
|
||||
tmpname = str(uuid.uuid4()).replace('-', '')[0:30]
|
||||
sglib.ShellCmd('ipset -N %s %s' % (tmpname, self.IPSET_TYPE))()
|
||||
try:
|
||||
for ip in self.ips:
|
||||
sglib.ShellCmd('ipset -A %s %s' % (tmpname, ip))()
|
||||
|
||||
|
||||
try:
|
||||
sglib.ShellCmd('ipset -N %s %s' % (self.name, self.IPSET_TYPE))()
|
||||
cherrypy.log('created new ipset: %s' % self.name)
|
||||
@ -59,8 +59,8 @@ class IPSet(object):
|
||||
sglib.ShellCmd('ipset -W %s %s' % (tmpname, self.name))()
|
||||
sglib.ShellCmd('ipset -F %s' % tmpname)()
|
||||
sglib.ShellCmd('ipset -X %s' % tmpname)()
|
||||
|
||||
@staticmethod
|
||||
|
||||
@staticmethod
|
||||
def destroy_sets(sets_to_keep):
|
||||
sets = sglib.ShellCmd('ipset list')()
|
||||
for s in sets.split('\n'):
|
||||
@ -69,17 +69,17 @@ class IPSet(object):
|
||||
if not set_name in sets_to_keep:
|
||||
sglib.ShellCmd('ipset destroy %s' % set_name)()
|
||||
cherrypy.log('destroyed unused ipset: %s' % set_name)
|
||||
|
||||
|
||||
class SGAgent(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def _self_list(self, obj):
|
||||
if isinstance(obj, types.ListType):
|
||||
return obj
|
||||
else:
|
||||
return [obj]
|
||||
|
||||
|
||||
def set_rules(self, req):
|
||||
body = req.body
|
||||
doc = xmlobject.loads(body)
|
||||
@ -89,7 +89,7 @@ class SGAgent(object):
|
||||
vm_mac = doc.vmMac.text_
|
||||
sig = doc.signature.text_
|
||||
seq = doc.sequenceNumber.text_
|
||||
|
||||
|
||||
def parse_rules(rules, lst):
|
||||
for i in self._self_list(rules):
|
||||
r = SGRule()
|
||||
@ -100,21 +100,21 @@ class SGAgent(object):
|
||||
for ip in self._self_list(i.ip):
|
||||
r.allowed_ips.append(ip.text_)
|
||||
lst.append(r)
|
||||
|
||||
|
||||
i_rules = []
|
||||
if hasattr(doc, 'ingressRules'):
|
||||
parse_rules(doc.ingressRules, i_rules)
|
||||
|
||||
|
||||
e_rules = []
|
||||
if hasattr(doc, 'egressRules'):
|
||||
parse_rules(doc.egressRules, e_rules)
|
||||
|
||||
|
||||
def create_chain(name):
|
||||
try:
|
||||
sglib.ShellCmd('iptables -F %s' % name)()
|
||||
except Exception:
|
||||
sglib.ShellCmd('iptables -N %s' % name)()
|
||||
|
||||
|
||||
def apply_rules(rules, chainname, direction, action, current_set_names):
|
||||
create_chain(chainname)
|
||||
for r in i_rules:
|
||||
@ -122,13 +122,13 @@ class SGAgent(object):
|
||||
if '0.0.0.0/0' in r.allowed_ips:
|
||||
allow_any = True
|
||||
r.allowed_ips.remove('0.0.0.0/0')
|
||||
|
||||
|
||||
if r.allowed_ips:
|
||||
setname = '_'.join([chainname, r.protocol, r.start_port, r.end_port])
|
||||
ipset = IPSet(setname, r.allowed_ips)
|
||||
ipset.create()
|
||||
current_set_names.append(setname)
|
||||
|
||||
|
||||
if r.protocol == 'all':
|
||||
cmd = ['iptables -I', chainname, '-m state --state NEW -m set --set', setname, direction, '-j', action]
|
||||
sglib.ShellCmd(' '.join(cmd))()
|
||||
@ -142,8 +142,8 @@ class SGAgent(object):
|
||||
port_range = "any"
|
||||
cmd = ['iptables', '-I', i_chain_name, '-p', 'icmp', '--icmp-type', port_range, '-m set --set', setname, direction, '-j', action]
|
||||
sglib.ShellCmd(' '.join(cmd))()
|
||||
|
||||
|
||||
|
||||
|
||||
if allow_any and r.protocol != 'all':
|
||||
if r.protocol != 'icmp':
|
||||
port_range = ":".join([r.start_port, r.end_port])
|
||||
@ -155,36 +155,36 @@ class SGAgent(object):
|
||||
port_range = "any"
|
||||
cmd = ['iptables', '-I', i_chain_name, '-p', 'icmp', '--icmp-type', port_range, '-j', action]
|
||||
sglib.ShellCmd(' '.join(cmd))()
|
||||
|
||||
|
||||
current_sets = []
|
||||
i_chain_name = vm_name + '-in'
|
||||
apply_rules(i_rules, i_chain_name, 'src', 'ACCEPT', current_sets)
|
||||
e_chain_name = vm_name + '-eg'
|
||||
apply_rules(e_rules, e_chain_name, 'dst', 'RETURN', current_sets)
|
||||
|
||||
|
||||
if e_rules:
|
||||
sglib.ShellCmd('iptables -A %s -j RETURN' % e_chain_name)
|
||||
else:
|
||||
sglib.ShellCmd('iptables -A %s -j DROP' % e_chain_name)
|
||||
|
||||
|
||||
sglib.ShellCmd('iptables -A %s -j DROP' % i_chain_name)
|
||||
IPSet.destroy_sets(current_sets)
|
||||
|
||||
|
||||
|
||||
|
||||
def echo(self, req):
|
||||
cherrypy.log("echo: I am alive")
|
||||
|
||||
|
||||
def index(self):
|
||||
req = sglib.Request.from_cherrypy_request(cherrypy.request)
|
||||
cmd_name = req.headers['command']
|
||||
|
||||
|
||||
if not hasattr(self, cmd_name):
|
||||
raise ValueError("SecurityGroupAgent doesn't have a method called '%s'" % cmd_name)
|
||||
raise ValueError("SecurityGroupAgent doesn't have a method called '%s'" % cmd_name)
|
||||
method = getattr(self, cmd_name)
|
||||
|
||||
|
||||
return method(req)
|
||||
index.exposed = True
|
||||
|
||||
|
||||
@staticmethod
|
||||
def start():
|
||||
cherrypy.log.access_file = '/var/log/cs-securitygroup.log'
|
||||
@ -192,8 +192,8 @@ class SGAgent(object):
|
||||
cherrypy.server.socket_host = '0.0.0.0'
|
||||
cherrypy.server.socket_port = 9988
|
||||
cherrypy.quickstart(SGAgent())
|
||||
|
||||
@staticmethod
|
||||
|
||||
@staticmethod
|
||||
def stop():
|
||||
cherrypy.engine.exit()
|
||||
|
||||
@ -204,16 +204,16 @@ class SGAgentDaemon(sglib.Daemon):
|
||||
self.is_stopped = False
|
||||
self.agent = SGAgent()
|
||||
sglib.Daemon.register_atexit_hook(self._do_stop)
|
||||
|
||||
|
||||
def _do_stop(self):
|
||||
if self.is_stopped:
|
||||
return
|
||||
self.is_stopped = True
|
||||
self.agent.stop()
|
||||
|
||||
|
||||
def run(self):
|
||||
self.agent.start()
|
||||
|
||||
|
||||
def stop(self):
|
||||
self.agent.stop()
|
||||
super(SGAgentDaemon, self).stop()
|
||||
@ -223,7 +223,7 @@ def main():
|
||||
if len(sys.argv) != 2 or not sys.argv[1] in ['start', 'stop', 'restart']:
|
||||
print usage
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
cmd = sys.argv[1]
|
||||
agentdaemon = SGAgentDaemon()
|
||||
if cmd == 'start':
|
||||
@ -232,5 +232,5 @@ def main():
|
||||
agentdaemon.stop()
|
||||
else:
|
||||
agentdaemon.restart()
|
||||
|
||||
|
||||
sys.exit(0)
|
||||
|
||||
@ -18,10 +18,10 @@
|
||||
#
|
||||
# Automatically generated by addcopyright.py at 01/29/2013
|
||||
|
||||
import sys, os, time, atexit
|
||||
import traceback
|
||||
import sys, os, time, atexit
|
||||
import traceback
|
||||
import subprocess
|
||||
from signal import SIGTERM
|
||||
from signal import SIGTERM
|
||||
import cherrypy
|
||||
import copy
|
||||
|
||||
@ -80,28 +80,28 @@ class Daemon(object):
|
||||
A generic daemon class.
|
||||
|
||||
Usage: subclass the Daemon class and override the run() method
|
||||
"""
|
||||
atexit_hooks = []
|
||||
"""
|
||||
atexit_hooks = []
|
||||
|
||||
def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'):
|
||||
self.stdin = stdin
|
||||
self.stdout = stdout
|
||||
self.stderr = stderr
|
||||
self.pidfile = pidfile
|
||||
|
||||
@staticmethod
|
||||
def register_atexit_hook(hook):
|
||||
Daemon.atexit_hooks.append(hook)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _atexit():
|
||||
for hook in Daemon.atexit_hooks:
|
||||
try:
|
||||
def register_atexit_hook(hook):
|
||||
Daemon.atexit_hooks.append(hook)
|
||||
|
||||
@staticmethod
|
||||
def _atexit():
|
||||
for hook in Daemon.atexit_hooks:
|
||||
try:
|
||||
hook()
|
||||
except Exception:
|
||||
except Exception:
|
||||
content = traceback.format_exc()
|
||||
err = 'Exception when calling atexit hook[%s]\n%s' % (hook.__name__, content)
|
||||
#logger.error(err)
|
||||
err = 'Exception when calling atexit hook[%s]\n%s' % (hook.__name__, content)
|
||||
#logger.error(err)
|
||||
|
||||
def daemonize(self):
|
||||
"""
|
||||
@ -145,7 +145,7 @@ class Daemon(object):
|
||||
|
||||
# write pidfile
|
||||
Daemon.register_atexit_hook(self.delpid)
|
||||
atexit.register(Daemon._atexit)
|
||||
atexit.register(Daemon._atexit)
|
||||
pid = str(os.getpid())
|
||||
file(self.pidfile,'w').write("%s\n" % pid)
|
||||
|
||||
@ -173,12 +173,12 @@ class Daemon(object):
|
||||
sys.exit(0)
|
||||
|
||||
# Start the daemon
|
||||
self.daemonize()
|
||||
self.daemonize()
|
||||
try:
|
||||
self.run()
|
||||
except Exception:
|
||||
content = traceback.format_exc()
|
||||
#logger.error(content)
|
||||
self.run()
|
||||
except Exception:
|
||||
content = traceback.format_exc()
|
||||
#logger.error(content)
|
||||
sys.exit(1)
|
||||
|
||||
def stop(self):
|
||||
|
||||
@ -1,21 +1,21 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Automatically generated by addcopyright.py at 01/29/2013
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
# Automatically generated by addcopyright.py at 01/29/2013
|
||||
'''
|
||||
Created on Dec 25, 2012
|
||||
|
||||
@ -28,23 +28,23 @@ import types
|
||||
class XmlObject(object):
|
||||
def __init__(self, tag):
|
||||
self.__tag_name__ = tag
|
||||
|
||||
|
||||
def put_attr(self, name, val):
|
||||
val = val.strip().strip('\t')
|
||||
setattr(self, name + '_', val)
|
||||
|
||||
|
||||
def put_text(self, val):
|
||||
val = val.strip().strip('\n').strip('\t')
|
||||
if val == "":
|
||||
setattr(self, 'text_', None)
|
||||
else:
|
||||
setattr(self, 'text_', val)
|
||||
|
||||
|
||||
def put_node(self, name, val):
|
||||
if not hasattr(self, name):
|
||||
setattr(self, name, val)
|
||||
return
|
||||
|
||||
|
||||
nodes = getattr(self, name)
|
||||
if not isinstance(nodes, types.ListType):
|
||||
nodes = []
|
||||
@ -55,7 +55,7 @@ class XmlObject(object):
|
||||
else:
|
||||
nodes.append(val)
|
||||
setattr(self, name, nodes)
|
||||
|
||||
|
||||
def get(self, name, default=None):
|
||||
if hasattr(self, name):
|
||||
val = getattr(self, name)
|
||||
@ -65,7 +65,7 @@ class XmlObject(object):
|
||||
return val.text_
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.endswith('__'):
|
||||
n = name[:-1]
|
||||
@ -78,7 +78,7 @@ class XmlObject(object):
|
||||
setattr(e, 'missing_attrib', name)
|
||||
setattr(e, 'tag_name', self.__tag_name__)
|
||||
raise e
|
||||
|
||||
|
||||
|
||||
def _loads(node):
|
||||
xo = XmlObject(node.tag)
|
||||
@ -90,7 +90,7 @@ def _loads(node):
|
||||
sub_xo = _loads(n)
|
||||
xo.put_node(n.tag, sub_xo)
|
||||
return xo
|
||||
|
||||
|
||||
def loads(xmlstr):
|
||||
xmlstr = re.sub(r'xmlns=".*"', '', xmlstr)
|
||||
root = etree.fromstring(xmlstr)
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -24,7 +24,7 @@ class ConfigFileOps:
|
||||
self.op = op
|
||||
self.separator = separator
|
||||
def setState(self, state):
|
||||
self.state = state
|
||||
self.state = state
|
||||
def getState(self):
|
||||
return self.state
|
||||
|
||||
@ -32,18 +32,18 @@ class ConfigFileOps:
|
||||
self.fileName = fileName
|
||||
self.entries = []
|
||||
self.backups = []
|
||||
|
||||
|
||||
if cfg is not None:
|
||||
cfg.cfoHandlers.append(self)
|
||||
|
||||
def addEntry(self, name, value, separator="="):
|
||||
e = self.entry(name, value, "add", separator)
|
||||
self.entries.append(e)
|
||||
|
||||
|
||||
def rmEntry(self, name, value, separator="="):
|
||||
entry = self.entry(name, value, "rm", separator)
|
||||
self.entries.append(entry)
|
||||
|
||||
|
||||
def getEntry(self, name, separator="="):
|
||||
try:
|
||||
ctx = file(self.fileName).read(-1)
|
||||
@ -71,7 +71,7 @@ class ConfigFileOps:
|
||||
matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
|
||||
else:
|
||||
matchString = "^\ *" + entry.name + "\ *" + entry.value
|
||||
|
||||
|
||||
match = re.match(matchString, line)
|
||||
if match is not None:
|
||||
if entry.op == "add" and entry.separator == "=":
|
||||
@ -85,9 +85,9 @@ class ConfigFileOps:
|
||||
entry.setState("set")
|
||||
self.backups.append([line, None])
|
||||
matched = True
|
||||
break
|
||||
|
||||
if not matched:
|
||||
break
|
||||
|
||||
if not matched:
|
||||
newLines.append(line)
|
||||
|
||||
for entry in self.entries:
|
||||
@ -99,7 +99,7 @@ class ConfigFileOps:
|
||||
entry.setState("set")
|
||||
|
||||
fp.close()
|
||||
|
||||
|
||||
file(self.fileName, "w").writelines(newLines)
|
||||
|
||||
def replace_line(self, startswith,stanza,always_add=False):
|
||||
@ -123,18 +123,18 @@ class ConfigFileOps:
|
||||
return self.replace_line(startswith,stanza,always_add=True)
|
||||
|
||||
def add_lines(self, lines, addToBackup=True):
|
||||
fp = file(self.fileName).read(-1)
|
||||
fp = file(self.fileName).read(-1)
|
||||
sh = re.escape(lines)
|
||||
match = re.search(sh, fp, re.MULTILINE)
|
||||
match = re.search(sh, fp, re.MULTILINE)
|
||||
if match is not None:
|
||||
return
|
||||
|
||||
|
||||
fp += lines
|
||||
file(self.fileName, "w").write(fp)
|
||||
self.backups.append([None, lines])
|
||||
|
||||
|
||||
def replace_lines(self, src, dst, addToBackup=True):
|
||||
fp = file(self.fileName).read(-1)
|
||||
fp = file(self.fileName).read(-1)
|
||||
sh = re.escape(src)
|
||||
if dst is None:
|
||||
dst = ""
|
||||
@ -165,11 +165,11 @@ class ConfigFileOps:
|
||||
newlines.append(line)
|
||||
|
||||
file(self.fileName, "w").writelines(newlines)
|
||||
|
||||
|
||||
def backup(self):
|
||||
for oldLine, newLine in self.backups:
|
||||
if newLine is None:
|
||||
self.add_lines(oldLine, False)
|
||||
else:
|
||||
self.replace_lines(newLine, oldLine, False)
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -23,7 +23,7 @@ try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
|
||||
from OvmObjectModule import *
|
||||
import types
|
||||
import logging
|
||||
@ -55,7 +55,7 @@ def setAttrFromDict(obj, name, refDict, convertFunc=None):
|
||||
def safeSetAttr(obj, name, value):
|
||||
if not hasattr(obj, name): raise Exception("%s doesn't have attribute %s"%(obj.__class__.__name__, name))
|
||||
setattr(obj, name, value)
|
||||
|
||||
|
||||
def toAscii(jstr):
|
||||
return str(jstr).encode('ascii', 'ignore')
|
||||
|
||||
@ -68,7 +68,7 @@ def toAsciiHook(dct):
|
||||
k = toAscii(k)
|
||||
dct[k] = v
|
||||
return dct
|
||||
|
||||
|
||||
def asciiLoads(jStr):
|
||||
jStr = str(jStr).replace("'", '"').replace('False', 'false').replace('True', 'true')
|
||||
return json.loads(jStr, object_hook=toAsciiHook)
|
||||
@ -90,7 +90,7 @@ def jsonSuccessToMap(str):
|
||||
dct = json.loads(str)
|
||||
if dct['status'] != 'SUCC': raise Exception(str)
|
||||
return dct['value']
|
||||
|
||||
|
||||
def safeDictSet(obj, dct, name):
|
||||
if not hasattr(obj, name): raise Exception("%s has no attribute %s for encoding"%(obj.__class__.__name__, name))
|
||||
dct[name] = getattr(obj, name)
|
||||
@ -133,7 +133,7 @@ def execute(cmd):
|
||||
|
||||
def getDomId(vm_name):
|
||||
return execute("xm list | grep " + vm_name + " | awk '{print $2}'").strip()
|
||||
|
||||
|
||||
def raiseExceptionIfFail(res):
|
||||
if not "success" in res and not "SUCC" in res: raise Exception(res)
|
||||
|
||||
@ -156,4 +156,4 @@ def makeOwnerFileName():
|
||||
hostIp = successToMap(get_master_ip())['ip']
|
||||
ownerFileName = OWNER_FILE_PREFIX + hostIp.replace('.', '_')
|
||||
return ownerFileName
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -36,7 +36,7 @@ class OvmDiskEncoder(json.JSONEncoder):
|
||||
dct = {}
|
||||
safeDictSet(obj, dct, 'path')
|
||||
safeDictSet(obj, dct, 'type')
|
||||
return dct
|
||||
return dct
|
||||
|
||||
def fromOvmDisk(disk):
|
||||
return normalizeToGson(json.dumps(disk, cls=OvmDiskEncoder))
|
||||
@ -58,8 +58,8 @@ class OvmDisk(OvmObject):
|
||||
path = ''
|
||||
type = ''
|
||||
isIso = False
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print toOvmDisk('''{"type":"w","path":"/data/data.raw"}''')
|
||||
print toOvmDisk('''{"path":"/data/data.raw'","type":"w"}''')
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -28,7 +28,7 @@ class NoVmFoundException(Exception):
|
||||
class ShellExceutedFailedException(Exception):
|
||||
stderr = ''
|
||||
errCode = -1000
|
||||
|
||||
|
||||
def __init__(self, err, code):
|
||||
Exception.__init__(self, "%s, return code:%s"%(err, code))
|
||||
self.stderr = err
|
||||
@ -40,7 +40,7 @@ errCode = {
|
||||
"OvmDispatch.InvaildClass":OvmDispatcherStub+2,
|
||||
"OvmDispatch.InvaildFunction":OvmDispatcherStub+3,
|
||||
"OvmVm.reboot":OvmDispatcherStub+4,
|
||||
|
||||
|
||||
"OvmHost.registerAsPrimary":OvmHostErrCodeStub+1,
|
||||
"OvmHost.registerAsVmServer":OvmHostErrCodeStub+2,
|
||||
"OvmHost.ping":OvmHostErrCodeStub+3,
|
||||
@ -50,7 +50,7 @@ errCode = {
|
||||
"OvmHost.fence":OvmHostErrCodeStub+7,
|
||||
"OvmHost.setupHeartBeat":OvmHostErrCodeStub+8,
|
||||
"OvmHost.pingAnotherHost":OvmHostErrCodeStub+9,
|
||||
|
||||
|
||||
"OvmVm.create":OvmVmErrCodeStub+1,
|
||||
"OvmVm.stop":OvmVmErrCodeStub+2,
|
||||
"OvmVm.getDetails":OvmVmErrCodeStub+3,
|
||||
@ -59,7 +59,7 @@ errCode = {
|
||||
"OvmVm.register":OvmVmErrCodeStub+6,
|
||||
"OvmVm.getVncPort":OvmVmErrCodeStub+7,
|
||||
"OvmVm.detachOrAttachIso":OvmVmErrCodeStub+8,
|
||||
|
||||
|
||||
"OvmStoragePool.create":OvmStoragePoolErrCodeStub+1,
|
||||
"OvmStoragePool.getDetailsByUuid":OvmStoragePoolErrCodeStub+2,
|
||||
"OvmStoragePool.downloadTemplate":OvmStoragePoolErrCodeStub+3,
|
||||
@ -68,7 +68,7 @@ errCode = {
|
||||
"OvmStoragePool._umount":OvmStoragePoolErrCodeStub+6,
|
||||
"OvmStoragePool.copyVolume":OvmStoragePoolErrCodeStub+7,
|
||||
"OvmStoragePool.delete":OvmStoragePoolErrCodeStub+8,
|
||||
|
||||
|
||||
"OvmNetwork.createBridge":OvmNetworkErrCodeStub+1,
|
||||
"OvmNetwork.deleteBridge":OvmNetworkErrCodeStub+2,
|
||||
"OvmNetwork.createVlan":OvmNetworkErrCodeStub+3,
|
||||
@ -77,11 +77,11 @@ errCode = {
|
||||
"OvmNetwork.getBridgeByIp":OvmNetworkErrCodeStub+6,
|
||||
"OvmNetwork.createVlanBridge":OvmNetworkErrCodeStub+7,
|
||||
"OvmNetwork.deleteVlanBridge":OvmNetworkErrCodeStub+8,
|
||||
|
||||
|
||||
"OvmVolume.createDataDisk":OvmVolumeErrCodeStub+1,
|
||||
"OvmVolume.createFromTemplate":OvmVolumeErrCodeStub+2,
|
||||
"OvmVolume.destroy":OvmVolumeErrCodeStub+3,
|
||||
|
||||
|
||||
"OvmOCFS2._addNode":OvmOCFS2ErrCodeStub+1,
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -34,7 +34,7 @@ class OvmHaHeartBeat(object):
|
||||
def __init__(self, mountPoint, ip):
|
||||
self.mountPoint = mountPoint
|
||||
self.ip = ip
|
||||
|
||||
|
||||
def mark(self, file):
|
||||
timestamp = HEARTBEAT_TIMESTAMP_FORMAT % time.time()
|
||||
try:
|
||||
@ -44,7 +44,7 @@ class OvmHaHeartBeat(object):
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHaHeartBeat.mark, errmsg)
|
||||
|
||||
|
||||
def run(self):
|
||||
'''
|
||||
Constructor
|
||||
@ -56,11 +56,11 @@ class OvmHaHeartBeat(object):
|
||||
while True:
|
||||
self.mark(hearBeatFile)
|
||||
time.sleep(120)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def start(poolPath, ip):
|
||||
pidFile = join(PID_DIR, "heartbeat.pid")
|
||||
|
||||
|
||||
def isLive():
|
||||
if exists(pidFile):
|
||||
f = open(pidFile)
|
||||
@ -69,7 +69,7 @@ class OvmHaHeartBeat(object):
|
||||
if isdir("/proc/%s" % pid):
|
||||
return long(pid)
|
||||
return None
|
||||
|
||||
|
||||
def stopOldHeartBeat(pid):
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
time.sleep(5)
|
||||
@ -81,10 +81,10 @@ class OvmHaHeartBeat(object):
|
||||
pid = isLive()
|
||||
if pid != None:
|
||||
raise Exception("Cannot stop old heartbeat process %s, setup heart beat failed"%pid)
|
||||
|
||||
|
||||
def heartBeat(hb):
|
||||
hb.run()
|
||||
|
||||
|
||||
def setupHeartBeat():
|
||||
hb = OvmHaHeartBeat(poolPath, ip)
|
||||
p = Process(target=heartBeat, args=(hb,))
|
||||
@ -96,10 +96,10 @@ class OvmHaHeartBeat(object):
|
||||
pidFd.write(str(pid))
|
||||
pidFd.close()
|
||||
logger.info(OvmHaHeartBeat.start, "Set up heart beat successfully, pid is %s" % pid)
|
||||
|
||||
|
||||
pid = isLive()
|
||||
if pid != None:
|
||||
stopOldHeartBeat(pid)
|
||||
|
||||
|
||||
setupHeartBeat()
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -44,11 +44,11 @@ class OvmHostEncoder(json.JSONEncoder):
|
||||
safeDictSet(obj, dct, 'dom0KernelVersion')
|
||||
safeDictSet(obj, dct, 'hypervisorVersion')
|
||||
return dct
|
||||
|
||||
|
||||
|
||||
def fromOvmHost(host):
|
||||
return normalizeToGson(json.dumps(host, cls=OvmHostEncoder))
|
||||
|
||||
|
||||
class OvmHost(OvmObject):
|
||||
masterIp = ''
|
||||
cpuNum = 0
|
||||
@ -64,7 +64,7 @@ class OvmHost(OvmObject):
|
||||
def _getVmPathFromPrimaryStorage(self, vmName):
|
||||
'''
|
||||
we don't have a database to store vm states, so there is no way to retrieve information of a vm
|
||||
when it was already stopped. The trick is to try to find the vm path in primary storage then we
|
||||
when it was already stopped. The trick is to try to find the vm path in primary storage then we
|
||||
can read information from its configure file.
|
||||
'''
|
||||
mps = OvmStoragePool()._getAllMountPoints()
|
||||
@ -76,18 +76,18 @@ class OvmHost(OvmObject):
|
||||
logger.error(self._getVmPathFromPrimaryStorage, "Cannot find link for %s in any primary storage, the vm was really gone!"%vmName)
|
||||
raise Exception("Cannot find link for %s in any primary storage, the vm was really gone!"%vmName)
|
||||
return vmPath
|
||||
|
||||
|
||||
def _vmNameToPath(self, vmName):
|
||||
# the xen_get_vm_path always sucks!!!
|
||||
#return successToMap((vmName))['path']
|
||||
return self._getVmPathFromPrimaryStorage(vmName)
|
||||
|
||||
|
||||
def _getAllDomains(self):
|
||||
stdout = timeout_command(["xm", "list"])
|
||||
l = [ line.split()[:2] for line in stdout.splitlines() ]
|
||||
l = [ (name, id) for (name, id) in l if name not in ("Name", "Domain-0") ]
|
||||
return l
|
||||
|
||||
|
||||
def _getDomainIdByName(self, vmName):
|
||||
l = self._getAllDomains()
|
||||
for name, id in l:
|
||||
@ -108,7 +108,7 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.registerAsPrimary, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.registerAsPrimary), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def registerAsVmServer(hostname, username="oracle", password="password", port=8899, isSsl=False):
|
||||
try:
|
||||
@ -121,7 +121,7 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.registerAsVmServer, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.registerAsVmServer), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def ping(hostname):
|
||||
try:
|
||||
@ -133,7 +133,7 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.ping, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.ping, errmsg))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getDetails():
|
||||
try:
|
||||
@ -166,7 +166,7 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.getDetails, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getDetails), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getPerformanceStats(bridgeName):
|
||||
try:
|
||||
@ -188,20 +188,20 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.getPerformanceStats, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getPerformanceStats), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getAllVms():
|
||||
def scanStoppedVmOnPrimaryStorage(vms):
|
||||
def isMyVmDirLink(path):
|
||||
return (islink(path) and exists(join(path, 'vm.cfg')) and ('-' in basename(path)) and (exists(join(path, makeOwnerFileName()))))
|
||||
|
||||
|
||||
mps = OvmStoragePool()._getAllMountPoints()
|
||||
for mountPoint in mps:
|
||||
runningPool = join(mountPoint, 'running_pool')
|
||||
if not exists(runningPool):
|
||||
logger.debug(OvmHost.getAllVms, "Primary storage %s not existing, skip it. this should be first getAllVms() called from Ovm resource configure"%runningPool)
|
||||
continue
|
||||
|
||||
|
||||
for dir in os.listdir(runningPool):
|
||||
vmDir = join(runningPool, dir)
|
||||
if not isMyVmDirLink(vmDir):
|
||||
@ -210,11 +210,11 @@ class OvmHost(OvmObject):
|
||||
if vms.has_key(dir):
|
||||
logger.debug(OvmHost.getAllVms, "%s is already in running list, skip it"%dir)
|
||||
continue
|
||||
|
||||
|
||||
logger.debug(OvmHost.getAllVms, "Found a stopped vm %s on primary storage %s, report it to management server" % (dir, mountPoint))
|
||||
vms[dir] = "DOWN"
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
l = OvmHost()._getAllDomains()
|
||||
dct = {}
|
||||
@ -227,7 +227,7 @@ class OvmHost(OvmObject):
|
||||
except Exception, e:
|
||||
logger.debug(OvmHost.getAllVms, "Cannot find link for %s on primary storage, treat it as Error"%name)
|
||||
dct[name] = 'ERROR'
|
||||
|
||||
|
||||
scanStoppedVmOnPrimaryStorage(dct)
|
||||
rs = toGson(dct)
|
||||
logger.info(OvmHost.getAllVms, rs)
|
||||
@ -236,13 +236,13 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.getAllVms, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.getAllVms), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def fence(ip):
|
||||
# try 3 times to avoid race condition that read when heartbeat file is being written
|
||||
def getTimeStamp(hbFile):
|
||||
for i in range(1, 3):
|
||||
f = open(hbFile, 'r')
|
||||
f = open(hbFile, 'r')
|
||||
str = f.readline()
|
||||
items = re.findall(HEARTBEAT_TIMESTAMP_PATTERN, str)
|
||||
if len(items) == 0:
|
||||
@ -253,7 +253,7 @@ class OvmHost(OvmObject):
|
||||
f.close()
|
||||
timestamp = items[0]
|
||||
return timestamp.lstrip('<timestamp>').rstrip('</timestamp>')
|
||||
|
||||
|
||||
# totally check in 6 mins, the update frequency is 2 mins
|
||||
def check(hbFile):
|
||||
for i in range(1, 6):
|
||||
@ -263,7 +263,7 @@ class OvmHost(OvmObject):
|
||||
if ts != nts: return True
|
||||
else: logger.debug(OvmHost.fence, '%s is not updated, old value=%s, will retry %s times'%(hbFile, ts, 6-i))
|
||||
return False
|
||||
|
||||
|
||||
try:
|
||||
mountpoints = OvmStoragePool()._getAllMountPoints()
|
||||
hbFile = None
|
||||
@ -272,7 +272,7 @@ class OvmHost(OvmObject):
|
||||
if exists(p):
|
||||
hbFile = p
|
||||
break
|
||||
|
||||
|
||||
if not hbFile: raise Exception('Can not find heartbeat file for %s in pools %s'%(ip, mountpoints))
|
||||
rs = toGson({"isLive":check(hbFile)})
|
||||
logger.debug(OvmHost.fence, rs)
|
||||
@ -281,7 +281,7 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.fence, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.fence), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def setupHeartBeat(poolUuid, ip):
|
||||
try:
|
||||
@ -292,7 +292,7 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.setupHeartBeat, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.setupHeartBeat), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def pingAnotherHost(ip):
|
||||
try:
|
||||
@ -302,6 +302,6 @@ class OvmHost(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmHost.pingAnotherHost, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmHost, OvmHost.pingAnotherHost), errmsg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print OvmHost.getAllVms()
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -32,22 +32,22 @@ class OvmLogger(object):
|
||||
'''
|
||||
self.className = className
|
||||
self.logger = logging.getLogger(className)
|
||||
|
||||
|
||||
def info(self, func, msg=None):
|
||||
assert callable(func), "%s is not a function"%func
|
||||
fmt = "[%s.%s]: "%(self.className, func.__name__)
|
||||
self.logger.info("%s%s"%(fmt,msg))
|
||||
|
||||
|
||||
def debug(self, func, msg=None):
|
||||
assert callable(func), "%s is not a function"%func
|
||||
fmt = "[%s.%s]: "%(self.className, func.__name__)
|
||||
self.logger.debug("%s%s"%(fmt,msg))
|
||||
|
||||
|
||||
def error(self, func, msg=None):
|
||||
assert callable(func), "%s is not a function"%func
|
||||
fmt = "[%s.%s]: "%(self.className, func.__name__)
|
||||
self.logger.error("%s%s"%(fmt,msg))
|
||||
|
||||
|
||||
def warning(self, func, msg=None):
|
||||
assert callable(func), "%s is not a function"%func
|
||||
fmt = "[%s.%s]: "%(self.className, func.__name__)
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -18,7 +18,7 @@ from OvmCommonModule import *
|
||||
import traceback
|
||||
import time
|
||||
import re
|
||||
|
||||
|
||||
logger = OvmLogger("OvmNetwork")
|
||||
|
||||
class Filter:
|
||||
@ -32,7 +32,7 @@ class Filter:
|
||||
class Parser(object):
|
||||
'''
|
||||
classdocs
|
||||
'''
|
||||
'''
|
||||
def findall(self, pattern, samples):
|
||||
"""
|
||||
@param pattern: search pattern
|
||||
@ -47,7 +47,7 @@ class Parser(object):
|
||||
for item in items:
|
||||
result.append(item)
|
||||
return result
|
||||
|
||||
|
||||
def checkPattern(self, pattern, cmd_result):
|
||||
"""
|
||||
@param pattern: search pattern
|
||||
@ -59,10 +59,10 @@ class Parser(object):
|
||||
if len(items) > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def search(self, cmd_result, pattern):
|
||||
return None
|
||||
|
||||
|
||||
class OvmVlanDecoder(json.JSONDecoder):
|
||||
def decode(self, jStr):
|
||||
deDict = asciiLoads(jStr)
|
||||
@ -79,7 +79,7 @@ class OvmVlanEncoder(json.JSONEncoder):
|
||||
safeDictSet(obj, dct, 'vid')
|
||||
safeDictSet(obj, dct, 'pif')
|
||||
return dct
|
||||
|
||||
|
||||
def toOvmVlan(jStr):
|
||||
return json.loads(jStr, cls=OvmVlanDecoder)
|
||||
|
||||
@ -102,7 +102,7 @@ class OvmBridgeEncoder(json.JSONEncoder):
|
||||
safeDictSet(obj, dct, 'attach')
|
||||
safeDictSet(obj, dct, 'interfaces')
|
||||
return dct
|
||||
|
||||
|
||||
def toOvmBridge(jStr):
|
||||
return json.loads(jStr, cls=OvmBridgeDecoder)
|
||||
|
||||
@ -120,7 +120,7 @@ class OvmBridge(OvmInterface):
|
||||
attach = ''
|
||||
interfaces = []
|
||||
|
||||
|
||||
|
||||
class OvmNetwork(OvmObject):
|
||||
'''
|
||||
Network
|
||||
@ -137,7 +137,7 @@ class OvmNetwork(OvmObject):
|
||||
@property
|
||||
def bridges(self):
|
||||
return self._getInterfaces("bridge")
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.Parser = Parser()
|
||||
|
||||
@ -146,51 +146,51 @@ class OvmNetwork(OvmObject):
|
||||
@param jsonString : parameter from client side
|
||||
@return : succ xxxxx
|
||||
ex. jsonString => {vid:100, pif:eth0}
|
||||
ex. return =>
|
||||
ex. return =>
|
||||
"""
|
||||
|
||||
|
||||
#Pre-condition
|
||||
#check Physical Interface Name
|
||||
if vlan.pif not in self.pifs.keys():
|
||||
if vlan.pif not in self.pifs.keys():
|
||||
msg = "Physical Interface(%s) does not exist" % vlan.pif
|
||||
logger.debug(self._createVlan, msg)
|
||||
raise Exception(msg)
|
||||
|
||||
#Pre-condition
|
||||
#Pre-condition
|
||||
#check Vlan Interface Name
|
||||
ifName = "%s.%s" % (vlan.pif, vlan.vid)
|
||||
if ifName in self.vlans.keys():
|
||||
msg = "Vlan Interface(%s) already exist, return it" % ifName
|
||||
logger.debug(self._createVlan, msg)
|
||||
return self.vlans[ifName]
|
||||
|
||||
|
||||
doCmd(['vconfig', 'add', vlan.pif, vlan.vid])
|
||||
self.bringUP(ifName)
|
||||
logger.debug(self._createVlan, "Create vlan %s successfully"%ifName)
|
||||
return self.vlans[ifName]
|
||||
|
||||
|
||||
def _deleteVlan(self, name):
|
||||
if name not in self.vlans.keys():
|
||||
raise Exception("No vlan device %s found"%name)
|
||||
|
||||
|
||||
vlan = self.vlans[name]
|
||||
self.bringDown(vlan.name)
|
||||
doCmd(['vconfig', 'rem', vlan.name])
|
||||
logger.debug(self._deleteVlan, "Delete vlan %s successfully"%vlan.name)
|
||||
|
||||
|
||||
|
||||
|
||||
def _createBridge(self, bridge):
|
||||
"""
|
||||
@return : success
|
||||
ex. {bridge:xapi100, attach:eth0.100}
|
||||
create bridge interface, and attached it
|
||||
create bridge interface, and attached it
|
||||
cmd 1: ip link add bridge
|
||||
cmd 2: ip link set dev
|
||||
"""
|
||||
|
||||
|
||||
if "xenbr" not in bridge.name and "vlan" not in bridge.name:
|
||||
raise Exception("Invalid bridge name %s. Bridge name must be in partten xenbr/vlan, e.g. xenbr0"%bridge.name)
|
||||
|
||||
|
||||
#pre-condition
|
||||
#check Bridge Interface Name
|
||||
if bridge.name in self.bridges.keys():
|
||||
@ -200,7 +200,7 @@ class OvmNetwork(OvmObject):
|
||||
|
||||
#pre-condition
|
||||
#check attach must exist
|
||||
#possible to attach in PIF or VLAN
|
||||
#possible to attach in PIF or VLAN
|
||||
if bridge.attach not in self.vlans.keys() and bridge.attach not in self.pifs.keys():
|
||||
msg = "%s is not either pif or vlan" % bridge.attach
|
||||
logger.error(self._createBridge, msg)
|
||||
@ -211,17 +211,17 @@ class OvmNetwork(OvmObject):
|
||||
self.bringUP(bridge.name)
|
||||
logger.debug(self._createBridge, "Create bridge %s on %s successfully"%(bridge.name, bridge.attach))
|
||||
return self.bridges[bridge.name]
|
||||
|
||||
|
||||
def _getBridges(self):
|
||||
return self.bridges.keys()
|
||||
|
||||
|
||||
def _getVlans(self):
|
||||
return self.vlans.keys()
|
||||
|
||||
|
||||
def _deleteBridge(self, name):
|
||||
if name not in self.bridges.keys():
|
||||
raise Exception("Can not find bridge %s"%name)
|
||||
|
||||
|
||||
bridge = self.bridges[name]
|
||||
if bridge.attach in bridge.interfaces: bridge.interfaces.remove(bridge.attach)
|
||||
if len(bridge.interfaces) != 0:
|
||||
@ -231,7 +231,7 @@ class OvmNetwork(OvmObject):
|
||||
doCmd(['ip', 'link', 'del', bridge.name])
|
||||
logger.debug(self._deleteBridge, "Delete bridge %s successfully"%bridge.name)
|
||||
return True
|
||||
|
||||
|
||||
def _getInterfaces(self, type):
|
||||
"""
|
||||
@param type : ["pif", "bridge", "tap"]
|
||||
@ -246,7 +246,7 @@ class OvmNetwork(OvmObject):
|
||||
ifInst = OvmInterface()
|
||||
ifInst.name = dev
|
||||
ifs[dev] = ifInst
|
||||
|
||||
|
||||
elif type == "vlan":
|
||||
devs = self.Parser.findall(Filter.Network.IFNAME_VLAN, devices)
|
||||
for dev in set(devs):
|
||||
@ -256,7 +256,7 @@ class OvmNetwork(OvmObject):
|
||||
ifInst.pif = pif
|
||||
ifInst.vid = vid
|
||||
ifs[dev] = ifInst
|
||||
|
||||
|
||||
elif type == "bridge":
|
||||
devs = self.Parser.findall(Filter.Network.IFNAME_BRIDGE, devices)
|
||||
for dev in set(devs):
|
||||
@ -271,13 +271,13 @@ class OvmNetwork(OvmObject):
|
||||
ifs[dev] = ifInst
|
||||
|
||||
return ifs
|
||||
|
||||
|
||||
def bringUP(self, ifName):
|
||||
doCmd(['ifconfig', ifName, 'up'])
|
||||
|
||||
|
||||
def bringDown(self, ifName):
|
||||
doCmd(['ifconfig', ifName, 'down'])
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createBridge(jStr):
|
||||
try:
|
||||
@ -288,7 +288,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.createBridge, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.createBridge), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def deleteBridge(name):
|
||||
try:
|
||||
@ -299,7 +299,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.deleteBridge, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.deleteBridge), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getAllBridges():
|
||||
try:
|
||||
@ -311,7 +311,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.getAllBridges, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.getAllBridges), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getBridgeByIp(ip):
|
||||
try:
|
||||
@ -327,8 +327,8 @@ class OvmNetwork(OvmObject):
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.getBridgeByIp, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.getBridgeByIp), errmsg)
|
||||
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.getBridgeByIp), errmsg)
|
||||
|
||||
@staticmethod
|
||||
def getVlans():
|
||||
try:
|
||||
@ -339,8 +339,8 @@ class OvmNetwork(OvmObject):
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.getVlans, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.getVlans), errmsg)
|
||||
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.getVlans), errmsg)
|
||||
|
||||
@staticmethod
|
||||
def createVlan(jStr):
|
||||
try:
|
||||
@ -353,7 +353,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.createVlan, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.createVlan), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createVlanBridge(bridgeDetails, vlanDetails):
|
||||
try:
|
||||
@ -368,7 +368,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.createVlanBridge, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.createVlanBridge), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def deleteVlanBridge(name):
|
||||
try:
|
||||
@ -376,7 +376,7 @@ class OvmNetwork(OvmObject):
|
||||
if name not in network.bridges.keys():
|
||||
logger.debug(OvmNetwork.deleteVlanBridge, "No bridge %s found"%name)
|
||||
return SUCC()
|
||||
|
||||
|
||||
bridge = network.bridges[name]
|
||||
vlanName = bridge.attach
|
||||
if network._deleteBridge(name):
|
||||
@ -389,7 +389,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.deleteVlanBridge, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.deleteVlanBridge), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getBridgeDetails(name):
|
||||
try:
|
||||
@ -404,7 +404,7 @@ class OvmNetwork(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.getBridgeDetails, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.getBridgeDetails), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def deleteVlan(name):
|
||||
try:
|
||||
@ -414,8 +414,8 @@ class OvmNetwork(OvmObject):
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmNetwork.deleteVlan, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.deleteVlan), errmsg)
|
||||
|
||||
raise XmlRpcFault(toErrCode(OvmNetwork, OvmNetwork.deleteVlan), errmsg)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
OvmNetwork.getBridgeDetails(sys.argv[1])
|
||||
@ -424,10 +424,10 @@ if __name__ == "__main__":
|
||||
# txt2 = json.dumps({"name":"xapi3", "attach":"eth0.104"})
|
||||
# print nw.createVlan(txt)
|
||||
# print nw.createBridge(txt2)
|
||||
#
|
||||
#
|
||||
# nw.deleteBridge("xapi3")
|
||||
# nw.deleteVlan("eth0.104")
|
||||
#=======================================================================
|
||||
|
||||
|
||||
except Exception, e:
|
||||
print e
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
from OvmCommonModule import *
|
||||
|
||||
logger = OvmLogger('OvmOCFS2')
|
||||
logger = OvmLogger('OvmOCFS2')
|
||||
class OvmOCFS2(OvmObject):
|
||||
def _prepareConf(self, cluster):
|
||||
conf = '''cluster:
|
||||
@ -26,22 +26,22 @@ class OvmOCFS2(OvmObject):
|
||||
dir = dirname(OCFS2_CONF)
|
||||
if not isdir(dir):
|
||||
os.makedirs(dir)
|
||||
|
||||
|
||||
fd = open(OCFS2_CONF, 'w')
|
||||
fd.write(conf)
|
||||
fd.close()
|
||||
|
||||
|
||||
def _addNode(self, name, nodeNum, ip, port, cluster, isOnline=True):
|
||||
nodePath = '/sys/kernel/config/cluster/%s/node/%s'%(cluster, name)
|
||||
if exists(nodePath):
|
||||
logger.debug(OvmOCFS2._addNode, "node %s already exists, skip it(%s)"%(name, nodePath))
|
||||
return
|
||||
|
||||
|
||||
if not isOnline:
|
||||
cmds = ['o2cb_ctl -C -n', name, '-t node', '-a number=%s'%nodeNum, '-a ip_address=%s'%ip, '-a ip_port=%s'%port, '-a cluster=%s'%cluster]
|
||||
else:
|
||||
cmds = ['o2cb_ctl -C -i -n', name, '-t node', '-a number=%s'%nodeNum, '-a ip_address=%s'%ip, '-a ip_port=%s'%port, '-a cluster=%s'%cluster]
|
||||
|
||||
|
||||
try:
|
||||
doCmd(cmds)
|
||||
except ShellExceutedFailedException, e:
|
||||
@ -49,18 +49,18 @@ class OvmOCFS2(OvmObject):
|
||||
logger.debug(OvmOCFS2._addNode, "node %s already exists, skip it(%s)"%(name, e.stderr))
|
||||
else:
|
||||
raise e
|
||||
|
||||
|
||||
def _isClusterOnline(self, cluster):
|
||||
cmds = ['service o2cb status', cluster]
|
||||
res = doCmd(cmds)
|
||||
for line in res.split('\n'):
|
||||
if not 'Checking O2CB cluster' in line: continue
|
||||
return not 'Offline' in line
|
||||
|
||||
|
||||
def _load(self):
|
||||
cmd = ['service o2cb load']
|
||||
doCmd(cmd)
|
||||
|
||||
|
||||
def _start(self, cluster):
|
||||
#blank line are answer by clicking enter
|
||||
config='''
|
||||
@ -77,4 +77,4 @@ EOF
|
||||
doCmd(cmd)
|
||||
cmd = ['service o2cb start %s'%cluster]
|
||||
doCmd(cmd)
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -34,11 +34,11 @@ class OvmSecurityGroup(OvmObject):
|
||||
except:
|
||||
print "ebtables was not found on the host"
|
||||
return False
|
||||
|
||||
|
||||
if not os.path.exists('/var/run/cloud'):
|
||||
os.makedirs('/var/run/cloud')
|
||||
|
||||
return OvmSecurityGroup.cleanup_rules()
|
||||
|
||||
return OvmSecurityGroup.cleanup_rules()
|
||||
|
||||
@staticmethod
|
||||
def cleanup_rules():
|
||||
@ -52,8 +52,8 @@ class OvmSecurityGroup(OvmObject):
|
||||
vm_name = chain
|
||||
else:
|
||||
continue
|
||||
|
||||
cmd = "xm list | grep " + vm_name
|
||||
|
||||
cmd = "xm list | grep " + vm_name
|
||||
try:
|
||||
result = execute(cmd)
|
||||
except:
|
||||
@ -62,10 +62,10 @@ class OvmSecurityGroup(OvmObject):
|
||||
if result == None or len(result) == 0:
|
||||
logging.debug("chain " + chain + " does not correspond to a vm, cleaning up")
|
||||
cleanup.append(vm_name)
|
||||
|
||||
|
||||
for vm_name in cleanup:
|
||||
OvmSecurityGroup.delete_all_network_rules_for_vm(vm_name)
|
||||
|
||||
|
||||
logging.debug("Cleaned up rules for " + str(len(cleanup)) + " chains")
|
||||
return True
|
||||
except:
|
||||
@ -111,26 +111,26 @@ class OvmSecurityGroup(OvmObject):
|
||||
execute("iptables -A " + brfw + " -m physdev --physdev-is-bridged --physdev-out " + phydev + " -j ACCEPT")
|
||||
execute("iptables -A " + brfw + " -m state --state RELATED,ESTABLISHED -j ACCEPT")
|
||||
execute("iptables -A " + brfw + " -m physdev --physdev-is-bridged --physdev-is-out -j " + brfwout)
|
||||
execute("iptables -A " + brfw + " -m physdev --physdev-is-bridged --physdev-is-in -j " + brfwin)
|
||||
|
||||
execute("iptables -A " + brfw + " -m physdev --physdev-is-bridged --physdev-is-in -j " + brfwin)
|
||||
|
||||
return True
|
||||
except:
|
||||
try:
|
||||
execute("iptables -F " + brfw)
|
||||
except:
|
||||
return False
|
||||
|
||||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def default_network_rules_user_vm(vm_name, vm_id, vm_ip, vm_mac, vif, bridge_name):
|
||||
if not OvmSecurityGroup.add_fw_framework(bridge_name):
|
||||
return False
|
||||
return False
|
||||
|
||||
OvmSecurityGroup.delete_iptables_rules_for_vm(vm_name)
|
||||
OvmSecurityGroup.delete_ebtables_rules_for_vm(vm_name)
|
||||
|
||||
bridge_firewall_chain = "BF-" + bridge_name
|
||||
|
||||
bridge_firewall_chain = "BF-" + bridge_name
|
||||
vm_chain = vm_name
|
||||
default_vm_chain = '-'.join(vm_chain.split('-')[:-1]) + "-def"
|
||||
dom_id = getDomId(vm_name)
|
||||
@ -139,7 +139,7 @@ class OvmSecurityGroup(OvmObject):
|
||||
execute("iptables -N " + vm_chain)
|
||||
except:
|
||||
execute("iptables -F " + vm_chain)
|
||||
|
||||
|
||||
try:
|
||||
execute("iptables -N " + default_vm_chain)
|
||||
except:
|
||||
@ -163,13 +163,13 @@ class OvmSecurityGroup(OvmObject):
|
||||
except:
|
||||
logging.debug("Failed to program default rules for vm " + vm_name)
|
||||
return False
|
||||
|
||||
|
||||
OvmSecurityGroup.default_ebtables_rules(vm_chain, vm_ip, vm_mac, vif)
|
||||
|
||||
|
||||
if vm_ip is not None:
|
||||
if (OvmSecurityGroup.write_rule_log_for_vm(vm_name, vm_id, vm_ip, dom_id, '_initial_', '-1') == False):
|
||||
logging.debug("Failed to log default network rules, ignoring")
|
||||
|
||||
|
||||
logging.debug("Programmed default rules for vm " + vm_name)
|
||||
return True
|
||||
|
||||
@ -177,12 +177,12 @@ class OvmSecurityGroup(OvmObject):
|
||||
def default_ebtables_rules(vm_name, vm_ip, vm_mac, vif):
|
||||
vm_chain_in = vm_name + "-in"
|
||||
vm_chain_out = vm_name + "-out"
|
||||
|
||||
|
||||
for chain in [vm_chain_in, vm_chain_out]:
|
||||
try:
|
||||
execute("ebtables -t nat -N " + chain)
|
||||
except:
|
||||
execute("ebtables -t nat -F " + chain)
|
||||
execute("ebtables -t nat -F " + chain)
|
||||
|
||||
try:
|
||||
execute("ebtables -t nat -A PREROUTING -i " + vif + " -j " + vm_chain_in)
|
||||
@ -190,27 +190,27 @@ class OvmSecurityGroup(OvmObject):
|
||||
except:
|
||||
logging.debug("Failed to program default rules")
|
||||
return False
|
||||
|
||||
|
||||
try:
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -s ! " + vm_mac + " -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP -s ! " + vm_mac + " -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP --arp-mac-src ! " + vm_mac + " -j DROP")
|
||||
if vm_ip is not None:
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP --arp-ip-src ! " + vm_ip + " -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP --arp-op Request -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP --arp-op Reply -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP --arp-op Request -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP --arp-op Reply -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_in + " -p ARP -j DROP")
|
||||
except:
|
||||
logging.exception("Failed to program default ebtables IN rules")
|
||||
return False
|
||||
|
||||
|
||||
try:
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-op Reply --arp-mac-dst ! " + vm_mac + " -j DROP")
|
||||
if vm_ip is not None:
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-ip-dst ! " + vm_ip + " -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-op Request -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-op Reply -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-ip-dst ! " + vm_ip + " -j DROP")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-op Request -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP --arp-op Reply -j ACCEPT")
|
||||
execute("ebtables -t nat -A " + vm_chain_out + " -p ARP -j DROP")
|
||||
except:
|
||||
logging.debug("Failed to program default ebtables OUT rules")
|
||||
return False
|
||||
@ -222,14 +222,14 @@ class OvmSecurityGroup(OvmObject):
|
||||
try:
|
||||
vm_chain = vm_name
|
||||
dom_id = getDomId(vm_name)
|
||||
|
||||
|
||||
changes = []
|
||||
changes = OvmSecurityGroup.check_rule_log_for_vm(vm_name, vm_id, vm_ip, dom_id, signature, seqno)
|
||||
|
||||
|
||||
if not 1 in changes:
|
||||
logging.debug("Rules already programmed for vm " + vm_name)
|
||||
return True
|
||||
|
||||
|
||||
if changes[0] or changes[1] or changes[2] or changes[3]:
|
||||
if not OvmSecurityGroup.default_network_rules(vm_name, vm_id, vm_ip, vm_mac, vif, bridge_name):
|
||||
return False
|
||||
@ -241,8 +241,8 @@ class OvmSecurityGroup(OvmObject):
|
||||
|
||||
logging.debug("Programming network rules for IP: " + vm_ip + " vmname=" + vm_name)
|
||||
execute("iptables -F " + vm_chain)
|
||||
|
||||
for line in lines:
|
||||
|
||||
for line in lines:
|
||||
tokens = line.split(':')
|
||||
if len(tokens) != 4:
|
||||
continue
|
||||
@ -257,9 +257,9 @@ class OvmSecurityGroup(OvmObject):
|
||||
i = ips.index('0.0.0.0/0')
|
||||
del ips[i]
|
||||
allow_any = True
|
||||
|
||||
|
||||
port_range = start + ":" + end
|
||||
if ips:
|
||||
if ips:
|
||||
if protocol == 'all':
|
||||
for ip in ips:
|
||||
execute("iptables -I " + vm_chain + " -m state --state NEW -s " + ip + " -j ACCEPT")
|
||||
@ -272,7 +272,7 @@ class OvmSecurityGroup(OvmObject):
|
||||
port_range = "any"
|
||||
for ip in ips:
|
||||
execute("iptables -I " + vm_chain + " -p icmp --icmp-type " + port_range + " -s " + ip + " -j ACCEPT")
|
||||
|
||||
|
||||
if allow_any and protocol != 'all':
|
||||
if protocol != 'icmp':
|
||||
execute("iptables -I " + vm_chain + " -p " + protocol + " -m " + protocol + " --dport " + port_range + " -m state --state NEW -j ACCEPT")
|
||||
@ -281,17 +281,17 @@ class OvmSecurityGroup(OvmObject):
|
||||
if start == "-1":
|
||||
port_range = "any"
|
||||
execute("iptables -I " + vm_chain + " -p icmp --icmp-type " + port_range + " -j ACCEPT")
|
||||
|
||||
iptables = "iptables -A " + vm_chain + " -j DROP"
|
||||
|
||||
iptables = "iptables -A " + vm_chain + " -j DROP"
|
||||
execute(iptables)
|
||||
|
||||
return OvmSecurityGroup.write_rule_log_for_vm(vm_name, vm_id, vm_ip, dom_id, signature, seqno)
|
||||
|
||||
return OvmSecurityGroup.write_rule_log_for_vm(vm_name, vm_id, vm_ip, dom_id, signature, seqno)
|
||||
except:
|
||||
logging.debug("Failed to network rule !: " + sys.exc_type)
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def delete_all_network_rules_for_vm(vm_name, vif = None):
|
||||
def delete_all_network_rules_for_vm(vm_name, vif = None):
|
||||
OvmSecurityGroup.delete_iptables_rules_for_vm(vm_name)
|
||||
OvmSecurityGroup.delete_ebtables_rules_for_vm(vm_name)
|
||||
|
||||
@ -299,15 +299,15 @@ class OvmSecurityGroup(OvmObject):
|
||||
default_vm_chain = None
|
||||
if vm_name.startswith('i-') or vm_name.startswith('r-'):
|
||||
default_vm_chain = '-'.join(vm_name.split('-')[:-1]) + "-def"
|
||||
|
||||
|
||||
try:
|
||||
if default_vm_chain != None:
|
||||
if default_vm_chain != None:
|
||||
execute("iptables -F " + default_vm_chain)
|
||||
except:
|
||||
logging.debug("Ignoring failure to delete chain " + default_vm_chain)
|
||||
|
||||
|
||||
try:
|
||||
if default_vm_chain != None:
|
||||
if default_vm_chain != None:
|
||||
execute("iptables -X " + vmchain_default)
|
||||
except:
|
||||
logging.debug("Ignoring failure to delete chain " + default_vm_chain)
|
||||
@ -316,12 +316,12 @@ class OvmSecurityGroup(OvmObject):
|
||||
execute("iptables -F " + vm_chain)
|
||||
except:
|
||||
logging.debug("Ignoring failure to delete chain " + vm_chain)
|
||||
|
||||
|
||||
try:
|
||||
execute("iptables -X " + vm_chain)
|
||||
except:
|
||||
logging.debug("Ignoring failure to delete chain " + vm_chain)
|
||||
|
||||
|
||||
if vif is not None:
|
||||
try:
|
||||
dnats = execute("iptables-save -t nat | grep " + vif + " | sed 's/-A/-D/'").split("\n")
|
||||
@ -329,15 +329,15 @@ class OvmSecurityGroup(OvmObject):
|
||||
try:
|
||||
execute("iptables -t nat " + dnat)
|
||||
except:
|
||||
logging.debug("Igoring failure to delete dnat: " + dnat)
|
||||
logging.debug("Igoring failure to delete dnat: " + dnat)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
OvmSecurityGroup.remove_rule_log_for_vm(vm_name)
|
||||
|
||||
|
||||
if 1 in [ vm_name.startswith(c) for c in ['r-', 's-', 'v-'] ]:
|
||||
return True
|
||||
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
@ -347,7 +347,7 @@ class OvmSecurityGroup(OvmObject):
|
||||
query = "iptables-save | grep " + vm_chain + " | grep physdev-is-bridged | sed 's/-A/-D/'"
|
||||
delete_cmds = execute(query).split('\n')
|
||||
delete_cmds.pop()
|
||||
|
||||
|
||||
for cmd in delete_cmds:
|
||||
try:
|
||||
execute("iptables " + cmd)
|
||||
@ -356,7 +356,7 @@ class OvmSecurityGroup(OvmObject):
|
||||
|
||||
@staticmethod
|
||||
def delete_ebtables_rules_for_vm(vm_name):
|
||||
vm_name = OvmSecurityGroup.truncate_vm_name(vm_name)
|
||||
vm_name = OvmSecurityGroup.truncate_vm_name(vm_name)
|
||||
query = "ebtables -t nat -L --Lx | grep ROUTING | grep " + vm_name + " | sed 's/-A/-D/'"
|
||||
delete_cmds = execute(query).split('\n')
|
||||
delete_cmds.pop()
|
||||
@ -366,9 +366,9 @@ class OvmSecurityGroup(OvmObject):
|
||||
execute(cmd)
|
||||
except:
|
||||
logging.debug("Ignoring failure to delete ebtables rules for vm " + vm_name)
|
||||
|
||||
|
||||
chains = [vm_name + "-in", vm_name + "-out"]
|
||||
|
||||
|
||||
for chain in chains:
|
||||
try:
|
||||
execute("ebtables -t nat -F " + chain)
|
||||
@ -382,7 +382,7 @@ class OvmSecurityGroup(OvmObject):
|
||||
truncated_vm_name = '-'.join(vm_name.split('-')[:-1])
|
||||
else:
|
||||
truncated_vm_name = vm_name
|
||||
return truncated_vm_name
|
||||
return truncated_vm_name
|
||||
|
||||
@staticmethod
|
||||
def write_rule_log_for_vm(vm_name, vm_id, vm_ip, dom_id, signature, seqno):
|
||||
@ -391,15 +391,15 @@ class OvmSecurityGroup(OvmObject):
|
||||
logf = open(log_file_name, 'w')
|
||||
output = ','.join([vm_name, vm_id, vm_ip, dom_id, signature, seqno])
|
||||
|
||||
result = True
|
||||
result = True
|
||||
try:
|
||||
logf.write(output)
|
||||
logf.write('\n')
|
||||
except:
|
||||
logging.debug("Failed to write to rule log file " + log_file_name)
|
||||
result = False
|
||||
|
||||
logf.close()
|
||||
|
||||
logf.close()
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
@ -412,7 +412,7 @@ class OvmSecurityGroup(OvmObject):
|
||||
except:
|
||||
logging.debug("Failed to delete rule log file " + log_file_name)
|
||||
result = False
|
||||
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
@ -420,11 +420,11 @@ class OvmSecurityGroup(OvmObject):
|
||||
log_file_name = "/var/run/cloud/" + vm_name + ".log"
|
||||
if not os.path.exists(log_file_name):
|
||||
return [True, True, True, True, True, True]
|
||||
|
||||
|
||||
try:
|
||||
lines = (line.rstrip() for line in open(log_file_name))
|
||||
except:
|
||||
logging.debug("failed to open " + log_file_name)
|
||||
logging.debug("failed to open " + log_file_name)
|
||||
return [True, True, True, True, True, True]
|
||||
|
||||
[_vm_name, _vm_id, _vm_ip, _dom_id, _signature, _seqno] = ['_', '-1', '_', '-1', '_', '-1']
|
||||
@ -436,10 +436,9 @@ class OvmSecurityGroup(OvmObject):
|
||||
logging.debug("Failed to parse log file for vm " + vm_name)
|
||||
remove_rule_log_for_vm(vm_name)
|
||||
return [True, True, True, True, True, True]
|
||||
|
||||
|
||||
return [(vm_name != _vm_name), (vm_id != _vm_id), (vm_ip != _vm_ip), (dom_id != _dom_id), (signature != _signature), (seqno != _seqno)]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -475,4 +474,5 @@ class OvmSecurityGroup(OvmObject):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -50,7 +50,7 @@ def fromOvmStoragePool(pool):
|
||||
def toOvmStoragePool(jStr):
|
||||
return json.loads(jStr, cls=OvmStoragePoolDecoder)
|
||||
|
||||
logger = OvmLogger('OvmStoragePool')
|
||||
logger = OvmLogger('OvmStoragePool')
|
||||
class OvmStoragePool(OvmObject):
|
||||
uuid = ''
|
||||
type = ''
|
||||
@ -65,42 +65,42 @@ class OvmStoragePool(OvmObject):
|
||||
for uuid, sr in d.items():
|
||||
if sr.name_label == poolUuid:
|
||||
return sr
|
||||
|
||||
|
||||
raise Exception("No SR matching to %s" % poolUuid)
|
||||
|
||||
|
||||
def _getSpaceinfoOfDir(self, dir):
|
||||
stat = os.statvfs(dir)
|
||||
freeSpace = stat.f_frsize * stat.f_bavail;
|
||||
totalSpace = stat.f_blocks * stat.f_frsize;
|
||||
return (totalSpace, freeSpace)
|
||||
|
||||
|
||||
def _checkDirSizeForImage(self, dir, image):
|
||||
(x, free_storage_size) = OvmStoragePool()._getSpaceinfoOfDir(dir)
|
||||
image_size = os.path.getsize(image)
|
||||
if image_size > (free_storage_size + 1024 * 1024 * 1024):
|
||||
raise Exception("No space on dir %s (free storage:%s, vm size:%s)"%(dir, free_storage_size, image_size))
|
||||
|
||||
|
||||
def _getAllMountPoints(self):
|
||||
mps = []
|
||||
d = db_dump('sr')
|
||||
for uuid, sr in d.items():
|
||||
mps.append(sr.mountpoint)
|
||||
return mps
|
||||
|
||||
|
||||
def _isMounted(self, path):
|
||||
res = doCmd(['mount'])
|
||||
return (path in res)
|
||||
|
||||
|
||||
def _mount(self, target, mountpoint, readonly=False):
|
||||
if not exists(mountpoint):
|
||||
os.makedirs(mountpoint)
|
||||
|
||||
|
||||
if not OvmStoragePool()._isMounted(mountpoint):
|
||||
if readonly:
|
||||
doCmd(['mount', target, mountpoint, '-r'])
|
||||
else:
|
||||
doCmd(['mount', target, mountpoint])
|
||||
|
||||
|
||||
def _umount(self, mountpoint):
|
||||
umountCmd = ['umount', '-f', mountpoint]
|
||||
doCmd(umountCmd)
|
||||
@ -110,7 +110,7 @@ class OvmStoragePool(OvmObject):
|
||||
doCmd(rmDirCmd)
|
||||
else:
|
||||
logger.warning(OvmStoragePool._umount, "Something wrong when umount %s, there are still files in directory:%s", mountpoint, " ".join(ls))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create(jStr):
|
||||
try:
|
||||
@ -125,7 +125,7 @@ class OvmStoragePool(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmStoragePool.create, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.create), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getDetailsByUuid(uuid):
|
||||
try:
|
||||
@ -147,7 +147,7 @@ class OvmStoragePool(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmStoragePool.getDetailsByUuid, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.getDetailsByUuid), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def downloadTemplate(uuid, secPath):
|
||||
secMountPoint = None
|
||||
@ -158,28 +158,28 @@ class OvmStoragePool(OvmObject):
|
||||
secMountPoint = join("/var/cloud/", tmpUuid)
|
||||
if not exists(secMountPoint):
|
||||
os.makedirs(secMountPoint)
|
||||
|
||||
|
||||
templateFile = None
|
||||
if secPath.endswith("raw"):
|
||||
secPathDir = os.path.dirname(secPath)
|
||||
templateFile = os.path.basename(secPath)
|
||||
else:
|
||||
secPathDir = secPath
|
||||
|
||||
|
||||
# mount as read-only
|
||||
mountCmd = ['mount.nfs', secPathDir, secMountPoint, '-r']
|
||||
doCmd(mountCmd)
|
||||
|
||||
|
||||
if not templateFile:
|
||||
for f in os.listdir(secMountPoint):
|
||||
if isfile(join(secMountPoint, f)) and f.endswith('raw'):
|
||||
templateFile = f
|
||||
break
|
||||
|
||||
break
|
||||
|
||||
if not templateFile:
|
||||
raise Exception("Can not find raw template in secondary storage")
|
||||
templateSecPath = join(secMountPoint, templateFile)
|
||||
|
||||
|
||||
sr = OvmStoragePool()._getSrByNameLable(uuid)
|
||||
priStorageMountPoint = sr.mountpoint
|
||||
# Although mgmt server will check the size, we check again for safety
|
||||
@ -188,12 +188,12 @@ class OvmStoragePool(OvmObject):
|
||||
if exists(seedDir):
|
||||
raise Exception("%s already here, cannot override existing template" % seedDir)
|
||||
os.makedirs(seedDir)
|
||||
|
||||
|
||||
tgt = join(seedDir, templateFile)
|
||||
cpTemplateCmd = ['cp', templateSecPath, tgt]
|
||||
logger.info(OvmStoragePool.downloadTemplate, " ".join(cpTemplateCmd))
|
||||
doCmd(cpTemplateCmd)
|
||||
templateSize = os.path.getsize(tgt)
|
||||
templateSize = os.path.getsize(tgt)
|
||||
logger.info(OvmStoragePool.downloadTemplate, "primary_storage_download success:installPath:%s, templateSize:%s"%(tgt,templateSize))
|
||||
rs = toGson({"installPath":tgt, "templateSize":templateSize})
|
||||
return rs
|
||||
@ -210,7 +210,7 @@ class OvmStoragePool(OvmObject):
|
||||
logger.error(OvmStoragePool.downloadTemplate, 'unmount secondary storage at %s failed, %s'%(secMountPoint, errmsg))
|
||||
|
||||
@staticmethod
|
||||
def prepareOCFS2Nodes(clusterName, nodeString):
|
||||
def prepareOCFS2Nodes(clusterName, nodeString):
|
||||
def configureEtcHosts(nodes):
|
||||
if not exists(ETC_HOSTS):
|
||||
orignalConf = ""
|
||||
@ -218,14 +218,14 @@ class OvmStoragePool(OvmObject):
|
||||
fd = open(ETC_HOSTS, "r")
|
||||
orignalConf = fd.read()
|
||||
fd.close()
|
||||
|
||||
|
||||
pattern = r"(.*%s.*)|(.*%s.*)"
|
||||
newlines = []
|
||||
for n in nodes:
|
||||
p = pattern % (n["ip_address"], n["name"])
|
||||
orignalConf = re.sub(p, "", orignalConf)
|
||||
newlines.append("%s\t%s\n"%(n["ip_address"], n["name"]))
|
||||
|
||||
|
||||
orignalConf = orignalConf + "".join(newlines)
|
||||
# remove extra empty lines
|
||||
orignalConf = re.sub(r"\n\s*\n*", "\n", orignalConf)
|
||||
@ -233,7 +233,7 @@ class OvmStoragePool(OvmObject):
|
||||
fd = open(ETC_HOSTS, "w")
|
||||
fd.write(orignalConf)
|
||||
fd.close()
|
||||
|
||||
|
||||
def configureHostName(nodes):
|
||||
myIp = successToMap(get_master_ip())['ip']
|
||||
nodeName = None
|
||||
@ -241,7 +241,7 @@ class OvmStoragePool(OvmObject):
|
||||
if myIp == n["ip_address"]:
|
||||
nodeName = n["name"]
|
||||
break
|
||||
|
||||
|
||||
if nodeName == None: raise Exception("Cannot find node equals to my ip address:%s"%myIp)
|
||||
if not exists(HOSTNAME_FILE):
|
||||
originalConf = ""
|
||||
@ -249,7 +249,7 @@ class OvmStoragePool(OvmObject):
|
||||
fd = open(HOSTNAME_FILE, "r")
|
||||
originalConf = fd.read()
|
||||
fd.close()
|
||||
|
||||
|
||||
pattern = r"HOSTNAME=(.*)"
|
||||
# remove any old hostname
|
||||
originalConf = re.sub(pattern, "", originalConf)
|
||||
@ -260,31 +260,31 @@ class OvmStoragePool(OvmObject):
|
||||
fd.write(originalConf)
|
||||
fd.close()
|
||||
doCmd(['hostname', nodeName])
|
||||
|
||||
|
||||
def addNodes(nodes, clusterName):
|
||||
ocfs2 = OvmOCFS2()
|
||||
ocfs2._load()
|
||||
isOnline = ocfs2._isClusterOnline(clusterName)
|
||||
if not isOnline:
|
||||
ocfs2._prepareConf(clusterName)
|
||||
|
||||
|
||||
for n in nodes:
|
||||
ocfs2._addNode(n['name'], n['number'], n['ip_address'], 7777, clusterName, isOnline)
|
||||
|
||||
|
||||
def checkStaleCluster(clusterName):
|
||||
if exists('/sys/kernel/config/cluster/'):
|
||||
dirs = os.listdir('/sys/kernel/config/cluster/')
|
||||
for dir in dirs:
|
||||
if dir != clusterName:
|
||||
errMsg = '''CloudStack detected there is a stale cluster(%s) on host %s. Please manually clean up it first then add again by
|
||||
1) remove the host from cloudstack
|
||||
1) remove the host from cloudstack
|
||||
2) umount all OCFS2 device on host
|
||||
3) /etc/init.d/o2cb offline %s
|
||||
4) /etc/init.d/o2cb restart
|
||||
if this doesn't resolve the problem, please check oracle manual to see how to offline a cluster
|
||||
''' % (dir, successToMap(get_master_ip())['ip'], dir)
|
||||
raise Exception(errMsg)
|
||||
|
||||
|
||||
try:
|
||||
checkStaleCluster(clusterName)
|
||||
nodeString = nodeString.strip(";")
|
||||
@ -294,10 +294,10 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
if len(params) != 3: raise Exception("Wrong parameter(%s) in node string(%s)"%(n, nodeString))
|
||||
dict = {"number":params[0], "ip_address":params[1], "name":params[2]}
|
||||
nodes.append(dict)
|
||||
|
||||
|
||||
if len(nodes) > 255:
|
||||
raise Exception("%s nodes beyond maximum 255 allowed by OCFS2"%len(nodes))
|
||||
|
||||
|
||||
configureHostName(nodes)
|
||||
configureEtcHosts(nodes)
|
||||
addNodes(nodes, clusterName)
|
||||
@ -308,12 +308,12 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
logger.debug(OvmStoragePool.prepareOCFS2Nodes, "Configure cluster.conf to:\n%s"%' '.join(conf))
|
||||
rs = SUCC()
|
||||
return rs
|
||||
|
||||
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmStoragePool.prepareOCFS2Nodes, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.prepareOCFS2Nodes), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createTemplateFromVolume(secStorageMountPath, installPath, volumePath):
|
||||
try:
|
||||
@ -323,7 +323,7 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
vmName = getVmNameFromConfigureFile(vmCfg)
|
||||
if vmName in doCmd(['xm', 'list']):
|
||||
raise Exception("%s is still running, please stop it first then create template again"%vmName)
|
||||
|
||||
|
||||
tmpUuid = get_uuid()
|
||||
secMountPoint = join("/var/cloud/", tmpUuid)
|
||||
OvmStoragePool()._mount(secStorageMountPath, secMountPoint)
|
||||
@ -335,7 +335,7 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
logger.warning(OvmStoragePool.createTemplateFromVolume, "%s is already here, delete it since it is most likely stale"%destPath)
|
||||
doCmd(['rm', '-rf', destPath])
|
||||
OvmStoragePool()._checkDirSizeForImage(secMountPoint, volumePath)
|
||||
|
||||
|
||||
os.makedirs(destPath)
|
||||
newName = get_uuid() + ".raw"
|
||||
destName = join(destPath, newName)
|
||||
@ -345,18 +345,18 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
OvmStoragePool()._umount(secMountPoint)
|
||||
rs = toGson({"installPath":resInstallPath, "templateFileName":newName, "virtualSize":size, "physicalSize":size})
|
||||
return rs
|
||||
|
||||
|
||||
except Exception, e:
|
||||
try:
|
||||
if exists(secMountPoint):
|
||||
OvmStoragePool()._umount(secMountPoint)
|
||||
except Exception, e:
|
||||
logger.warning(OvmStoragePool.createTemplateFromVolume, "umount %s failed"%secMountPoint)
|
||||
|
||||
logger.warning(OvmStoragePool.createTemplateFromVolume, "umount %s failed"%secMountPoint)
|
||||
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmStoragePool.createTemplateFromVolume, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.createTemplateFromVolume), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def delete(uuid):
|
||||
try:
|
||||
@ -368,8 +368,8 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmStoragePool.delete, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.delete), errmsg)
|
||||
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.delete), errmsg)
|
||||
|
||||
@staticmethod
|
||||
def copyVolume(secStorageMountPath, volumeFolderOnSecStorage, volumePath, storagePoolUuid, toSec):
|
||||
def copyToSecStorage(secMountPoint, volumeFolderOnSecStorage, volumePath):
|
||||
@ -387,7 +387,7 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
destName = join(destPath, newName)
|
||||
doCmd(['cp', volumePath, destName])
|
||||
return destName
|
||||
|
||||
|
||||
def copyToPrimary(secMountPoint, volumeFolderOnSecStorage, volumePath, primaryMountPath):
|
||||
srcPath = join(secMountPoint, volumeFolderOnSecStorage.lstrip("/"), volumePath.lstrip("/"))
|
||||
if not srcPath.endswith(".raw"): srcPath = srcPath + ".raw"
|
||||
@ -399,7 +399,7 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
destName = join(destPath, newName)
|
||||
doCmd(['cp', srcPath, destName])
|
||||
return destName
|
||||
|
||||
|
||||
secMountPoint = ""
|
||||
try:
|
||||
tmpUuid = get_uuid()
|
||||
@ -412,7 +412,7 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
primaryStoragePath = sr.mountpoint
|
||||
resultPath = copyToPrimary(secMountPoint, volumeFolderOnSecStorage, volumePath, primaryStoragePath)
|
||||
OvmStoragePool()._umount(secMountPoint)
|
||||
|
||||
|
||||
# ingratiate bad mgmt server design, it asks 'installPath' but it only wants the volume name without suffix
|
||||
volumeUuid = basename(resultPath).rstrip(".raw")
|
||||
rs = toGson({"installPath":volumeUuid})
|
||||
@ -422,11 +422,10 @@ if this doesn't resolve the problem, please check oracle manual to see how to of
|
||||
if exists(secMountPoint):
|
||||
OvmStoragePool()._umount(secMountPoint)
|
||||
except Exception, e:
|
||||
logger.warning(OvmStoragePool.copyVolume, "umount %s failed"%secMountPoint)
|
||||
|
||||
logger.warning(OvmStoragePool.copyVolume, "umount %s failed"%secMountPoint)
|
||||
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmStoragePool.copyVolume, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmStoragePool, OvmStoragePool.copyVolume), errmsg)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -27,7 +27,7 @@ class OvmVifDecoder(json.JSONDecoder):
|
||||
vif.mac = deDict['mac']
|
||||
vif.bridge = deDict['bridge']
|
||||
return vif
|
||||
|
||||
|
||||
class OvmVifEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if not isinstance(obj, OvmVif): raise Exception("%s is not instance of OvmVif"%type(obj))
|
||||
@ -36,7 +36,7 @@ class OvmVifEncoder(json.JSONEncoder):
|
||||
safeDictSet(obj, dct, 'bridge')
|
||||
safeDictSet(obj, dct, 'type')
|
||||
safeDictSet(obj, dct, 'name')
|
||||
return dct
|
||||
return dct
|
||||
|
||||
def fromOvmVif(vif):
|
||||
return normalizeToGson(json.dumps(vif, cls=OvmVifEncoder))
|
||||
@ -60,6 +60,6 @@ class OvmVif(OvmObject):
|
||||
bridge = ''
|
||||
type = ''
|
||||
mode = ''
|
||||
|
||||
|
||||
def toXenString(self):
|
||||
return "%s,%s,%s"%(self.mac, self.bridge, self.type)
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -71,7 +71,7 @@ class OvmVmEncoder(json.JSONEncoder):
|
||||
disks = fromOvmDiskList(obj.disks)
|
||||
dct['disks'] = disks
|
||||
return dct
|
||||
|
||||
|
||||
def toOvmVm(jStr):
|
||||
return json.loads(jStr, cls=OvmVmDecoder)
|
||||
|
||||
@ -88,7 +88,7 @@ class OvmVm(OvmObject):
|
||||
name = ''
|
||||
bootDev = ''
|
||||
type = ''
|
||||
|
||||
|
||||
def _getVifs(self, vmName):
|
||||
vmPath = OvmHost()._vmNameToPath(vmName)
|
||||
domId = OvmHost()._getDomainIdByName(vmName)
|
||||
@ -104,9 +104,9 @@ class OvmVm(OvmObject):
|
||||
safeSetAttr(vif, 'bridge', bridge)
|
||||
safeSetAttr(vif, 'type', type)
|
||||
lst.append(vif)
|
||||
|
||||
|
||||
return lst
|
||||
|
||||
|
||||
def _getVifsFromConfig(self, vmPath):
|
||||
vifs = successToMap(xen_get_vifs(vmPath))
|
||||
lst = []
|
||||
@ -120,16 +120,16 @@ class OvmVm(OvmObject):
|
||||
safeSetAttr(vif, 'type', type)
|
||||
lst.append(vif)
|
||||
return lst
|
||||
|
||||
|
||||
def _getIsoMountPath(self, vmPath):
|
||||
vmName = basename(vmPath)
|
||||
priStoragePath = vmPath.rstrip(join('running_pool', vmName))
|
||||
return join(priStoragePath, 'iso_pool', vmName)
|
||||
|
||||
|
||||
def _getVmTypeFromConfigFile(self, vmPath):
|
||||
vmType = successToMap(xen_get_vm_type(vmPath))['type']
|
||||
return vmType.replace('hvm', 'HVM').replace('para', 'PV')
|
||||
|
||||
|
||||
def _tapAOwnerFile(self, vmPath):
|
||||
# Create a file with name convention 'host_ip_address' in vmPath
|
||||
# Because xm list doesn't return vm that has been stopped, we scan
|
||||
@ -140,30 +140,30 @@ class OvmVm(OvmObject):
|
||||
fd = open(join(vmPath, ownerFileName), 'w')
|
||||
fd.write(ownerFileName)
|
||||
fd.close()
|
||||
|
||||
|
||||
def _cleanUpOwnerFile(self, vmPath):
|
||||
for f in os.listdir(vmPath):
|
||||
fp = join(vmPath, f)
|
||||
if isfile(fp) and f.startswith(OWNER_FILE_PREFIX):
|
||||
os.remove(fp)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create(jsonString):
|
||||
def create(jsonString):
|
||||
def dumpCfg(vmName, cfgPath):
|
||||
cfgFd = open(cfgPath, 'r')
|
||||
cfg = cfgFd.readlines()
|
||||
cfgFd.close()
|
||||
logger.info(OvmVm.create, "Start %s with configure:\n\n%s\n"%(vmName, "".join(cfg)))
|
||||
|
||||
|
||||
def setVifsType(vifs, type):
|
||||
for vif in vifs:
|
||||
vif.type = type
|
||||
|
||||
|
||||
def hddBoot(vm, vmPath):
|
||||
vmType = vm.type
|
||||
if vmType == "FROMCONFIGFILE":
|
||||
vmType = OvmVm()._getVmTypeFromConfigFile(vmPath)
|
||||
|
||||
|
||||
cfgDict = {}
|
||||
if vmType == "HVM":
|
||||
cfgDict['builder'] = "'hvm'"
|
||||
@ -175,7 +175,7 @@ class OvmVm(OvmObject):
|
||||
else:
|
||||
cfgDict['bootloader'] = "'/usr/bin/pygrub'"
|
||||
vifType = 'netfront'
|
||||
|
||||
|
||||
cfgDict['name'] = "'%s'"%vm.name
|
||||
cfgDict['disk'] = "[]"
|
||||
cfgDict['vcpus'] = "''"
|
||||
@ -183,17 +183,17 @@ class OvmVm(OvmObject):
|
||||
cfgDict['on_crash'] = "'destroy'"
|
||||
cfgDict['on_reboot'] = "'restart'"
|
||||
cfgDict['vif'] = "[]"
|
||||
|
||||
|
||||
items = []
|
||||
for k in cfgDict.keys():
|
||||
item = " = ".join([k, cfgDict[k]])
|
||||
items.append(item)
|
||||
vmSpec = "\n".join(items)
|
||||
|
||||
|
||||
vmCfg = open(join(vmPath, 'vm.cfg'), 'w')
|
||||
vmCfg.write(vmSpec)
|
||||
vmCfg.close()
|
||||
|
||||
|
||||
setVifsType(vm.vifs, vifType)
|
||||
raiseExceptionIfFail(xen_set_vcpus(vmPath, vm.cpuNum))
|
||||
raiseExceptionIfFail(xen_set_memory(vmPath, BytesToM(vm.memory)))
|
||||
@ -201,7 +201,7 @@ class OvmVm(OvmObject):
|
||||
vifs = [OvmVif.toXenString(v) for v in vm.vifs]
|
||||
for vif in vifs:
|
||||
raiseExceptionIfFail(xen_set_vifs(vmPath, vif))
|
||||
|
||||
|
||||
for disk in vm.disks:
|
||||
raiseExceptionIfFail(xen_add_disk(vmPath, disk.path, mode=disk.type))
|
||||
|
||||
@ -215,7 +215,7 @@ class OvmVm(OvmObject):
|
||||
# it's tricky !
|
||||
raiseExceptionIfFail(xen_config_boot_sequence(vmPath, 'd'))
|
||||
raiseExceptionIfFail(xen_config_boot_sequence(vmPath, 'c'))
|
||||
|
||||
|
||||
raiseExceptionIfFail(xen_correct_cfg(cfgFile, vmPath))
|
||||
xen_correct_qos_cfg(cfgFile)
|
||||
dumpCfg(vm.name, cfgFile)
|
||||
@ -223,7 +223,7 @@ class OvmVm(OvmObject):
|
||||
raiseExceptionIfFail(start_vm(vmPath, server))
|
||||
rs = SUCC()
|
||||
return rs
|
||||
|
||||
|
||||
def cdBoot(vm, vmPath):
|
||||
isoMountPath = None
|
||||
try:
|
||||
@ -233,7 +233,7 @@ class OvmVm(OvmObject):
|
||||
cdrom = disk
|
||||
break
|
||||
if not cdrom: raise Exception("Cannot find Iso in disks")
|
||||
|
||||
|
||||
isoOnSecStorage = dirname(cdrom.path)
|
||||
isoName = basename(cdrom.path)
|
||||
isoMountPath = OvmVm()._getIsoMountPath(vmPath)
|
||||
@ -241,10 +241,10 @@ class OvmVm(OvmObject):
|
||||
isoPath = join(isoMountPath, isoName)
|
||||
if not exists(isoPath):
|
||||
raise Exception("Cannot found iso %s at %s which mounts to %s"%(isoName, isoOnSecStorage, isoMountPath))
|
||||
|
||||
|
||||
stdout = run_cmd(args=['file', isoPath])
|
||||
if not stdout.strip().endswith("(bootable)"): raise Exception("ISO %s is not bootable"%cdrom.path)
|
||||
|
||||
|
||||
#now alter cdrom to correct path
|
||||
cdrom.path = isoPath
|
||||
if len(vm.vifs) != 0:
|
||||
@ -253,7 +253,7 @@ class OvmVm(OvmObject):
|
||||
vifCfg = ','.join([vif.mac, vif.bridge, 'ioemu'])
|
||||
else:
|
||||
vifCfg = ''
|
||||
|
||||
|
||||
rootDiskSize = os.path.getsize(vm.rootDisk.path)
|
||||
rooDiskCfg = ':'.join([join(vmPath, basename(vm.rootDisk.path)), str(BytesToG(rootDiskSize)), 'True'])
|
||||
disks = [rooDiskCfg]
|
||||
@ -264,7 +264,7 @@ class OvmVm(OvmObject):
|
||||
disks.append(cfg)
|
||||
disksCfg = ','.join(disks)
|
||||
server = successToMap(get_master_ip())['ip']
|
||||
|
||||
|
||||
raiseExceptionIfFail(install_vm_hvm(vmPath, BytesToM(vm.memory), vm.cpuNum, vifCfg, disksCfg, cdrom.path, vncpassword='', dedicated_server=server))
|
||||
rs = SUCC()
|
||||
return rs
|
||||
@ -273,13 +273,13 @@ class OvmVm(OvmObject):
|
||||
doCmd(['umount', '-f', isoMountPath])
|
||||
errmsg = fmt_err_msg(e)
|
||||
raise Exception(errmsg)
|
||||
|
||||
|
||||
try:
|
||||
vm = toOvmVm(jsonString)
|
||||
logger.debug(OvmVm.create, "creating vm, spec:%s"%jsonString)
|
||||
rootDiskPath = vm.rootDisk.path
|
||||
if not exists(rootDiskPath): raise Exception("Cannot find root disk %s"%rootDiskPath)
|
||||
|
||||
|
||||
rootDiskDir = dirname(rootDiskPath)
|
||||
vmPath = join(dirname(rootDiskDir), vm.name)
|
||||
if not exists(vmPath):
|
||||
@ -287,7 +287,7 @@ class OvmVm(OvmObject):
|
||||
vmNameFile = open(join(rootDiskDir, 'vmName'), 'w')
|
||||
vmNameFile.write(vm.name)
|
||||
vmNameFile.close()
|
||||
|
||||
|
||||
OvmVm()._tapAOwnerFile(rootDiskDir)
|
||||
# set the VM to DOWN before starting, OVS agent will check this status
|
||||
set_vm_status(vmPath, 'DOWN')
|
||||
@ -302,7 +302,7 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.create, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.create), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def stop(vmName):
|
||||
try:
|
||||
@ -311,7 +311,7 @@ class OvmVm(OvmObject):
|
||||
except NoVmFoundException, e:
|
||||
logger.info(OvmVm.stop, "vm %s is already stopped"%vmName)
|
||||
return SUCC()
|
||||
|
||||
|
||||
logger.info(OvmVm.stop, "Stop vm %s"%vmName)
|
||||
try:
|
||||
vmPath = OvmHost()._vmNameToPath(vmName)
|
||||
@ -327,7 +327,7 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.stop, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.stop), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def reboot(vmName):
|
||||
try:
|
||||
@ -347,12 +347,12 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.reboot, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.reboot), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getDetails(vmName):
|
||||
def getDetails(vmName):
|
||||
try:
|
||||
vm = OvmVm()
|
||||
|
||||
|
||||
try:
|
||||
OvmHost()._getDomainIdByName(vmName)
|
||||
vmPath = OvmHost()._vmNameToPath(vmName)
|
||||
@ -360,8 +360,8 @@ class OvmVm(OvmObject):
|
||||
except NoVmFoundException, e:
|
||||
vmPath = OvmHost()._getVmPathFromPrimaryStorage(vmName)
|
||||
vifsFromConfig = True
|
||||
|
||||
|
||||
|
||||
|
||||
if not isdir(vmPath):
|
||||
# The case is, when vm starting was not completed at primaryStroageDownload or createVolume(e.g. mgmt server stop), the mgmt
|
||||
# server will keep vm state in staring, then a stop command will be sent. The stop command will delete bridges that vm attaches,
|
||||
@ -373,7 +373,7 @@ class OvmVm(OvmObject):
|
||||
vm.vifs.extend(vm._getVifsFromConfig(vmPath))
|
||||
else:
|
||||
vm.vifs.extend(vm._getVifs(vmName))
|
||||
|
||||
|
||||
safeSetAttr(vm, 'name', vmName)
|
||||
disks = successToMap(xen_get_vdisks(vmPath))['vdisks'].split(',')
|
||||
rootDisk = None
|
||||
@ -398,7 +398,7 @@ class OvmVm(OvmObject):
|
||||
safeSetAttr(vm, 'powerState', vmStatus['status'])
|
||||
vmType = successToMap(xen_get_vm_type(vmPath))['type'].replace('hvm', 'HVM').replace('para', 'PV')
|
||||
safeSetAttr(vm, 'type', vmType)
|
||||
|
||||
|
||||
rs = fromOvmVm(vm)
|
||||
logger.info(OvmVm.getDetails, rs)
|
||||
return rs
|
||||
@ -406,7 +406,7 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.getDetails, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.getDetails), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getVmStats(vmName):
|
||||
def getVcpuNumAndUtils():
|
||||
@ -421,7 +421,7 @@ class OvmVm(OvmObject):
|
||||
nvCpus = len(items)
|
||||
if nvCpus == 0:
|
||||
raise Exception("vm %s has 0 vcpus !!!"%vmName)
|
||||
|
||||
|
||||
xmInfo = successToMap(xen_get_xm_info())
|
||||
nCpus = int(xmInfo['nr_cpus'])
|
||||
totalUtils = 0.0
|
||||
@ -432,8 +432,8 @@ class OvmVm(OvmObject):
|
||||
return (nvCpus, avgUtils)
|
||||
finally:
|
||||
session_logout()
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
try:
|
||||
OvmHost()._getDomainIdByName(vmName)
|
||||
@ -456,15 +456,15 @@ class OvmVm(OvmObject):
|
||||
avgUtils = 0
|
||||
rxBytes = 0
|
||||
txBytes = 0
|
||||
|
||||
|
||||
rs = toGson({"cpuNum":nvcpus, "cpuUtil":avgUtils, "rxBytes":rxBytes, "txBytes":txBytes})
|
||||
logger.debug(OvmVm.getVmStats, rs)
|
||||
return rs
|
||||
return rs
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.getVmStats, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.getVmStats), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def migrate(vmName, targetHost):
|
||||
try:
|
||||
@ -477,7 +477,7 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.migrate, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.migrate), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def register(vmName):
|
||||
try:
|
||||
@ -492,7 +492,7 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.register, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.register), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getVncPort(vmName):
|
||||
try:
|
||||
@ -504,7 +504,7 @@ class OvmVm(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.getVncPort, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.getVncPort), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def detachOrAttachIso(vmName, iso, isAttach):
|
||||
try:
|
||||
@ -514,11 +514,11 @@ class OvmVm(OvmObject):
|
||||
else:
|
||||
scope = 'cfg'
|
||||
vmPath = OvmHost()._getVmPathFromPrimaryStorage(vmName)
|
||||
|
||||
|
||||
vmType = OvmVm()._getVmTypeFromConfigFile(vmPath)
|
||||
if vmType != 'HVM':
|
||||
raise Exception("Only HVM supports attaching/detaching ISO")
|
||||
|
||||
|
||||
if not isAttach:
|
||||
iso = ''
|
||||
else:
|
||||
@ -527,14 +527,14 @@ class OvmVm(OvmObject):
|
||||
isoOnSecStorage = dirname(iso)
|
||||
OvmStoragePool()._mount(isoOnSecStorage, isoMountPoint)
|
||||
iso = join(isoMountPoint, isoName)
|
||||
|
||||
|
||||
exceptionIfNoSuccess(xen_change_vm_cdrom(vmPath, iso, scope))
|
||||
return SUCC()
|
||||
except Exception, e:
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVm.detachOrAttachIso, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVm, OvmVm.detachOrAttachIso), errmsg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
print OvmVm.getDetails(sys.argv[1])
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -34,7 +34,7 @@ class OvmVolumeDecoder(json.JSONDecoder):
|
||||
setAttrFromDict(vol, 'size', deDict, long)
|
||||
setAttrFromDict(vol, 'poolUuid', deDict)
|
||||
return vol
|
||||
|
||||
|
||||
class OvmVolumeEncoder(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if not isinstance(obj, OvmVolume): raise Exception("%s is not instance of OvmVolume"%type(obj))
|
||||
@ -45,7 +45,7 @@ class OvmVolumeEncoder(json.JSONEncoder):
|
||||
safeDictSet(obj, dct, 'path')
|
||||
safeDictSet(obj, dct, 'size')
|
||||
return dct
|
||||
|
||||
|
||||
def toOvmVolume(jStr):
|
||||
return json.loads(jStr, cls=OvmVolumeDecoder)
|
||||
|
||||
@ -58,7 +58,7 @@ class OvmVolume(OvmObject):
|
||||
poolUuid = ''
|
||||
path = ''
|
||||
size = 0
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createDataDisk(poolUuid, size, isRoot):
|
||||
try:
|
||||
@ -75,7 +75,7 @@ class OvmVolume(OvmObject):
|
||||
freeSpace = pool._getSpaceinfoOfDir(path)
|
||||
if freeSpace < vol.size:
|
||||
raise Exception("%s has not enough space (available:%s, required:%s"%(path, freeSpace, vol.size))
|
||||
|
||||
|
||||
vol.uuid = get_uuid()
|
||||
vol.name = vol.uuid + '.raw'
|
||||
filePath = join(path, vol.name)
|
||||
@ -88,7 +88,7 @@ class OvmVolume(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVolume.createDataDisk, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVolume, OvmVolume.createDataDisk, errmsg))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def createFromTemplate(poolUuid, templateUrl):
|
||||
try:
|
||||
@ -121,7 +121,7 @@ class OvmVolume(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVolume.createFromTemplate, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVolume, OvmVolume.createFromTemplate), errmsg)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def destroy(poolUuid, path):
|
||||
try:
|
||||
@ -148,12 +148,11 @@ class OvmVolume(OvmObject):
|
||||
errmsg = fmt_err_msg(e)
|
||||
logger.error(OvmVolume.destroy, errmsg)
|
||||
raise XmlRpcFault(toErrCode(OvmVolume, OvmVolume.destroy), errmsg)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print OvmVolume.detachOrAttachIso(sys.argv[1], '', False)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import web
|
||||
import socket, struct
|
||||
@ -52,11 +52,11 @@ class dhcp:
|
||||
start_ip_num = self.ipToNum(dhcp_start);
|
||||
end_ip_num = self.ipToNum(dhcp_end)
|
||||
print(start_ip_num, end_ip_num)
|
||||
|
||||
|
||||
for ip in range(start_ip_num, end_ip_num + 1):
|
||||
self.availIP.append(ip)
|
||||
print(self.availIP[0], self.availIP[len(self.availIP) - 1])
|
||||
|
||||
self.availIP.append(ip)
|
||||
print(self.availIP[0], self.availIP[len(self.availIP) - 1])
|
||||
|
||||
#load the ip already allocated
|
||||
self.reloadAllocatedIP()
|
||||
|
||||
@ -69,7 +69,7 @@ class dhcp:
|
||||
def getFreeIP(self):
|
||||
if len(self.availIP) > 0:
|
||||
ip = self.numToIp(self.availIP[0])
|
||||
self.availIP.remove(self.availIP[0])
|
||||
self.availIP.remove(self.availIP[0])
|
||||
return ip
|
||||
else:
|
||||
return None
|
||||
@ -88,13 +88,13 @@ class dhcp:
|
||||
|
||||
def reloadAllocatedIP(self):
|
||||
dhcp_hosts = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.decode('utf-8').strip().splitlines()
|
||||
|
||||
|
||||
for host in dhcp_hosts:
|
||||
if host.find("dhcp-host") != -1:
|
||||
allocatedIP = self.ipToNum(host.split("=")[1].strip().split(",")[1])
|
||||
if allocatedIP in self.availIP:
|
||||
if allocatedIP in self.availIP:
|
||||
self.availIP.remove(allocatedIP)
|
||||
|
||||
|
||||
def allocateIP(self, mac):
|
||||
newIP = self.getFreeIP()
|
||||
dhcp_host = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.decode('utf-8').strip()
|
||||
@ -112,7 +112,7 @@ class dhcp:
|
||||
for host in dhcp_host.splitlines():
|
||||
if host.find(ip) != -1:
|
||||
path = host.split("=")[0].strip()
|
||||
|
||||
|
||||
if path == None:
|
||||
print("Can't find " + str(ip) + " in conf file")
|
||||
return None
|
||||
@ -121,9 +121,9 @@ class dhcp:
|
||||
script = """rm %s
|
||||
save"""%(path)
|
||||
augtool < script
|
||||
|
||||
|
||||
self.availIP.remove(ip)
|
||||
|
||||
|
||||
#reset dnsmasq
|
||||
service("dnsmasq", "restart", stdout=None, stderr=None)
|
||||
|
||||
@ -145,7 +145,7 @@ class ipallocator:
|
||||
if not freeIP:
|
||||
return "0,0,0"
|
||||
print("Find an available IP: " + freeIP)
|
||||
|
||||
|
||||
return freeIP + "," + dhcpInit.getNetmask() + "," + dhcpInit.getRouter()
|
||||
elif command == "releaseIpAddr":
|
||||
ip = user_data.ip
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import web
|
||||
import socket, struct
|
||||
@ -52,11 +52,11 @@ class dhcp:
|
||||
start_ip_num = self.ipToNum(dhcp_start);
|
||||
end_ip_num = self.ipToNum(dhcp_end)
|
||||
print(start_ip_num, end_ip_num)
|
||||
|
||||
|
||||
for ip in range(start_ip_num, end_ip_num + 1):
|
||||
self.availIP.append(ip)
|
||||
print(self.availIP[0], self.availIP[len(self.availIP) - 1])
|
||||
|
||||
self.availIP.append(ip)
|
||||
print(self.availIP[0], self.availIP[len(self.availIP) - 1])
|
||||
|
||||
#load the ip already allocated
|
||||
self.reloadAllocatedIP()
|
||||
|
||||
@ -69,7 +69,7 @@ class dhcp:
|
||||
def getFreeIP(self):
|
||||
if len(self.availIP) > 0:
|
||||
ip = self.numToIp(self.availIP[0])
|
||||
self.availIP.remove(self.availIP[0])
|
||||
self.availIP.remove(self.availIP[0])
|
||||
return ip
|
||||
else:
|
||||
return None
|
||||
@ -88,13 +88,13 @@ class dhcp:
|
||||
|
||||
def reloadAllocatedIP(self):
|
||||
dhcp_hosts = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.decode('utf-8').strip().splitlines()
|
||||
|
||||
|
||||
for host in dhcp_hosts:
|
||||
if host.find("dhcp-host") != -1:
|
||||
allocatedIP = self.ipToNum(host.split("=")[1].strip().split(",")[1])
|
||||
if allocatedIP in self.availIP:
|
||||
if allocatedIP in self.availIP:
|
||||
self.availIP.remove(allocatedIP)
|
||||
|
||||
|
||||
def allocateIP(self, mac):
|
||||
newIP = self.getFreeIP()
|
||||
dhcp_host = augtool.match("/files/etc/dnsmasq.conf/dhcp-host").stdout.decode('utf-8').strip()
|
||||
@ -112,7 +112,7 @@ class dhcp:
|
||||
for host in dhcp_host.splitlines():
|
||||
if host.find(ip) != -1:
|
||||
path = host.split("=")[0].strip()
|
||||
|
||||
|
||||
if path == None:
|
||||
print("Can't find " + str(ip) + " in conf file")
|
||||
return None
|
||||
@ -121,9 +121,9 @@ class dhcp:
|
||||
script = """rm %s
|
||||
save"""%(path)
|
||||
augtool < script
|
||||
|
||||
|
||||
self.availIP.remove(ip)
|
||||
|
||||
|
||||
#reset dnsmasq
|
||||
service("dnsmasq", "restart", stdout=None, stderr=None)
|
||||
|
||||
@ -145,7 +145,7 @@ class ipallocator:
|
||||
if not freeIP:
|
||||
return "0,0,0"
|
||||
print("Find an available IP: " + freeIP)
|
||||
|
||||
|
||||
return freeIP + "," + dhcpInit.getNetmask() + "," + dhcpInit.getRouter()
|
||||
elif command == "releaseIpAddr":
|
||||
ip = user_data.ip
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -23,7 +23,7 @@ class CloudRuntimeException(Exception):
|
||||
value = sys.exc_info()[1]
|
||||
if value is not None:
|
||||
self.errMsg += ", due to:" + str(value)
|
||||
|
||||
|
||||
self.details = formatExceptionInfo()
|
||||
def __str__(self):
|
||||
return self.errMsg
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -27,7 +27,7 @@ class configFileOps:
|
||||
self.op = op
|
||||
self.separator = separator
|
||||
def setState(self, state):
|
||||
self.state = state
|
||||
self.state = state
|
||||
def getState(self):
|
||||
return self.state
|
||||
|
||||
@ -35,18 +35,18 @@ class configFileOps:
|
||||
self.fileName = fileName
|
||||
self.entries = []
|
||||
self.backups = []
|
||||
|
||||
|
||||
if cfg is not None:
|
||||
cfg.cfoHandlers.append(self)
|
||||
|
||||
def addEntry(self, name, value, separator="="):
|
||||
e = self.entry(name, value, "add", separator)
|
||||
self.entries.append(e)
|
||||
|
||||
|
||||
def rmEntry(self, name, value, separator="="):
|
||||
entry = self.entry(name, value, "rm", separator)
|
||||
self.entries.append(entry)
|
||||
|
||||
|
||||
def getEntry(self, name, separator="="):
|
||||
try:
|
||||
ctx = open(self.fileName).read(-1)
|
||||
@ -74,7 +74,7 @@ class configFileOps:
|
||||
matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
|
||||
else:
|
||||
matchString = "^\ *" + entry.name + "\ *" + entry.value
|
||||
|
||||
|
||||
match = re.match(matchString, line)
|
||||
if match is not None:
|
||||
if entry.op == "add" and entry.separator == "=":
|
||||
@ -88,9 +88,9 @@ class configFileOps:
|
||||
entry.setState("set")
|
||||
self.backups.append([line, None])
|
||||
matched = True
|
||||
break
|
||||
|
||||
if not matched:
|
||||
break
|
||||
|
||||
if not matched:
|
||||
newLines.append(line)
|
||||
|
||||
for entry in self.entries:
|
||||
@ -102,7 +102,7 @@ class configFileOps:
|
||||
entry.setState("set")
|
||||
|
||||
fp.close()
|
||||
|
||||
|
||||
open(self.fileName, "w").writelines(newLines)
|
||||
|
||||
def replace_line(self, startswith,stanza,always_add=False):
|
||||
@ -126,18 +126,18 @@ class configFileOps:
|
||||
return self.replace_line(startswith,stanza,always_add=True)
|
||||
|
||||
def add_lines(self, lines, addToBackup=True):
|
||||
fp = open(self.fileName).read(-1)
|
||||
fp = open(self.fileName).read(-1)
|
||||
sh = re.escape(lines)
|
||||
match = re.search(sh, fp, re.MULTILINE)
|
||||
match = re.search(sh, fp, re.MULTILINE)
|
||||
if match is not None:
|
||||
return
|
||||
|
||||
|
||||
fp += lines
|
||||
open(self.fileName, "w").write(fp)
|
||||
self.backups.append([None, lines])
|
||||
|
||||
|
||||
def replace_lines(self, src, dst, addToBackup=True):
|
||||
fp = open(self.fileName).read(-1)
|
||||
fp = open(self.fileName).read(-1)
|
||||
sh = re.escape(src)
|
||||
if dst is None:
|
||||
dst = ""
|
||||
@ -168,7 +168,7 @@ class configFileOps:
|
||||
newlines.append(line)
|
||||
|
||||
open(self.fileName, "w").writelines(newlines)
|
||||
|
||||
|
||||
def backup(self):
|
||||
for oldLine, newLine in self.backups:
|
||||
if newLine is None:
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -32,16 +32,16 @@ class networkConfig:
|
||||
self.type = type
|
||||
self.name = name
|
||||
#dhcp or static
|
||||
self.method = None
|
||||
|
||||
self.method = None
|
||||
|
||||
@staticmethod
|
||||
def listNetworks():
|
||||
devs = os.listdir("/sys/class/net/")
|
||||
devs = list(filter(networkConfig.isBridge, devs))
|
||||
devs = os.listdir("/sys/class/net/")
|
||||
devs = list(filter(networkConfig.isBridge, devs))
|
||||
return devs
|
||||
@staticmethod
|
||||
def getDefaultNetwork():
|
||||
cmd = bash("route -n|awk \'/^0.0.0.0/ {print $2,$8}\'")
|
||||
cmd = bash("route -n|awk \'/^0.0.0.0/ {print $2,$8}\'")
|
||||
if not cmd.isSuccess():
|
||||
logging.debug("Failed to get default route")
|
||||
raise CloudRuntimeException("Failed to get default route")
|
||||
@ -67,7 +67,7 @@ class networkConfig:
|
||||
cmds = ""
|
||||
if not networkConfig.isBridge(brName):
|
||||
cmds = "ip link add name %s type bridge ;"%brName
|
||||
|
||||
|
||||
cmds += "ifconfig %s up;"%brName
|
||||
cmds += "ip link set dev %s master %s"%(dev, brName)
|
||||
return bash(cmds).isSuccess()
|
||||
@ -75,10 +75,10 @@ class networkConfig:
|
||||
@staticmethod
|
||||
def isBridgeEnslavedWithDevices(brName):
|
||||
if not networkConfig.isBridge(brName):
|
||||
return False
|
||||
return False
|
||||
|
||||
if not os.listdir("/sys/class/net/%s/brif"%brName):
|
||||
return False
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@ -96,7 +96,7 @@ class networkConfig:
|
||||
@staticmethod
|
||||
def isBridgePort(devName):
|
||||
return os.path.exists("/sys/class/net/%s/brport" % devName)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def isBridge(devName):
|
||||
return os.path.exists("/sys/class/net/%s/bridge" % devName)
|
||||
@ -116,7 +116,7 @@ class networkConfig:
|
||||
bridgeName = None
|
||||
if os.path.exists("/sys/class/net/%s/brport/bridge"%devName):
|
||||
realPath = os.path.realpath("/sys/class/net/%s/brport/bridge"%devName)
|
||||
bridgeName = realPath.split("/")[-1]
|
||||
bridgeName = realPath.split("/")[-1]
|
||||
return bridgeName
|
||||
|
||||
@staticmethod
|
||||
@ -130,7 +130,7 @@ class networkConfig:
|
||||
return dev
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@staticmethod
|
||||
def getDevInfo(dev):
|
||||
if not networkConfig.isNetworkDev(dev):
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -38,7 +38,7 @@ def lock():
|
||||
if count > sleep_max:
|
||||
print "Can not get file lock at %s, time expired" % file_lock
|
||||
return False
|
||||
|
||||
|
||||
try:
|
||||
f = open(file_lock, "w")
|
||||
f.close()
|
||||
@ -104,7 +104,7 @@ if __name__ == "__main__":
|
||||
if len(sys.argv) < 7:
|
||||
print usage
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
mac = sys.argv[1]
|
||||
ip = sys.argv[2]
|
||||
hostname = sys.argv[3]
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -41,12 +41,12 @@ def writeIfNotHere(fileName, texts):
|
||||
if not t in entries:
|
||||
entries.append(t)
|
||||
need = True
|
||||
|
||||
if need:
|
||||
|
||||
if need:
|
||||
f = open(fileName, 'w')
|
||||
f.write(''.join(entries))
|
||||
f.close()
|
||||
|
||||
|
||||
def createRedirectEntry(vmIp, folder, filename):
|
||||
entry = "RewriteRule ^%s$ ../%s/%%{REMOTE_ADDR}/%s [L,NC,QSA]" % (filename, folder, filename)
|
||||
htaccessFolder="/var/www/html/latest"
|
||||
@ -54,7 +54,7 @@ def createRedirectEntry(vmIp, folder, filename):
|
||||
if not os.path.exists(htaccessFolder):
|
||||
os.makedirs(htaccessFolder)
|
||||
writeIfNotHere(htaccessFile, ["Options +FollowSymLinks", "RewriteEngine On", entry])
|
||||
|
||||
|
||||
htaccessFolder = os.path.join("/var/www/html/", folder, vmIp)
|
||||
if not os.path.exists(htaccessFolder):
|
||||
os.makedirs(htaccessFolder)
|
||||
@ -63,23 +63,23 @@ def createRedirectEntry(vmIp, folder, filename):
|
||||
f = open(htaccessFile, 'w')
|
||||
f.write(entry)
|
||||
f.close()
|
||||
|
||||
|
||||
if folder in ['metadata', 'meta-data']:
|
||||
entry1="RewriteRule ^meta-data/(.+)$ ../%s/%%{REMOTE_ADDR}/$1 [L,NC,QSA]" % folder
|
||||
htaccessFolder="/var/www/html/latest"
|
||||
htaccessFile=os.path.join(htaccessFolder, ".htaccess")
|
||||
entry2="RewriteRule ^meta-data/$ ../%s/%%{REMOTE_ADDR}/meta-data [L,NC,QSA]" % folder
|
||||
writeIfNotHere(htaccessFile, [entry1, entry2])
|
||||
|
||||
|
||||
|
||||
def addUserData(vmIp, folder, fileName, contents):
|
||||
|
||||
|
||||
baseFolder = os.path.join(HTML_ROOT, folder, vmIp)
|
||||
if not os.path.exists(baseFolder):
|
||||
os.makedirs(baseFolder)
|
||||
|
||||
|
||||
createRedirectEntry(vmIp, folder, fileName)
|
||||
|
||||
|
||||
datafileName = os.path.join(HTML_ROOT, folder, vmIp, fileName)
|
||||
metaManifest = os.path.join(HTML_ROOT, folder, vmIp, "meta-data")
|
||||
if folder == "userdata":
|
||||
@ -87,11 +87,11 @@ def addUserData(vmIp, folder, fileName, contents):
|
||||
contents = base64.urlsafe_b64decode(contents)
|
||||
else:
|
||||
contents = ""
|
||||
|
||||
|
||||
f = open(datafileName, 'w')
|
||||
f.write(contents)
|
||||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
|
||||
if folder == "metadata" or folder == "meta-data":
|
||||
writeIfNotHere(metaManifest, [fileName])
|
||||
|
||||
@ -101,4 +101,4 @@ if __name__ == '__main__':
|
||||
for entry in allEntires:
|
||||
(vmIp, folder, fileName, contents) = entry.split(',', 3)
|
||||
addUserData(vmIp, folder, fileName, contents)
|
||||
sys.exit(0)
|
||||
sys.exit(0)
|
||||
|
||||
@ -9,12 +9,12 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
# Automatically generated by addcopyright.py at 04/03/2012
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restore cifs_username cifs_password
|
||||
import os, sys
|
||||
@ -28,7 +28,7 @@ TIMEOUT 26
|
||||
DISPLAY boot.msg
|
||||
LABEL default
|
||||
KERNEL %s
|
||||
APPEND ramdisk_size=66000 initrd=%s ksdevice=%s ks=%s
|
||||
APPEND ramdisk_size=66000 initrd=%s ksdevice=%s ks=%s
|
||||
'''
|
||||
fmt2 = '''DEFAULT default
|
||||
PROMPT 1
|
||||
@ -73,6 +73,6 @@ if __name__ == "__main__":
|
||||
exit(1)
|
||||
|
||||
(tftp_dir, mac, kernel, initrd, ks_file, ks_device) = sys.argv[1:]
|
||||
|
||||
|
||||
ret = prepare()
|
||||
exit(ret)
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -29,7 +29,7 @@ def cmd(cmdstr, err=True):
|
||||
print cmdstr
|
||||
if os.system(cmdstr) != 0 and err:
|
||||
raise Exception("Failed to run shell command: %s" % cmdstr)
|
||||
|
||||
|
||||
def prepare():
|
||||
global kernel, initrd, copy_to
|
||||
try:
|
||||
@ -64,12 +64,12 @@ def prepare():
|
||||
except Exception, e:
|
||||
print e
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 4:
|
||||
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to"
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
(kernel, initrd, copy_to) = sys.argv[1:]
|
||||
sys.exit(prepare())
|
||||
|
||||
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -83,7 +83,7 @@ if __name__ == "__main__":
|
||||
exit(1)
|
||||
|
||||
(cmd, tftp_dir, mac, cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway) = sys.argv[1:]
|
||||
|
||||
|
||||
if cmd == "restore":
|
||||
ret = prepare(True)
|
||||
elif cmd == "backup":
|
||||
@ -91,5 +91,5 @@ if __name__ == "__main__":
|
||||
else:
|
||||
print "Unknown cmd: %s"%cmd
|
||||
ret = 1
|
||||
|
||||
|
||||
exit(ret)
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -16,7 +16,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import sys, os, subprocess, errno, re
|
||||
@ -72,7 +72,7 @@ class Command:
|
||||
else: return l
|
||||
def __str__(self):
|
||||
return '<Command %r>'%self.__get_recursive_name(sep=" ")
|
||||
|
||||
|
||||
def __repr__(self): return self.__str__()
|
||||
|
||||
|
||||
@ -134,13 +134,13 @@ def reboot(args):
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
if "is on" in o.stdout:
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "cycle")
|
||||
else:
|
||||
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "reset")
|
||||
|
||||
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
return 1
|
||||
@ -172,7 +172,7 @@ def boot_or_reboot(args):
|
||||
if o.ret:
|
||||
print o.stderr
|
||||
return 1
|
||||
|
||||
|
||||
if "is on" in o.stdout:
|
||||
return reboot(args)
|
||||
elif "is off" in o.stdout:
|
||||
@ -181,7 +181,7 @@ def boot_or_reboot(args):
|
||||
else:
|
||||
print "unknown power status:" + o.stdout
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot, "power":power, "boot_or_reboot":boot_or_reboot}
|
||||
def dispatch(args):
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -16,7 +16,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
# $Id: macgen.py 9132 2010-06-04 20:17:43Z manuel $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/util/macgen.py $
|
||||
# macgen.py script to generate a MAC address for Red Hat Virtualization guests
|
||||
|
||||
@ -47,14 +47,14 @@ def get_clusters(content, cluster=None):
|
||||
clusters.append(c)
|
||||
hosts = c.host
|
||||
for host in hosts:
|
||||
hostClusterNameDict[host.name] = c.name
|
||||
hostClusterNameDict[host.name] = c.name
|
||||
break
|
||||
else:
|
||||
for c in cluster_view.view:
|
||||
clusters.append(c)
|
||||
hosts = c.host
|
||||
for host in hosts:
|
||||
hostClusterNameDict[host.name] = c.name
|
||||
hostClusterNameDict[host.name] = c.name
|
||||
cluster_view.Destroy()
|
||||
log_message('\t{} cluster(s) found'.format(len(clusters)))
|
||||
for c in clusters:
|
||||
@ -187,7 +187,7 @@ def add_network(portGroup, vlanId, isolatedPvlanType, isolatedPvlan, vSwitch, vm
|
||||
cluster = hostClusterNameDict[host]
|
||||
except KeyError:
|
||||
cluster = vmClusterName
|
||||
|
||||
|
||||
network = {"portgroup": portGroup, "cluster": cluster, "host": host, "switch": vSwitch, "virtualmachines": vms}
|
||||
if vlanId != '':
|
||||
network["vlanid"] = vlanId
|
||||
@ -267,7 +267,7 @@ def main():
|
||||
content = serviceInstance.RetrieveContent()
|
||||
if args.cluster:
|
||||
clusters = get_clusters(content, args.cluster)
|
||||
else:
|
||||
else:
|
||||
clusters = get_clusters(content)
|
||||
hosts = []
|
||||
if len(clusters) > 0:
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -86,7 +86,7 @@ def main(command, vif_raw):
|
||||
return
|
||||
|
||||
bridge = pluginlib.do_cmd([pluginlib.VSCTL_PATH, 'iface-to-br', this_vif])
|
||||
|
||||
|
||||
# find xs network for this bridge, verify is used for ovs tunnel network
|
||||
xs_nw_uuid = pluginlib.do_cmd([pluginlib.XE_PATH, "network-list",
|
||||
"bridge=%s" % bridge, "--minimal"])
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -87,7 +87,7 @@ class RRDUpdates:
|
||||
return result
|
||||
|
||||
def get_vm_data(self, uuid, param, row):
|
||||
#pp = pprint.PrettyPrinter(indent=4)
|
||||
#pp = pprint.PrettyPrinter(indent=4)
|
||||
#pp.pprint(self.vm_reports)
|
||||
report = self.vm_reports[uuid]
|
||||
col = report[param]
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -36,7 +36,7 @@ CAPABILITIES = ["SR_PROBE","SR_UPDATE", "SR_CACHING", \
|
||||
CONFIGURATION = [ [ 'server', 'hostname or IP address of NFS server (required)' ], \
|
||||
[ 'serverpath', 'path on remote server (required)' ] ]
|
||||
|
||||
|
||||
|
||||
DRIVER_INFO = {
|
||||
'name': 'NFS VHD',
|
||||
'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem',
|
||||
@ -123,7 +123,7 @@ class NFSSR(FileSR.FileSR):
|
||||
def probe(self):
|
||||
# Verify NFS target and port
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
|
||||
|
||||
self.validate_remotepath(True)
|
||||
self.check_server()
|
||||
|
||||
@ -155,7 +155,7 @@ class NFSSR(FileSR.FileSR):
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
||||
|
||||
|
||||
def create(self, sr_uuid, size):
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
@ -186,8 +186,8 @@ class NFSSR(FileSR.FileSR):
|
||||
# except util.CommandException, inst:
|
||||
# if inst.code != errno.EEXIST:
|
||||
# self.detach(sr_uuid)
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# % inst.code)
|
||||
self.detach(sr_uuid)
|
||||
|
||||
@ -216,7 +216,7 @@ class NFSSR(FileSR.FileSR):
|
||||
if not loadLocked:
|
||||
return NFSFileVDI(self, uuid)
|
||||
return NFSFileVDI(self, uuid)
|
||||
|
||||
|
||||
def _checkmount(self):
|
||||
return util.ioretry(lambda: util.pathexists(self.path)) \
|
||||
and util.ioretry(lambda: util.ismount(self.path))
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -36,7 +36,7 @@ CAPABILITIES = ["SR_PROBE","SR_UPDATE", "SR_CACHING", \
|
||||
CONFIGURATION = [ [ 'server', 'hostname or IP address of NFS server (required)' ], \
|
||||
[ 'serverpath', 'path on remote server (required)' ] ]
|
||||
|
||||
|
||||
|
||||
DRIVER_INFO = {
|
||||
'name': 'NFS VHD',
|
||||
'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem',
|
||||
@ -123,7 +123,7 @@ class NFSSR(FileSR.FileSR):
|
||||
def probe(self):
|
||||
# Verify NFS target and port
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
|
||||
|
||||
self.validate_remotepath(True)
|
||||
self.check_server()
|
||||
|
||||
@ -155,7 +155,7 @@ class NFSSR(FileSR.FileSR):
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
||||
|
||||
|
||||
def create(self, sr_uuid, size):
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
@ -186,8 +186,8 @@ class NFSSR(FileSR.FileSR):
|
||||
# except util.CommandException, inst:
|
||||
# if inst.code != errno.EEXIST:
|
||||
# self.detach(sr_uuid)
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# % inst.code)
|
||||
self.detach(sr_uuid)
|
||||
|
||||
@ -216,7 +216,7 @@ class NFSSR(FileSR.FileSR):
|
||||
if not loadLocked:
|
||||
return NFSFileVDI(self, uuid)
|
||||
return NFSFileVDI(self, uuid)
|
||||
|
||||
|
||||
def _checkmount(self):
|
||||
return util.ioretry(lambda: util.pathexists(self.path)) \
|
||||
and util.ioretry(lambda: util.ismount(self.path))
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -339,12 +339,12 @@ def db_init_from_cache(cache):
|
||||
global _db
|
||||
assert(_db is None)
|
||||
_db = DatabaseCache(cache_file=cache)
|
||||
|
||||
|
||||
def db_init_from_xenapi(session):
|
||||
global _db
|
||||
global _db
|
||||
assert(_db is None)
|
||||
_db = DatabaseCache(session_ref=session)
|
||||
|
||||
|
||||
class DatabaseCache(object):
|
||||
def __read_xensource_inventory(self):
|
||||
filename = root_prefix() + "/etc/xensource-inventory"
|
||||
@ -626,7 +626,7 @@ def ethtool_settings(oc):
|
||||
# {VIF,PIF,Network}.other-config:mtu.
|
||||
#
|
||||
# type parameter is a string describing the object that the oc parameter
|
||||
# is from. e.g. "PIF", "Network"
|
||||
# is from. e.g. "PIF", "Network"
|
||||
def mtu_setting(nw, type, oc):
|
||||
mtu = None
|
||||
|
||||
@ -635,7 +635,7 @@ def mtu_setting(nw, type, oc):
|
||||
mtu = nwrec['MTU']
|
||||
else:
|
||||
mtu = "1500"
|
||||
|
||||
|
||||
if oc.has_key('mtu'):
|
||||
log("Override Network.MTU setting on bridge %s from %s.MTU is %s" % \
|
||||
(nwrec['bridge'], type, mtu))
|
||||
@ -796,7 +796,7 @@ class Datapath(object):
|
||||
datapath for a given PIF. Does not include configuration of the
|
||||
IP address on the ipdev.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, pif):
|
||||
self._pif = pif
|
||||
|
||||
@ -804,7 +804,7 @@ class Datapath(object):
|
||||
"""Write ifcfg TYPE field for an IPdev, plus any type specific
|
||||
fields to cfg
|
||||
"""
|
||||
raise NotImplementedError
|
||||
raise NotImplementedError
|
||||
|
||||
def preconfigure(self, parent):
|
||||
"""Prepare datapath configuration for PIF, but do not actually
|
||||
@ -813,7 +813,7 @@ class Datapath(object):
|
||||
Any configuration files should be attached to parent.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def bring_down_existing(self):
|
||||
"""Tear down any existing network device configuration which
|
||||
needs to be undone in order to bring this PIF up.
|
||||
@ -831,7 +831,7 @@ class Datapath(object):
|
||||
Should not bring up the IPdev.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def post(self):
|
||||
"""Called after the IPdev has been brought up.
|
||||
|
||||
@ -846,17 +846,17 @@ class Datapath(object):
|
||||
IPdev has already been brought down.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def DatapathFactory(pif):
|
||||
# XXX Need a datapath object for bridgeless PIFs
|
||||
|
||||
try:
|
||||
network_conf = open(root_prefix() + "/etc/xensource/network.conf", 'r')
|
||||
network_backend = network_conf.readline().strip()
|
||||
network_conf.close()
|
||||
network_conf.close()
|
||||
except Exception, e:
|
||||
raise Error("failed to determine network backend:" + e)
|
||||
|
||||
|
||||
if network_backend == "bridge":
|
||||
from InterfaceReconfigureBridge import DatapathBridge
|
||||
return DatapathBridge(pif)
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -36,7 +36,7 @@ CAPABILITIES = ["SR_PROBE","SR_UPDATE", \
|
||||
CONFIGURATION = [ [ 'server', 'hostname or IP address of NFS server (required)' ], \
|
||||
[ 'serverpath', 'path on remote server (required)' ] ]
|
||||
|
||||
|
||||
|
||||
DRIVER_INFO = {
|
||||
'name': 'NFS VHD',
|
||||
'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem',
|
||||
@ -124,7 +124,7 @@ class NFSSR(FileSR.FileSR):
|
||||
def probe(self):
|
||||
# Verify NFS target and port
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
|
||||
|
||||
self.validate_remotepath(True)
|
||||
self.check_server()
|
||||
|
||||
@ -157,7 +157,7 @@ class NFSSR(FileSR.FileSR):
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
||||
|
||||
|
||||
@FileSR.locking("SRUnavailable")
|
||||
def create(self, sr_uuid, size):
|
||||
@ -189,8 +189,8 @@ class NFSSR(FileSR.FileSR):
|
||||
# except util.CommandException, inst:
|
||||
# if inst.code != errno.EEXIST:
|
||||
# self.detach(sr_uuid)
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# % inst.code)
|
||||
self.detach(sr_uuid)
|
||||
|
||||
@ -220,7 +220,7 @@ class NFSSR(FileSR.FileSR):
|
||||
if not loadLocked:
|
||||
return NFSFileVDINolock(self, uuid)
|
||||
return NFSFileVDI(self, uuid)
|
||||
|
||||
|
||||
def _checkmount(self):
|
||||
return util.ioretry(lambda: util.pathexists(self.path)) \
|
||||
and util.ioretry(lambda: util.ismount(self.path))
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -37,7 +37,7 @@ CAPABILITIES = ["SR_PROBE","SR_UPDATE", "SR_CACHING", \
|
||||
CONFIGURATION = [ [ 'server', 'hostname or IP address of NFS server (required)' ], \
|
||||
[ 'serverpath', 'path on remote server (required)' ] ]
|
||||
|
||||
|
||||
|
||||
DRIVER_INFO = {
|
||||
'name': 'NFS VHD',
|
||||
'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem',
|
||||
@ -124,7 +124,7 @@ class NFSSR(FileSR.FileSR):
|
||||
def probe(self):
|
||||
# Verify NFS target and port
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
|
||||
|
||||
self.validate_remotepath(True)
|
||||
self.check_server()
|
||||
|
||||
@ -156,7 +156,7 @@ class NFSSR(FileSR.FileSR):
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
||||
|
||||
|
||||
def create(self, sr_uuid, size):
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
@ -187,8 +187,8 @@ class NFSSR(FileSR.FileSR):
|
||||
# except util.CommandException, inst:
|
||||
# if inst.code != errno.EEXIST:
|
||||
# self.detach(sr_uuid)
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# % inst.code)
|
||||
self.detach(sr_uuid)
|
||||
|
||||
@ -217,7 +217,7 @@ class NFSSR(FileSR.FileSR):
|
||||
if not loadLocked:
|
||||
return NFSFileVDI(self, uuid)
|
||||
return NFSFileVDI(self, uuid)
|
||||
|
||||
|
||||
def _checkmount(self):
|
||||
return util.ioretry(lambda: util.pathexists(self.path)) \
|
||||
and util.ioretry(lambda: util.ismount(self.path))
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -38,7 +38,7 @@ CAPABILITIES = ["SR_PROBE","SR_UPDATE", "SR_CACHING",
|
||||
CONFIGURATION = [ [ 'server', 'hostname or IP address of NFS server (required)' ], \
|
||||
[ 'serverpath', 'path on remote server (required)' ] ]
|
||||
|
||||
|
||||
|
||||
DRIVER_INFO = {
|
||||
'name': 'NFS VHD',
|
||||
'description': 'SR plugin which stores disks as VHD files on a remote NFS filesystem',
|
||||
@ -129,7 +129,7 @@ class NFSSR(FileSR.FileSR):
|
||||
def probe(self):
|
||||
# Verify NFS target and port
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
|
||||
|
||||
self.validate_remotepath(True)
|
||||
self.check_server()
|
||||
|
||||
@ -161,7 +161,7 @@ class NFSSR(FileSR.FileSR):
|
||||
raise xs_errors.XenError('NFSUnMount', opterr=exc.errstr)
|
||||
|
||||
return super(NFSSR, self).detach(sr_uuid)
|
||||
|
||||
|
||||
|
||||
def create(self, sr_uuid, size):
|
||||
util._testHost(self.dconf['server'], NFSPORT, 'NFSTarget')
|
||||
@ -192,8 +192,8 @@ class NFSSR(FileSR.FileSR):
|
||||
# except util.CommandException, inst:
|
||||
# if inst.code != errno.EEXIST:
|
||||
# self.detach(sr_uuid)
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# raise xs_errors.XenError('NFSCreate',
|
||||
# opterr='remote directory creation error is %d'
|
||||
# % inst.code)
|
||||
self.detach(sr_uuid)
|
||||
|
||||
@ -222,7 +222,7 @@ class NFSSR(FileSR.FileSR):
|
||||
if not loadLocked:
|
||||
return NFSFileVDI(self, uuid)
|
||||
return NFSFileVDI(self, uuid)
|
||||
|
||||
|
||||
def _checkmount(self):
|
||||
return util.ioretry(lambda: util.pathexists(self.path)) \
|
||||
and util.ioretry(lambda: util.ismount(self.path))
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -108,8 +108,8 @@ class TestlistTemplates(cloudstackTestCase):
|
||||
name,value )
|
||||
self.RestartServers()
|
||||
time.sleep(self.testdata["sleep"])
|
||||
|
||||
|
||||
|
||||
|
||||
@attr(tags=["advanced", "basic"], required_hardware="true")
|
||||
def test_01_CS40139_listtemplate_with_different_pagesize(self):
|
||||
"""
|
||||
@ -135,7 +135,7 @@ class TestlistTemplates(cloudstackTestCase):
|
||||
domainid=self.domain.id,
|
||||
max=1000
|
||||
)
|
||||
|
||||
|
||||
for i in range(0, 850):
|
||||
template_created = Template.register(
|
||||
self.apiclient,
|
||||
@ -219,7 +219,7 @@ class TestlistTemplates(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
self.updateConfigurAndRestart("allow.public.user.templates", "false")
|
||||
|
||||
|
||||
user_account = Account.create(
|
||||
self.apiclient,
|
||||
self.testdata["account2"],
|
||||
|
||||
@ -456,7 +456,7 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
|
||||
Host.update(self.apiclient, id=self.hosts[0].id, hosttags="hosttag1,hosttag2")
|
||||
Host.update(self.apiclient, id=self.hosts[1].id, hosttags="hosttag1,hosttag2")
|
||||
|
||||
|
||||
self.validate_vm_deployment()
|
||||
self.debug("Stop the host on which the VPC virtual router is running")
|
||||
try:
|
||||
@ -477,11 +477,11 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
True,
|
||||
"List routers shall return a valid VPCVR for account"
|
||||
)
|
||||
|
||||
|
||||
router = routers[0]
|
||||
|
||||
|
||||
try:
|
||||
|
||||
|
||||
timeout = self.services["timeout"]
|
||||
self.debug("Timeout Value %d : " % timeout)
|
||||
while True:
|
||||
@ -490,7 +490,7 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
id = router.id,
|
||||
state = "Running"
|
||||
)
|
||||
|
||||
|
||||
if list_router_response is not None:
|
||||
break
|
||||
elif timeout == 0:
|
||||
@ -499,12 +499,12 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = timeout - 1
|
||||
self.debug("Waiting for %d seconds - %d tries left" % (self.services["sleep"],timeout))
|
||||
|
||||
|
||||
self.debug("Verified that the Router is in Running State")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to find the Router in Running state %s " % e)
|
||||
|
||||
|
||||
vms = VirtualMachine.list(
|
||||
self.apiclient,
|
||||
account=self.account.name,
|
||||
@ -537,7 +537,7 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
# 1. Successfully cancel the Maintenance mode on the host.
|
||||
# 2. Migrate the VMs back successfully onto the host.
|
||||
# 3. Check that the network connectivity exists with the migrated VMs.
|
||||
|
||||
|
||||
try:
|
||||
timeout = self.services["timeout"]
|
||||
while True:
|
||||
@ -545,7 +545,7 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
self.apiclient,
|
||||
id=self.vpcvr.hostid,
|
||||
resourcestate="Maintenance")
|
||||
|
||||
|
||||
if list_host_response is not None:
|
||||
break
|
||||
elif timeout == 0:
|
||||
@ -553,9 +553,9 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
|
||||
self.debug("Verified that the Host is in Maintenance State")
|
||||
|
||||
|
||||
except:
|
||||
self.fail("Failed to find the Host in maintenance state")
|
||||
|
||||
@ -569,7 +569,7 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
self.apiclient,
|
||||
id=self.vpcvr.hostid,
|
||||
state="Up")
|
||||
|
||||
|
||||
if list_host_response is not None:
|
||||
break
|
||||
elif timeout == 0:
|
||||
@ -577,9 +577,9 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
|
||||
self.debug("Verified that the Host is in Up State after Canceling Maintenance Mode")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to cancel maintenance mode on host: %s" % e)
|
||||
|
||||
@ -626,13 +626,13 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
# effected due to reconnection.
|
||||
|
||||
try:
|
||||
timeout = self.services["timeout"]
|
||||
timeout = self.services["timeout"]
|
||||
while True:
|
||||
list_host_response = Host.list(
|
||||
self.apiclient,
|
||||
id=self.vpcvr.hostid,
|
||||
resourcestate="Enabled")
|
||||
|
||||
|
||||
if list_host_response is not None:
|
||||
break
|
||||
elif timeout == 0:
|
||||
@ -640,9 +640,9 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase):
|
||||
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
|
||||
self.debug("Verified that the Host is in Up State")
|
||||
|
||||
|
||||
except:
|
||||
self.fail("Failed to find the Host in Up State")
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ class TestDeployVMSync(cloudstackTestCase):
|
||||
|
||||
list_vms = VirtualMachine.list(self.apiclient, ids=[self.vm1.id, self.vm2.id, self.vm3.id], listAll=True)
|
||||
self.assertTrue(isinstance(list_vms, list) and len(list_vms) == 3, msg = "List VM response is empty")
|
||||
for vm in list_vms:
|
||||
for vm in list_vms:
|
||||
if vm.id == self.vm1.id:
|
||||
self.assertTrue(vm.state == "Running", msg = "VM {0} is expected to be in running state".format(vm.name))
|
||||
elif vm.id == self.vm2.id or vm.id == self.vm3.id:
|
||||
|
||||
@ -201,7 +201,7 @@ class TestVPNService(cloudstackTestCase):
|
||||
# IP by using ike-scan
|
||||
|
||||
self.create_VPN(self.public_ip)
|
||||
|
||||
|
||||
cmd = ['ike-scan', self.public_ip, '-s', '4534'] # Random port
|
||||
|
||||
stdout = subprocess.check_output(cmd)
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -125,7 +125,7 @@ class Services:
|
||||
# Max networks allowed as per hypervisor
|
||||
# Xenserver -> 5, VMWare -> 9
|
||||
},
|
||||
|
||||
|
||||
"virtual_machine": {
|
||||
"displayname": "Test VM",
|
||||
"username": "root",
|
||||
|
||||
@ -2488,7 +2488,7 @@ class TestStorageLiveMigrationVmware(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
4. Deploy a windows VM, set vmware.vcenter.session.timeout to a low value
|
||||
and do migration, migration should fail
|
||||
and do migration, migration should fail
|
||||
"""
|
||||
|
||||
vm = "virtual_machine3"
|
||||
@ -2498,7 +2498,7 @@ class TestStorageLiveMigrationVmware(cloudstackTestCase):
|
||||
# list cluster for that host
|
||||
vm_cluster = list_clusters(self.apiclient, id=vm_host.clusterid, listall=True)[0]
|
||||
#list all hosts in the cluster
|
||||
host_list = list_hosts(self.apiclient, clusterid=vm_cluster.id, listall=True)
|
||||
host_list = list_hosts(self.apiclient, clusterid=vm_cluster.id, listall=True)
|
||||
Configurations.update(
|
||||
self.apiclient,
|
||||
"vmware.vcenter.session.timeout",
|
||||
@ -2611,7 +2611,7 @@ class TestStorageLiveMigrationVmware(cloudstackTestCase):
|
||||
self.apiclient,
|
||||
"Running"
|
||||
)
|
||||
# Create 2 data disks
|
||||
# Create 2 data disks
|
||||
data_disk_1 = Volume.create(
|
||||
self.apiclient,
|
||||
self.testdata["volume"],
|
||||
@ -2677,7 +2677,7 @@ class TestStorageLiveMigrationVmware(cloudstackTestCase):
|
||||
self.apiclient,
|
||||
ssvm.id,
|
||||
"Running"
|
||||
)
|
||||
)
|
||||
|
||||
# Try vMotion on virtual_machine_1 to the host which is in maintenance
|
||||
destinationHost, destinationPools, vol_list = get_destination_pools_hosts(self, list_vm_1, storage_scope, storage_type)
|
||||
@ -2825,7 +2825,7 @@ class TestStorageLiveMigrationVmware(cloudstackTestCase):
|
||||
self.apiclient,
|
||||
"Running"
|
||||
)
|
||||
# Create 2 data disks
|
||||
# Create 2 data disks
|
||||
data_disk_1 = Volume.create(
|
||||
self.apiclient,
|
||||
self.testdata["volume"],
|
||||
|
||||
@ -5,17 +5,17 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
Test cases relating to access checks for createNetwork(), deploying VM in an isolated network and restartNetwork() for Admin, domain admin and regular users
|
||||
"""
|
||||
Test cases relating to access checks for createNetwork(), deploying VM in an isolated network and restartNetwork() for Admin, domain admin and regular users
|
||||
"""
|
||||
|
||||
# Import Local Modules
|
||||
|
||||
@ -5,16 +5,16 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
"""
|
||||
|
||||
Test cases relating to acess checks for deleteNetwork() for Admin, domain admin and regular users
|
||||
|
||||
@ -64,7 +64,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
cls.default_apikey = cls.apiclient.connection.apiKey
|
||||
cls.default_secretkey = cls.apiclient.connection.securityKey
|
||||
|
||||
# Create domains
|
||||
# Create domains
|
||||
cls.domain_1 = Domain.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["domain1"]
|
||||
@ -115,7 +115,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d1a)
|
||||
cls.user_d1a_apikey = user.apikey
|
||||
cls.user_d1a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d1b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD1B"],
|
||||
@ -126,7 +126,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d1b)
|
||||
cls.user_d1b_apikey = user.apikey
|
||||
cls.user_d1b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 1 admin and 2 user accounts for doamin_11
|
||||
cls.account_d11 = Account.create(
|
||||
cls.apiclient,
|
||||
@ -138,7 +138,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d11)
|
||||
cls.user_d11_apikey = user.apikey
|
||||
cls.user_d11_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d11a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD11A"],
|
||||
@ -149,7 +149,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d11a)
|
||||
cls.user_d11a_apikey = user.apikey
|
||||
cls.user_d11a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d11b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD11B"],
|
||||
@ -160,7 +160,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d11b)
|
||||
cls.user_d11b_apikey = user.apikey
|
||||
cls.user_d11b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 2 user accounts and 1 admin account for doamin_111
|
||||
cls.account_d111 = Account.create(
|
||||
cls.apiclient,
|
||||
@ -172,7 +172,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d111)
|
||||
cls.user_d111_apikey = user.apikey
|
||||
cls.user_d111_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d111a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD111A"],
|
||||
@ -183,7 +183,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d111a)
|
||||
cls.user_d111a_apikey = user.apikey
|
||||
cls.user_d111a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d111b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD111B"],
|
||||
@ -194,7 +194,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d111b)
|
||||
cls.user_d111b_apikey = user.apikey
|
||||
cls.user_d111b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 2 user accounts for doamin_12
|
||||
cls.account_d12a = Account.create(
|
||||
cls.apiclient,
|
||||
@ -206,7 +206,7 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d12a)
|
||||
cls.user_d12a_apikey = user.apikey
|
||||
cls.user_d12a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d12b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD12B"],
|
||||
@ -217,9 +217,9 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d12b)
|
||||
cls.user_d12b_apikey = user.apikey
|
||||
cls.user_d12b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 1 user account for domain_2
|
||||
|
||||
|
||||
cls.account_d2a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD2"],
|
||||
@ -239,22 +239,22 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
admin=False,
|
||||
)
|
||||
cls._cleanup.append(cls.account_roota)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_roota)
|
||||
cls.user_roota_apikey = user.apikey
|
||||
cls.user_roota_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_root = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountROOT"],
|
||||
admin=True,
|
||||
)
|
||||
cls._cleanup.append(cls.account_root)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_root)
|
||||
cls.user_root_apikey = user.apikey
|
||||
cls.user_root_secretkey = user.secretkey
|
||||
|
||||
|
||||
# create service offering
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
@ -265,63 +265,63 @@ class TestIsolatedNetworkDelete(cloudstackTestCase):
|
||||
cls.zone = get_zone(cls.apiclient,cls.testclient.getZoneForTests())
|
||||
cls.acldata['mode'] = cls.zone.networktype
|
||||
cls.template = get_template(cls.apiclient, cls.zone.id, cls.acldata["ostype"])
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.default_apikey
|
||||
cls.apiclient.connection.securityKey = cls.default_secretkey
|
||||
|
||||
|
||||
list_isolated_network_offerings_response = NetworkOffering.list(
|
||||
cls.apiclient,
|
||||
name="DefaultIsolatedNetworkOfferingWithSourceNatService"
|
||||
)
|
||||
cls.isolated_network_offering_id = list_isolated_network_offerings_response[0].id
|
||||
|
||||
|
||||
## Create Network objects for Update API related test cases
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_root_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_root_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_root_secretkey
|
||||
cls.network_root = cls.createNetwork(cls.apiclient,cls.account_root,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d1_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d1_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d1_secretkey
|
||||
cls.network_d1 = cls.createNetwork(cls.apiclient,cls.account_d1,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d1a_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d1a_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d1a_secretkey
|
||||
cls.network_d1a = cls.createNetwork(cls.apiclient,cls.account_d1a,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d1b_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d1b_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d1b_secretkey
|
||||
cls.network_d1b = cls.createNetwork(cls.apiclient,cls.account_d1b,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d11a_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d11a_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d11a_secretkey
|
||||
cls.network_d11a = cls.createNetwork(cls.apiclient,cls.account_d11a,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d11b_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d11b_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d11b_secretkey
|
||||
cls.network_d11b = cls.createNetwork(cls.apiclient,cls.account_d11b,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d12a_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d12a_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d12a_secretkey
|
||||
cls.network_d12a = cls.createNetwork(cls.apiclient,cls.account_d12a,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_roota_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_roota_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_roota_secretkey
|
||||
cls.network_roota = cls.createNetwork(cls.apiclient,cls.account_roota,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d111a_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d111a_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d111a_secretkey
|
||||
cls.network_d111a = cls.createNetwork(cls.apiclient,cls.account_d111a,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d111b_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d111b_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d111b_secretkey
|
||||
cls.network_d111b = cls.createNetwork(cls.apiclient,cls.account_d111b,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.user_d2a_apikey
|
||||
cls.apiclient.connection.securityKey = cls.user_d2a_secretkey
|
||||
cls.apiclient.connection.securityKey = cls.user_d2a_secretkey
|
||||
cls.network_d2a = cls.createNetwork(cls.apiclient,cls.account_d2a,cls.isolated_network_offering_id,cls.zone)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
cls.tearDownClass()
|
||||
raise Exception("Failed to create the setup required to execute the test cases: %s" % e)
|
||||
|
||||
@ -5,16 +5,16 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
"""
|
||||
Test cases relating to listSnapshot() relating to parameters - id,listall,isrecursive,account and domainid
|
||||
"""
|
||||
# Import Local Modules
|
||||
@ -63,7 +63,7 @@ class TestSnapshotList(cloudstackTestCase):
|
||||
cls.default_apikey = cls.apiclient.connection.apiKey
|
||||
cls.default_secretkey = cls.apiclient.connection.securityKey
|
||||
|
||||
# Create domains
|
||||
# Create domains
|
||||
cls.domain_1 = Domain.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["domain1"]
|
||||
@ -198,7 +198,7 @@ class TestSnapshotList(cloudstackTestCase):
|
||||
cls.user_d2a_apikey = user.apikey
|
||||
cls.user_d2a_secretkey = user.secretkey
|
||||
|
||||
# Create admin user account
|
||||
# Create admin user account
|
||||
|
||||
cls.account_a = Account.create(
|
||||
cls.apiclient,
|
||||
|
||||
@ -5,16 +5,16 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
"""
|
||||
Test cases relating to listVirtualMachine() relating to parameters - id,listall,isrecursive,account and domainid
|
||||
"""
|
||||
# Import Local Modules
|
||||
|
||||
@ -5,16 +5,16 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
"""
|
||||
Test cases relating to listVolumes() relating to parameters - id,listall,isrecursive,account and domainid
|
||||
"""
|
||||
# Import Local Modules
|
||||
@ -60,7 +60,7 @@ class TestVolumeList(cloudstackTestCase):
|
||||
cls.default_apikey = cls.apiclient.connection.apiKey
|
||||
cls.default_secretkey = cls.apiclient.connection.securityKey
|
||||
|
||||
# Create domains
|
||||
# Create domains
|
||||
cls.domain_1 = Domain.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["domain1"]
|
||||
@ -195,7 +195,7 @@ class TestVolumeList(cloudstackTestCase):
|
||||
cls.user_d2a_apikey = user.apikey
|
||||
cls.user_d2a_secretkey = user.secretkey
|
||||
|
||||
# Create admin user account
|
||||
# Create admin user account
|
||||
|
||||
cls.account_a = Account.create(
|
||||
cls.apiclient,
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -67,7 +67,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
cls.default_apikey = cls.apiclient.connection.apiKey
|
||||
cls.default_secretkey = cls.apiclient.connection.securityKey
|
||||
|
||||
# Create domains
|
||||
# Create domains
|
||||
cls.domain_1 = Domain.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["domain1"]
|
||||
@ -98,167 +98,167 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
admin=True,
|
||||
domainid=cls.domain_1.id
|
||||
)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d1)
|
||||
cls.user_d1_apikey = user.apikey
|
||||
cls.user_d1_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d1a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD1A"],
|
||||
admin=False,
|
||||
domainid=cls.domain_1.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d1a)
|
||||
cls.user_d1a_apikey = user.apikey
|
||||
cls.user_d1a_secretkey = user.secretkey
|
||||
|
||||
|
||||
|
||||
|
||||
cls.account_d1b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD1B"],
|
||||
admin=False,
|
||||
domainid=cls.domain_1.id
|
||||
)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d1b)
|
||||
cls.user_d1b_apikey = user.apikey
|
||||
cls.user_d1b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 1 admin and 2 user accounts for doamin_11
|
||||
cls.account_d11 = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD11"],
|
||||
admin=True,
|
||||
domainid=cls.domain_11.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d11)
|
||||
cls.user_d11_apikey = user.apikey
|
||||
cls.user_d11_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d11a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD11A"],
|
||||
admin=False,
|
||||
domainid=cls.domain_11.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d11a)
|
||||
cls.user_d11a_apikey = user.apikey
|
||||
cls.user_d11a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d11b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD11B"],
|
||||
admin=False,
|
||||
domainid=cls.domain_11.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d11b)
|
||||
cls.user_d11b_apikey = user.apikey
|
||||
cls.user_d11b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 2 user accounts and 1 admin account for doamin_111
|
||||
|
||||
|
||||
cls.account_d111 = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD111"],
|
||||
admin=True,
|
||||
domainid=cls.domain_111.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d111)
|
||||
cls.user_d111_apikey = user.apikey
|
||||
cls.user_d111_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d111a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD111A"],
|
||||
admin=False,
|
||||
domainid=cls.domain_111.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d111a)
|
||||
cls.user_d111a_apikey = user.apikey
|
||||
cls.user_d111a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d111b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD111B"],
|
||||
admin=False,
|
||||
domainid=cls.domain_111.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d111b)
|
||||
cls.user_d111b_apikey = user.apikey
|
||||
cls.user_d111b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 2 user accounts for doamin_12
|
||||
cls.account_d12a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD12A"],
|
||||
admin=False,
|
||||
domainid=cls.domain_12.id
|
||||
)
|
||||
)
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d12a)
|
||||
cls.user_d12a_apikey = user.apikey
|
||||
cls.user_d12a_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_d12b = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD12B"],
|
||||
admin=False,
|
||||
domainid=cls.domain_12.id
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d12b)
|
||||
cls.user_d12b_apikey = user.apikey
|
||||
cls.user_d12b_secretkey = user.secretkey
|
||||
|
||||
|
||||
# Create 1 user account for domain_2
|
||||
|
||||
|
||||
cls.account_d2a = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountD2"],
|
||||
admin=False,
|
||||
domainid=cls.domain_2.id
|
||||
)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_d2a)
|
||||
cls.user_d2a_apikey = user.apikey
|
||||
cls.user_d2a_secretkey = user.secretkey
|
||||
|
||||
|
||||
|
||||
|
||||
# Create 1 user account and admin account in "ROOT" domain
|
||||
|
||||
|
||||
cls.account_roota = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountROOTA"],
|
||||
admin=False,
|
||||
)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_roota)
|
||||
cls.user_roota_apikey = user.apikey
|
||||
cls.user_roota_secretkey = user.secretkey
|
||||
|
||||
|
||||
cls.account_root = Account.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["accountROOTA"],
|
||||
admin=True,
|
||||
)
|
||||
|
||||
|
||||
user = cls.generateKeysForUser(cls.apiclient,cls.account_root)
|
||||
cls.user_root_apikey = user.apikey
|
||||
cls.user_root_secretkey = user.secretkey
|
||||
|
||||
|
||||
# create service offering
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["service_offering"]["small"]
|
||||
)
|
||||
|
||||
|
||||
cls.zone = get_zone(cls.apiclient,cls.testclient.getZoneForTests())
|
||||
cls.acldata['mode'] = cls.zone.networktype
|
||||
cls.template = get_template(cls.apiclient, cls.zone.id, cls.acldata["ostype"])
|
||||
|
||||
|
||||
cls.apiclient.connection.apiKey = cls.default_apikey
|
||||
cls.apiclient.connection.securityKey = cls.default_secretkey
|
||||
|
||||
|
||||
list_shared_network_offerings_response = NetworkOffering.list(
|
||||
cls.apiclient,
|
||||
name="DefaultSharedNetworkOffering",
|
||||
@ -279,7 +279,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
networkofferingid=cls.shared_network_offering_id,
|
||||
zoneid=cls.zone.id
|
||||
)
|
||||
|
||||
|
||||
cls.shared_network_domain_d11 = Network.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["network_domain_with_no_subdomain_access"],
|
||||
@ -288,7 +288,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
domainid=cls.domain_11.id,
|
||||
subdomainaccess=False
|
||||
)
|
||||
|
||||
|
||||
cls.shared_network_domain_with_subdomain_d11 = Network.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["network_domain_with_subdomain_access"],
|
||||
@ -297,7 +297,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
domainid=cls.domain_11.id,
|
||||
subdomainaccess=True
|
||||
)
|
||||
|
||||
|
||||
cls.shared_network_account_d111a = Network.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["network_account"],
|
||||
@ -402,7 +402,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
Validate that regular user in any subdomain is allowed to deploy VM in a shared network created with scope="all"
|
||||
"""
|
||||
|
||||
# deploy VM as user in a subdomain under ROOT
|
||||
# deploy VM as user in a subdomain under ROOT
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d11a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d11a_secretkey
|
||||
@ -428,7 +428,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as an admin user in a subdomain under ROOT
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d11_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d11_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11"]["name"] +"-shared-scope-all"
|
||||
@ -454,7 +454,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_roota_apikey
|
||||
self.apiclient.connection.securityKey = self.user_roota_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOTA"]["name"] + "-shared-scope-all"
|
||||
@ -478,7 +478,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
Validate that admin user in ROOT domain is allowed to deploy VM in a shared network created with scope="all"
|
||||
"""
|
||||
# deploy VM as admin user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_root_apikey
|
||||
self.apiclient.connection.securityKey = self.user_root_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOT"]["name"] + "-shared-scope-all"
|
||||
@ -505,7 +505,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as user in a domain that has shared network with no subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d11a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d11a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11A"]["name"] +"-shared-scope-domain-nosubdomainaccess"
|
||||
@ -532,7 +532,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
#deploy VM as an admin user in a domain that has shared network with no subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d11_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d11_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11"]["name"] +"-shared-scope-domain-nosubdomainaccess"
|
||||
@ -558,7 +558,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as user in a subdomain under a domain that has shared network with no subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111A"]["name"] +"-shared-scope-domain-nosubdomainaccess"
|
||||
@ -585,7 +585,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as an admin user in a subdomain under a domain that has shared network with no subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111"]["name"] +"-shared-scope-domain-nosubdomainaccess"
|
||||
@ -614,7 +614,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as user in parentdomain of a domain that has shared network with no subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d1a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD1A"]["name"] +"-shared-scope-domain-nosubdomainaccess"
|
||||
@ -642,7 +642,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as an admin user in parentdomain of a domain that has shared network with no subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d1_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD1"]["name"] +"-shared-scope-domain-nosubdomainaccess"
|
||||
@ -671,12 +671,12 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_roota_apikey
|
||||
self.apiclient.connection.securityKey = self.user_roota_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOTA"]["name"] + "-shared-scope-domain-nosubdomainaccess"
|
||||
self.vmdata["displayname"] = self.acldata["vmROOTA"]["displayname"] + "-shared-scope-domain-nosubdomainaccess"
|
||||
try:
|
||||
try:
|
||||
vm = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.vmdata,
|
||||
@ -696,16 +696,16 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
@attr("simulator_only",tags=["advanced"],required_hardware="false")
|
||||
def test_deployVM_in_sharedNetwork_scope_domain_nosubdomainaccess_ROOTadmin(self):
|
||||
"""
|
||||
Validate that admin in ROOT domain is NOT allowed to deploy VM in a shared network created with scope="domain" and no subdomain access
|
||||
Validate that admin in ROOT domain is NOT allowed to deploy VM in a shared network created with scope="domain" and no subdomain access
|
||||
|
||||
"""
|
||||
# deploy VM as admin user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_root_apikey
|
||||
self.apiclient.connection.securityKey = self.user_root_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOT"]["name"] + "-shared-scope-domain-nosubdomainaccess"
|
||||
self.vmdata["displayname"] = self.acldata["vmROOT"]["displayname"] + "-shared-scope-domain-nosubdomainaccess"
|
||||
try:
|
||||
try:
|
||||
vm = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.vmdata,
|
||||
@ -731,7 +731,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as user in a domain that has shared network with subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d11a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d11a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11A"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -758,7 +758,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as an admin user in a domain that has shared network with subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d11_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d11_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -784,7 +784,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as user in a subdomain under a domain that has shared network with subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111A"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -809,7 +809,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as an admin user in a subdomain under a domain that has shared network with subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -834,7 +834,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as user in parentdomain of a domain that has shared network with subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d1a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD1A"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -862,7 +862,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as an admin user in parentdomain of a domain that has shared network with subdomain access
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d1_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD1"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -891,7 +891,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_roota_apikey
|
||||
self.apiclient.connection.securityKey = self.user_roota_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOTA"]["name"] + "-shared-scope-domain-withsubdomainaccess"
|
||||
@ -919,7 +919,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as admin user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_root_apikey
|
||||
self.apiclient.connection.securityKey = self.user_root_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOT"]["name"] + "-shared-scope-domain-withsubdomainaccess"
|
||||
@ -950,7 +950,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as user under the same domain but belonging to a different account from the acount that has a shared network with scope=account
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111b_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111b_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111B"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -979,7 +979,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as admin user for a domain that has an account with shared network with scope=account
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -1007,7 +1007,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as account with shared network with scope=account
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d111a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d111a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD111A"]["name"] +"-shared-scope-domain-withsubdomainaccess"
|
||||
@ -1032,8 +1032,8 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
Validate that regular user from a domain different from that of the account is NOT allowed to deploy VM in a shared network created with scope="account" for an account
|
||||
"""
|
||||
|
||||
# deploy VM as a user in a subdomain under ROOT
|
||||
|
||||
# deploy VM as a user in a subdomain under ROOT
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_d2a_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d2a_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD2A"]["name"] +"-shared-scope-account"
|
||||
@ -1062,7 +1062,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
|
||||
"""
|
||||
# deploy VM as user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_roota_apikey
|
||||
self.apiclient.connection.securityKey = self.user_roota_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOTA"]["name"] + "-shared-scope-account"
|
||||
@ -1090,7 +1090,7 @@ class TestSharedNetwork(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
# deploy VM as admin user in ROOT domain
|
||||
|
||||
|
||||
self.apiclient.connection.apiKey = self.user_root_apikey
|
||||
self.apiclient.connection.securityKey = self.user_root_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmROOT"]["name"] + "-shared-scope-account"
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
Test cases for deploying Virtual Machine using impersonation (passing account and domainId parameters) for shared network
|
||||
Test cases for deploying Virtual Machine using impersonation (passing account and domainId parameters) for shared network
|
||||
"""
|
||||
# Import Local Modules
|
||||
import marvin
|
||||
@ -67,7 +67,7 @@ class TestSharedNetworkImpersonation(cloudstackTestCase):
|
||||
cls.default_apikey = cls.apiclient.connection.apiKey
|
||||
cls.default_secretkey = cls.apiclient.connection.securityKey
|
||||
|
||||
# Create domains
|
||||
# Create domains
|
||||
cls.domain_1 = Domain.create(
|
||||
cls.apiclient,
|
||||
cls.acldata["domain1"]
|
||||
@ -402,7 +402,7 @@ class TestSharedNetworkImpersonation(cloudstackTestCase):
|
||||
"""
|
||||
Valiate that ROOT admin is able to deploy a VM for any user in a subdomain in a shared network with scope=all
|
||||
"""
|
||||
# Deploy VM as user in a subdomain under ROOT
|
||||
# Deploy VM as user in a subdomain under ROOT
|
||||
|
||||
self.apiclient.connection.apiKey = self.default_apikey
|
||||
self.apiclient.connection.securityKey = self.default_secretkey
|
||||
@ -984,7 +984,7 @@ class TestSharedNetworkImpersonation(cloudstackTestCase):
|
||||
Valiate that ROOT admin is NOT able to deploy a VM for a admin user in a shared network with scope=account which the admin user does not have access to
|
||||
"""
|
||||
|
||||
# Deploy VM as an admin user in a subdomain under ROOT
|
||||
# Deploy VM as an admin user in a subdomain under ROOT
|
||||
|
||||
self.apiclient.connection.apiKey = self.default_apikey
|
||||
self.apiclient.connection.securityKey = self.default_secretkey
|
||||
@ -1100,7 +1100,7 @@ class TestSharedNetworkImpersonation(cloudstackTestCase):
|
||||
Valiate that Domain admin is able to deploy a VM for a sub domain user in a shared network with scope=all
|
||||
"""
|
||||
|
||||
# Deploy VM as user in a subdomain under ROOT
|
||||
# Deploy VM as user in a subdomain under ROOT
|
||||
self.apiclient.connection.apiKey = self.user_d1_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11A"]["name"] + "-shared-scope-all-domain-admin"
|
||||
@ -1126,7 +1126,7 @@ class TestSharedNetworkImpersonation(cloudstackTestCase):
|
||||
Valiate that Domain admin is able to deploy a VM for a sub domain admin user in a shared network with scope=all
|
||||
"""
|
||||
|
||||
# Deploy VM as an admin user in a subdomain under ROOT
|
||||
# Deploy VM as an admin user in a subdomain under ROOT
|
||||
self.apiclient.connection.apiKey = self.user_d1_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD11"]["name"] + "-shared-scope-all-domain-admin"
|
||||
@ -1698,7 +1698,7 @@ class TestSharedNetworkImpersonation(cloudstackTestCase):
|
||||
Valiate that Domain admin is able NOT able to deploy a VM for an regular user from a differnt domain in a shared network with scope=account
|
||||
"""
|
||||
|
||||
# Deploy VM as an admin user in a subdomain under ROOT
|
||||
# Deploy VM as an admin user in a subdomain under ROOT
|
||||
self.apiclient.connection.apiKey = self.user_d1_apikey
|
||||
self.apiclient.connection.securityKey = self.user_d1_secretkey
|
||||
self.vmdata["name"] = self.acldata["vmD2A"]["name"] + "-shared-scope-account-domain-admin"
|
||||
|
||||
@ -65,7 +65,7 @@ class Services:
|
||||
"type": "host anti-affinity",
|
||||
},
|
||||
"virtual_machine" : {
|
||||
|
||||
|
||||
},
|
||||
"new_domain": {
|
||||
"name": "New Domain",
|
||||
|
||||
@ -6,9 +6,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -109,11 +109,11 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
|
||||
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
cls.services["template"] = cls.template.id
|
||||
cls.services["zoneid"] = cls.zone.id
|
||||
|
||||
|
||||
cls.domain_admin_account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["domain_admin_account"],
|
||||
@ -127,7 +127,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
)
|
||||
|
||||
cls.account_api_client = cls.testClient.getUserApiClient(cls.account.name, cls.domain.name, 0)
|
||||
|
||||
@ -145,7 +145,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
account=cls.domain_admin_account.name,
|
||||
domainid=cls.domain_admin_account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls.project2 = Project.create(
|
||||
cls.api_client,
|
||||
cls.services["project2"],
|
||||
@ -167,7 +167,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
cls.services["service_offering"],
|
||||
domainid=cls.account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls._cleanup = []
|
||||
return
|
||||
|
||||
@ -209,7 +209,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
return AffinityGroup.create(api_client, aff_grp, None, None, projectid)
|
||||
except Exception as e:
|
||||
raise Exception("Error: Creation of Affinity Group failed : %s" % e)
|
||||
|
||||
|
||||
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
|
||||
def test_01_admin_create_aff_grp_for_project(self):
|
||||
"""
|
||||
@ -223,7 +223,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
self.assertTrue(list_aff_grps[0].id == aff_grp.id)
|
||||
self.assertTrue(list_aff_grps[0].projectid == self.project.id)
|
||||
self.cleanup.append(aff_grp)
|
||||
|
||||
|
||||
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
|
||||
def test_02_doadmin_create_aff_grp_for_project(self):
|
||||
"""
|
||||
@ -236,7 +236,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
self.assertTrue(list_aff_grps[0].id == aff_grp.id)
|
||||
self.assertTrue(list_aff_grps[0].projectid == self.project.id)
|
||||
self.cleanup.append(aff_grp)
|
||||
|
||||
|
||||
@attr(tags=["vogxn", "simulator", "basic", "advanced"], required_hardware="false")
|
||||
def test_03_user_create_aff_grp_for_project(self):
|
||||
"""
|
||||
@ -249,19 +249,19 @@ class TestCreateAffinityGroup(cloudstackTestCase):
|
||||
self.assertTrue(list_aff_grps[0].id == aff_grp.id)
|
||||
self.assertTrue(list_aff_grps[0].projectid == self.project.id)
|
||||
self.cleanup.append(aff_grp)
|
||||
|
||||
|
||||
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
|
||||
def test_4_user_create_aff_grp_existing_name_for_project(self):
|
||||
"""
|
||||
Test create affinity group that exists (same name) for projects
|
||||
@return:
|
||||
"""
|
||||
|
||||
|
||||
failed_aff_grp = None
|
||||
aff_grp = self.create_aff_grp(api_client=self.account_api_client)
|
||||
with self.assertRaises(Exception):
|
||||
failed_aff_grp = self.create_aff_grp(api_client=self.account_api_client,aff_grp_name = aff_grp.name)
|
||||
|
||||
|
||||
if failed_aff_grp:
|
||||
self.cleanup.append(failed_aff_grp)
|
||||
self.cleanup.append(aff_grp)
|
||||
@ -284,11 +284,11 @@ class TestListAffinityGroups(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
|
||||
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
cls.services["template"] = cls.template.id
|
||||
cls.services["zoneid"] = cls.zone.id
|
||||
|
||||
|
||||
cls.domain_admin_account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["domain_admin_account"],
|
||||
@ -302,7 +302,7 @@ class TestListAffinityGroups(cloudstackTestCase):
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
)
|
||||
|
||||
cls.account_api_client = cls.testClient.getUserApiClient(cls.account.name, cls.domain.name, 0)
|
||||
|
||||
@ -320,7 +320,7 @@ class TestListAffinityGroups(cloudstackTestCase):
|
||||
account=cls.domain_admin_account.name,
|
||||
domainid=cls.domain_admin_account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls.project2 = Project.create(
|
||||
cls.api_client,
|
||||
cls.services["project2"],
|
||||
@ -342,7 +342,7 @@ class TestListAffinityGroups(cloudstackTestCase):
|
||||
cls.services["service_offering"],
|
||||
domainid=cls.account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls._cleanup = []
|
||||
return
|
||||
|
||||
@ -523,7 +523,7 @@ class TestListAffinityGroups(cloudstackTestCase):
|
||||
#Wait for expunge interval to cleanup VM
|
||||
wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
|
||||
self.cleanup.append(aff_grp)
|
||||
|
||||
|
||||
class TestDeleteAffinityGroups(cloudstackTestCase):
|
||||
|
||||
@classmethod
|
||||
@ -542,11 +542,11 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
|
||||
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
cls.services["template"] = cls.template.id
|
||||
cls.services["zoneid"] = cls.zone.id
|
||||
|
||||
|
||||
cls.domain_admin_account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["domain_admin_account"],
|
||||
@ -560,7 +560,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
)
|
||||
|
||||
cls.account_api_client = cls.testClient.getUserApiClient(cls.account.name, cls.domain.name, 0)
|
||||
|
||||
@ -578,7 +578,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
|
||||
account=cls.domain_admin_account.name,
|
||||
domainid=cls.domain_admin_account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls.project2 = Project.create(
|
||||
cls.api_client,
|
||||
cls.services["project2"],
|
||||
@ -600,7 +600,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
|
||||
cls.services["service_offering"],
|
||||
domainid=cls.account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls._cleanup = []
|
||||
return
|
||||
|
||||
@ -685,10 +685,10 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
|
||||
aff_grp2 = self.create_aff_grp(self.account_api_client)
|
||||
|
||||
aff_grp1.delete(self.account_api_client)
|
||||
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
list_aff_grps = AffinityGroup.list(self.api_client, id=aff_grp1.id)
|
||||
|
||||
|
||||
self.cleanup.append(aff_grp2)
|
||||
|
||||
@attr(tags=["simulator", "basic", "advanced"], required_hardware="false")
|
||||
@ -724,11 +724,11 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
|
||||
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
cls.services["template"] = cls.template.id
|
||||
cls.services["zoneid"] = cls.zone.id
|
||||
|
||||
|
||||
cls.domain_admin_account = Account.create(
|
||||
cls.api_client,
|
||||
cls.services["domain_admin_account"],
|
||||
@ -742,7 +742,7 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
|
||||
cls.api_client,
|
||||
cls.services["account"],
|
||||
domainid=cls.domain.id
|
||||
)
|
||||
)
|
||||
|
||||
cls.account_api_client = cls.testClient.getUserApiClient(cls.account.name, cls.domain.name, 0)
|
||||
|
||||
@ -760,7 +760,7 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
|
||||
account=cls.domain_admin_account.name,
|
||||
domainid=cls.domain_admin_account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls.project2 = Project.create(
|
||||
cls.api_client,
|
||||
cls.services["project2"],
|
||||
@ -782,7 +782,7 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
|
||||
cls.services["service_offering"],
|
||||
domainid=cls.account.domainid
|
||||
)
|
||||
|
||||
|
||||
cls._cleanup = []
|
||||
return
|
||||
|
||||
@ -891,7 +891,7 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase):
|
||||
wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
|
||||
aff_grp1.delete(self.api_client)
|
||||
aff_grp2.delete(self.api_client)
|
||||
|
||||
|
||||
|
||||
class TestDeployVMAffinityGroups(cloudstackTestCase):
|
||||
|
||||
@ -911,7 +911,7 @@ class TestDeployVMAffinityGroups(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.services["ostype"]
|
||||
)
|
||||
|
||||
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
cls.services["template"] = cls.template.id
|
||||
cls.services["zoneid"] = cls.zone.id
|
||||
@ -972,7 +972,7 @@ class TestDeployVMAffinityGroups(cloudstackTestCase):
|
||||
cls.services["service_offering"],
|
||||
domainid=cls.account.domainid
|
||||
)
|
||||
|
||||
|
||||
return
|
||||
|
||||
def setUp(self):
|
||||
@ -1074,9 +1074,9 @@ class TestDeployVMAffinityGroups(cloudstackTestCase):
|
||||
vm_failed = None
|
||||
with self.assertRaises(Exception):
|
||||
vm_failed = self.create_vm_in_aff_grps(self.account_api_client,ag_list=[aff_grp.name])
|
||||
|
||||
|
||||
self.assertEqual(len(hosts), len(vms), "Received %s and %s " % (hosts, vms))
|
||||
|
||||
|
||||
if vm_failed:
|
||||
vm_failed.expunge(self.api_client)
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -422,7 +422,7 @@ class TestVMOwnership(cloudstackTestCase):
|
||||
self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'], snapshot=True)
|
||||
with self.assertRaises(Exception):
|
||||
self.virtual_machine.assign_virtual_machine(self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id)
|
||||
|
||||
|
||||
@attr(tags = ["advanced"])
|
||||
@log_test_exceptions
|
||||
def test_14_move_across_subdomain_vm_project(self):
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -86,7 +86,7 @@ class TestBaremetal(cloudstackTestCase):
|
||||
networkoffering = NetworkOffering.create(self.apiclient, self.services["network_offering"])
|
||||
networkoffering.update(self.apiclient, state="Enabled")
|
||||
self.cleanup.append(networkoffering)
|
||||
|
||||
|
||||
physical_network = PhysicalNetwork.list(self.apiclient, zoneid=self.zoneid)[0];
|
||||
dhcp_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalDhcpProvider", physical_network_id=physical_network.id)[0]
|
||||
NetworkServiceProvider.update(
|
||||
@ -106,10 +106,10 @@ class TestBaremetal(cloudstackTestCase):
|
||||
id=userdata_provider.id,
|
||||
state='Enabled'
|
||||
)
|
||||
|
||||
|
||||
network = Network.create(self.apiclient, self.services["network"], zoneid=self.zoneid, networkofferingid=networkoffering.id)
|
||||
self.cleanup.insert(0, network)
|
||||
|
||||
|
||||
pod = Pod.list(self.apiclient)[0]
|
||||
cmd = createVlanIpRange.createVlanIpRangeCmd()
|
||||
cmd.podid = pod.id
|
||||
@ -120,4 +120,4 @@ class TestBaremetal(cloudstackTestCase):
|
||||
cmd.endip = "10.1.1.40"
|
||||
cmd.forVirtualNetwork="false"
|
||||
self.apiclient.createVlanIpRange(cmd)
|
||||
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -177,8 +177,8 @@ class TestTemplate(cloudstackTestCase):
|
||||
#3. Deploy VM should return password set in template.
|
||||
|
||||
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
|
||||
self.services["template"]["url"] = builtin_info[0]
|
||||
self.services["template"]["hypervisor"] = builtin_info[1]
|
||||
self.services["template"]["url"] = builtin_info[0]
|
||||
self.services["template"]["hypervisor"] = builtin_info[1]
|
||||
self.services["template"]["format"] = builtin_info[2]
|
||||
temp = self.services["template"]
|
||||
self.debug("Registering a new template")
|
||||
|
||||
@ -80,7 +80,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
"Check for default cent OS template readiness ")
|
||||
|
||||
cls.service_offering = ServiceOffering.create(
|
||||
cls.apiclient,
|
||||
cls.apiclient,
|
||||
cls.testdata["service_offering"]
|
||||
)
|
||||
cls._cleanup.append(cls.service_offering)
|
||||
@ -267,7 +267,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
uploadfile = url.split('/')[-1]
|
||||
r = requests.get(url, stream=True)
|
||||
with open(uploadfile, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk: # filter out keep-alive new chunks
|
||||
f.write(chunk)
|
||||
f.flush()
|
||||
@ -285,7 +285,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
results = requests.post(posturl,files=files,headers=headers,verify=False)
|
||||
|
||||
print(results.status_code)
|
||||
if results.status_code !=200:
|
||||
if results.status_code !=200:
|
||||
self.fail("Upload is not fine")
|
||||
|
||||
self.validate_uploaded_template(self.apiclient, getuploadparamsresponce.id)
|
||||
@ -366,7 +366,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
uploadfile = url.split('/')[-1]
|
||||
r = requests.get(url, stream=True)
|
||||
with open(uploadfile, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk: # filter out keep-alive new chunks
|
||||
f.write(chunk)
|
||||
f.flush()
|
||||
@ -378,7 +378,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
results = requests.post(posturl,files=files,headers=headers,verify=False)
|
||||
|
||||
print(results.status_code)
|
||||
if results.status_code !=200:
|
||||
if results.status_code !=200:
|
||||
self.fail("Upload is not fine")
|
||||
|
||||
self.validate_uploaded_template(self.apiclient, getuploadparamsresponce.id)
|
||||
@ -410,7 +410,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
uploadfile = url.split('/')[-1]
|
||||
r = requests.get(url, stream=True)
|
||||
with open(uploadfile, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk: # filter out keep-alive new chunks
|
||||
f.write(chunk)
|
||||
f.flush()
|
||||
@ -428,7 +428,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
results = requests.post(posturl,files=files,headers=headers,verify=False)
|
||||
|
||||
print(results.status_code)
|
||||
if results.status_code !=200:
|
||||
if results.status_code !=200:
|
||||
self.fail("Upload is not fine")
|
||||
|
||||
for z1 in lzones:
|
||||
@ -459,7 +459,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
uploadfile = url.split('/')[-1]
|
||||
r = requests.get(url, stream=True)
|
||||
with open(uploadfile, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk: # filter out keep-alive new chunks
|
||||
f.write(chunk)
|
||||
f.flush()
|
||||
@ -478,7 +478,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
time.sleep(60)
|
||||
|
||||
print(results.status_code)
|
||||
if results.status_code !=200:
|
||||
if results.status_code !=200:
|
||||
self.fail("Upload is not fine")
|
||||
|
||||
return(getuploadparamsresponce)
|
||||
@ -959,7 +959,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
)
|
||||
|
||||
list_zones_response = list_zones(self.apiclient)
|
||||
|
||||
|
||||
self.assertEqual(
|
||||
isinstance(list_zones_response, list),
|
||||
True,
|
||||
@ -1014,13 +1014,13 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
"Check list response returns a valid list"
|
||||
)
|
||||
iprange = ipranges_response[0]
|
||||
|
||||
|
||||
#Fetch corresponding Physical Network of SSVM's Zone
|
||||
listphyntwk = PhysicalNetwork.list(
|
||||
self.apiclient,
|
||||
zoneid=ssvm.zoneid
|
||||
)
|
||||
|
||||
|
||||
# Execute the following assertion in all zones except EIP-ELB Zones
|
||||
if not (self.zone.networktype.lower() == 'basic' and isinstance(NetScaler.list(self.apiclient,physicalnetworkid=listphyntwk[0].id), list) is True):
|
||||
self.assertEqual(
|
||||
@ -1082,7 +1082,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
cmd = stopSystemVm.stopSystemVmCmd()
|
||||
cmd.id = ssvm.id
|
||||
self.apiclient.stopSystemVm(cmd)
|
||||
|
||||
|
||||
timeout = self.testdata["timeout"]
|
||||
while True:
|
||||
list_ssvm_response = list_ssvms(
|
||||
@ -1094,10 +1094,10 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
break
|
||||
if timeout == 0:
|
||||
raise Exception("List SSVM call failed!")
|
||||
|
||||
|
||||
time.sleep(self.testdata["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
|
||||
self.assertEqual(
|
||||
isinstance(list_ssvm_response, list),
|
||||
True,
|
||||
@ -1124,13 +1124,13 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
state='Running',
|
||||
zoneid=self.zone.id
|
||||
)
|
||||
|
||||
|
||||
self.assertEqual(
|
||||
isinstance(list_ssvm_response, list),
|
||||
True,
|
||||
"Check list response returns a valid list"
|
||||
)
|
||||
|
||||
|
||||
ssvm_response = list_ssvm_response[0]
|
||||
|
||||
hosts = list_hosts(
|
||||
@ -1164,7 +1164,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
break
|
||||
if timeout == 0:
|
||||
raise Exception("List SSVM call failed!")
|
||||
|
||||
|
||||
time.sleep(self.testdata["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
@ -1227,7 +1227,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
break
|
||||
if timeout == 0:
|
||||
raise Exception("List SSVM call failed!")
|
||||
|
||||
|
||||
time.sleep(self.testdata["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
@ -1257,7 +1257,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
True,
|
||||
"Check whether SSVM has public IP field"
|
||||
)
|
||||
|
||||
|
||||
# Wait for the agent to be up
|
||||
self.waitForSystemVMAgent(ssvm_response.name)
|
||||
|
||||
@ -1510,10 +1510,10 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
@attr(tags = ["TODO"], required_hardware="true")
|
||||
def test_02_SSVM_Life_Cycle_With_Browser_Template_TPath(self):
|
||||
"""
|
||||
Test SSVM_Life_Cycle_With_Browser_template_TPath
|
||||
Test SSVM_Life_Cycle_With_Browser_template_TPath
|
||||
"""
|
||||
try:
|
||||
|
||||
|
||||
self.debug("========================= Test 11: Stop and Start SSVM and Perform Browser based volume validations ========================= ")
|
||||
|
||||
self.stop_ssvm()
|
||||
|
||||
@ -1978,7 +1978,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
@attr(tags=["advanced", "advancedns", "smoke", "basic"], required_hardware="true")
|
||||
def test_01_Browser_volume_Life_cycle_tpath(self):
|
||||
"""
|
||||
Test Browser_volume_Life_cycle - This includes upload volume,attach to a VM, write data ,Stop ,Start, Reboot,Reset of a VM, detach,attach back to the VM, delete volumes
|
||||
Test Browser_volume_Life_cycle - This includes upload volume,attach to a VM, write data ,Stop ,Start, Reboot,Reset of a VM, detach,attach back to the VM, delete volumes
|
||||
"""
|
||||
try:
|
||||
|
||||
@ -2228,7 +2228,7 @@ class TestBrowseUploadVolume(cloudstackTestCase):
|
||||
@attr(tags=["advanced", "advancedns", "smoke", "basic"], required_hardware="true")
|
||||
def test_03_Browser_Upload_Volume_Global_Config_TPath(self):
|
||||
"""
|
||||
Test Browser_Upload_Volume_Global_Config limits
|
||||
Test Browser_Upload_Volume_Global_Config limits
|
||||
"""
|
||||
try:
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ class TestHostHA(cloudstackTestCase):
|
||||
self.logger.addHandler(self.stream_handler)
|
||||
self.apiclient = self.testClient.getApiClient()
|
||||
self.hypervisor = self.testClient.getHypervisorInfo()
|
||||
self.mgtSvrDetails = self.config.__dict__["mgtSvr"][0].__dict__
|
||||
self.mgtSvrDetails = self.config.__dict__["mgtSvr"][0].__dict__
|
||||
self.dbclient = self.testClient.getDbConnection()
|
||||
self.services = self.testClient.getParsedTestDataConfig()
|
||||
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
|
||||
@ -85,7 +85,7 @@ class TestHostHA(cloudstackTestCase):
|
||||
"sleep": 60,
|
||||
"timeout": 10,
|
||||
}
|
||||
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
try:
|
||||
@ -96,10 +96,10 @@ class TestHostHA(cloudstackTestCase):
|
||||
raise Exception("Warning: Exception during cleanup : %s" % e)
|
||||
|
||||
return
|
||||
|
||||
|
||||
def checkHostDown(self, fromHostIp, testHostIp):
|
||||
try:
|
||||
ssh = SshClient(fromHostIp, 22, "root", "password")
|
||||
ssh = SshClient(fromHostIp, 22, "root", "password")
|
||||
res = ssh.execute("ping -c 1 %s" % testHostIp)
|
||||
result = str(res)
|
||||
if result.count("100% packet loss") == 1:
|
||||
@ -109,10 +109,10 @@ class TestHostHA(cloudstackTestCase):
|
||||
except Exception as e:
|
||||
self.logger.debug("Got exception %s" % e)
|
||||
return False, 1
|
||||
|
||||
|
||||
def checkHostUp(self, fromHostIp, testHostIp):
|
||||
try:
|
||||
ssh = SshClient(fromHostIp, 22, "root", "password")
|
||||
ssh = SshClient(fromHostIp, 22, "root", "password")
|
||||
res = ssh.execute("ping -c 1 %s" % testHostIp)
|
||||
result = str(res)
|
||||
if result.count(" 0% packet loss") == 1:
|
||||
@ -122,7 +122,7 @@ class TestHostHA(cloudstackTestCase):
|
||||
except Exception as e:
|
||||
self.logger.debug("Got exception %s" % e)
|
||||
return False, 1
|
||||
|
||||
|
||||
def checkHostStateInCloudstack(self, state, hostId):
|
||||
try:
|
||||
listHost = Host.list(
|
||||
@ -137,7 +137,7 @@ class TestHostHA(cloudstackTestCase):
|
||||
True,
|
||||
"Check if listHost returns a valid response"
|
||||
)
|
||||
|
||||
|
||||
self.assertEqual(
|
||||
len(listHost),
|
||||
1,
|
||||
@ -181,7 +181,7 @@ class TestHostHA(cloudstackTestCase):
|
||||
def test_01_host_ha_with_nfs_storagepool_with_vm(self):
|
||||
Configurations.update(self.apiclient, "ping.timeout", "150")
|
||||
self.updateConfigurAndRestart("ping.interval", "150")
|
||||
|
||||
|
||||
listHost = Host.list(
|
||||
self.apiclient,
|
||||
type='Routing',
|
||||
@ -190,11 +190,11 @@ class TestHostHA(cloudstackTestCase):
|
||||
)
|
||||
for host in listHost:
|
||||
self.logger.debug('Hypervisor = {}'.format(host.id))
|
||||
|
||||
|
||||
|
||||
hostToTest = listHost[0]
|
||||
hostUpInCloudstack = wait_until(40, 10, self.checkHostStateInCloudstack, "Up", hostToTest.id)
|
||||
|
||||
if not(hostUpInCloudstack):
|
||||
if not(hostUpInCloudstack):
|
||||
raise self.fail("Host is not up %s, in cloudstack so failing test " % (hostToTest.ipaddress))
|
||||
return
|
||||
return
|
||||
|
||||
@ -79,7 +79,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
cls.apiclient,
|
||||
type="Routing"
|
||||
)
|
||||
|
||||
|
||||
if hosts is None:
|
||||
raise unittest.SkipTest(
|
||||
"There are no hypervisor's available.Check list hosts response")
|
||||
@ -98,7 +98,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
raise unittest.SkipTest("Interop is not supported on KVM")
|
||||
|
||||
cls.uploadurl=cls.services["interop"][cls.uploadtemplateformat]["url"]
|
||||
|
||||
|
||||
cls.xtemplate = get_template(
|
||||
cls.apiclient,
|
||||
cls.zone.id,
|
||||
@ -140,7 +140,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
timeout = cls.services["vgpu"]["timeout"]
|
||||
|
||||
while True:
|
||||
time.sleep(cls.services["vgpu"]["sleep"])
|
||||
time.sleep(cls.services["vgpu"]["sleep"])
|
||||
list_template_response = Template.list(
|
||||
cls.apiclient,
|
||||
templatefilter=cls.services["templatefilter"],
|
||||
@ -182,7 +182,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
cls.services["small"],
|
||||
accountid=cls.account.name,
|
||||
domainid=cls.account.domainid,
|
||||
serviceofferingid=cls.service_offering.id,
|
||||
serviceofferingid=cls.service_offering.id,
|
||||
mode=cls.services['mode'],
|
||||
startvm="false"
|
||||
)
|
||||
@ -324,7 +324,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
for zone1 in listallzones:
|
||||
if zone1.allocationstate=="Enabled":
|
||||
zonesavailable=zonesavailable+1
|
||||
|
||||
|
||||
if zonesavailable<1:
|
||||
self.fail("Check if zones are listed")
|
||||
|
||||
@ -450,7 +450,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
@attr(tags = ["devcloud", "advanced", "advancedns", "basic", "sg"], required_hardware="true")
|
||||
def test_07_start_vm(self):
|
||||
"""
|
||||
Test Start Stopped Virtual Machine with volumes attached
|
||||
Test Start Stopped Virtual Machine with volumes attached
|
||||
"""
|
||||
|
||||
list_vm_response = VirtualMachine.list(
|
||||
@ -502,7 +502,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
"""
|
||||
|
||||
vm_available=0
|
||||
|
||||
|
||||
cmd = listVirtualMachines.listVirtualMachinesCmd()
|
||||
cmd.listall = True
|
||||
cmd.zoneid=self.zone.id
|
||||
@ -563,7 +563,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
@attr(tags = ["devcloud", "advanced", "advancedns", "basic", "sg"], required_hardware="true")
|
||||
def test_10_detach_volume(self):
|
||||
"""
|
||||
Test Detach Volume
|
||||
Test Detach Volume
|
||||
"""
|
||||
|
||||
list_volume_response1 = Volume.list(
|
||||
@ -1200,7 +1200,7 @@ class TestXDCCPInterop(cloudstackTestCase):
|
||||
self.skipTest("template creation from volume feature is not supported on %s" % self.hypervisor.lower())
|
||||
|
||||
try:
|
||||
|
||||
|
||||
noffering=NetworkOffering.list(
|
||||
self.user_api_client,
|
||||
name="DefaultIsolatedNetworkOfferingWithSourceNatService"
|
||||
|
||||
@ -1146,10 +1146,10 @@ class TestGuestNetworkWithNetScaler(_NetScalerDeployVMBase):
|
||||
"""
|
||||
|
||||
# Validate the following
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 2. Create a Network offering with LB services provided by Netscaler
|
||||
# and all other services by VR.
|
||||
# 3.Create a new account/user.
|
||||
# 3.Create a new account/user.
|
||||
# 4. Deploy the first VM using a network from the above created
|
||||
# Network offering.
|
||||
# In Netscaler:
|
||||
@ -1268,10 +1268,10 @@ class TestGuestNetworkWithNetScaler(_NetScalerDeployVMBase):
|
||||
"""
|
||||
|
||||
# Validate the following
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 2. Create a Network offering with LB services provided by Netscaler
|
||||
# and all other services by VR.
|
||||
# 3.Create a new account/user.
|
||||
# 3.Create a new account/user.
|
||||
# 4. Deploy the first VM using a network from the above created
|
||||
# Network offering.
|
||||
# In Netscaler:
|
||||
@ -2031,7 +2031,7 @@ class TestServiceProvider(_NetScalerDeployVMBase):
|
||||
"""
|
||||
|
||||
# Validate the following
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 2. Create a Network offering. Do not enable the network offering
|
||||
# 3. Try to create a network with this network offering.
|
||||
# 4. Network creation should fail
|
||||
@ -2077,7 +2077,7 @@ class TestServiceProvider(_NetScalerDeployVMBase):
|
||||
"""
|
||||
|
||||
# Validate the following
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 2. Disable the service provider. Create a Network offering.
|
||||
# 3. Try to create a network. Network creation should fail
|
||||
|
||||
@ -2110,7 +2110,7 @@ class TestServiceProvider(_NetScalerDeployVMBase):
|
||||
"""
|
||||
|
||||
# Validate the following
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 2. Create a Network offering. Create instances and acquire public Ip
|
||||
# 3. Disabled service provider and again try to create LB rules
|
||||
# 4.Deploy VM should fail
|
||||
@ -2274,10 +2274,10 @@ class TestDeleteNetscaler(_NetScalerDeployVMBase):
|
||||
"""
|
||||
|
||||
# Validate the following
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 1. Configure Netscaler for load balancing.
|
||||
# 2. Create a Network offering with LB services provided by Netscaler
|
||||
# and all other services by VR.
|
||||
# 3.Create a new account/user.
|
||||
# 3.Create a new account/user.
|
||||
# 4. Deploy the first VM using a network from the above created
|
||||
# Network offering.
|
||||
# 5. Attempt to delete Netscaler load balancer from zone.
|
||||
|
||||
@ -1663,7 +1663,7 @@ class TestLbAlgoSbLc(cloudstackTestCase):
|
||||
except Exception as e:
|
||||
if cls.exception_string.lower() in e.lower():
|
||||
cls.skiptest = True
|
||||
cls.exception_msg =e
|
||||
cls.exception_msg =e
|
||||
else:
|
||||
cls.tearDownClass()
|
||||
raise Exception("Warning: Exception in setUpClass: %s" % e)
|
||||
|
||||
@ -132,7 +132,7 @@ class TestNonContiguousVLANRanges(cloudstackTestCase):
|
||||
|
||||
self.physicalnetworkid = self.physicalnetwork.id
|
||||
self.existingvlan = self.physicalnetwork.vlan
|
||||
|
||||
|
||||
if self.vlan == None:
|
||||
self.fail("Failed to set non contiguous vlan ids to test. Free some ids from \
|
||||
from existing physical networks at extreme ends")
|
||||
|
||||
@ -5,16 +5,16 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""
|
||||
"""
|
||||
|
||||
Test cases relating to enabling/diabling of zone/pod/cluster/host
|
||||
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@ -1213,7 +1213,7 @@ class TestProjectInviteTimeout(cloudstackTestCase):
|
||||
|
||||
def test_09_invite_to_project_by_email(self):
|
||||
"""Test invite user to project by email"""
|
||||
|
||||
|
||||
# Validate the following:
|
||||
# 1. Set configuration to 5 mins
|
||||
# 2. Create a Project
|
||||
|
||||
@ -909,7 +909,7 @@ class TestResourceLimitsProject(cloudstackTestCase):
|
||||
max=1,
|
||||
projectid=self.project.id
|
||||
)
|
||||
|
||||
|
||||
# Register the First Template in the project
|
||||
self.debug("Register the First Template in the project")
|
||||
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
|
||||
@ -949,7 +949,7 @@ class TestResourceLimitsProject(cloudstackTestCase):
|
||||
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
|
||||
#Verify template response to check whether template added successfully
|
||||
self.assertEqual(
|
||||
isinstance(list_template_response, list),
|
||||
|
||||
@ -871,7 +871,7 @@ class TestTemplateUsage(cloudstackTestCase):
|
||||
|
||||
time.sleep(self.services["sleep"])
|
||||
timeout = timeout - 1
|
||||
|
||||
|
||||
#Verify template response to check whether template added successfully
|
||||
self.assertEqual(
|
||||
isinstance(list_template_response, list),
|
||||
@ -891,9 +891,9 @@ class TestTemplateUsage(cloudstackTestCase):
|
||||
True,
|
||||
"Template state is not ready, it is %s" % template_response.isready
|
||||
)
|
||||
|
||||
|
||||
self.debug("Created template with ID: %s" % template.id)
|
||||
|
||||
|
||||
# Delete template
|
||||
template.delete(self.apiclient)
|
||||
self.debug("Deleted template with ID: %s" % template.id)
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -94,7 +94,7 @@ class TestSecSRMount(cloudstackTestCase):
|
||||
for storage_pool in storage_pools:
|
||||
if storage_pool.type == 'NetworkFilesystem':
|
||||
return False
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def download(self, apiclient, template_id, retries=12, interval=5):
|
||||
@ -149,10 +149,10 @@ class TestSecSRMount(cloudstackTestCase):
|
||||
"xenserver"],
|
||||
required_hardware="true")
|
||||
def test_01_prepare_template_local_storage(self):
|
||||
|
||||
|
||||
if not self.isOnlyLocalStorageAvailable():
|
||||
self.skipTest("Skipping this test as this is for Local storage on only.")
|
||||
|
||||
|
||||
listHost = Host.list(
|
||||
self.apiclient,
|
||||
type='Routing',
|
||||
@ -161,20 +161,20 @@ class TestSecSRMount(cloudstackTestCase):
|
||||
)
|
||||
for host in listHost:
|
||||
self.logger.debug('Host id %s, hypervisor %s, localstorage %s' % (host.id, host.hypervisor, host.islocalstorageactive))
|
||||
|
||||
|
||||
if len(listHost) < 2:
|
||||
self.logger.debug("Prepare secondary storage race condition can be tested with two or more host only %s, found" % len(listHost));
|
||||
self.skipTest("Prepare secondary storage can be tested with two host only %s, found" % len(listHost))
|
||||
|
||||
|
||||
list_template_response = Template.list(
|
||||
self.apiclient,
|
||||
templatefilter='all',
|
||||
zoneid=self.zone.id)
|
||||
|
||||
|
||||
template_response = list_template_response[0]
|
||||
|
||||
|
||||
self.logger.debug('Template id %s is Ready %s' % (template_response.id, template_response.isready))
|
||||
|
||||
|
||||
if template_response.isready != True:
|
||||
self.skipTest('Template id %s is Not Ready' % (template_response.id))
|
||||
|
||||
|
||||
@ -764,10 +764,10 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
|
||||
# Get Zone, Domain and templates
|
||||
cls.hypervisor = cls.testClient.getHypervisorInfo()
|
||||
cls.skip = False
|
||||
|
||||
|
||||
if cls.hypervisor.lower() == 'lxc':
|
||||
if not find_storage_pool_type(cls.apiclient, storagetype='rbd'):
|
||||
cls.skip = True
|
||||
cls.skip = True
|
||||
return
|
||||
|
||||
cls.domain = get_domain(cls.api_client)
|
||||
|
||||
@ -292,7 +292,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
tag['resid'],
|
||||
tag['restype'],
|
||||
{concrete_tag['key']: concrete_tag['value']})
|
||||
|
||||
|
||||
return
|
||||
|
||||
@attr(tags=["advanced"], required_hardware="false")
|
||||
@ -880,7 +880,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope5'
|
||||
tag_value = 'test_05_vm_tag'
|
||||
|
||||
|
||||
self.debug("Creating a tag for user VM")
|
||||
tag = Tag.create(
|
||||
self.apiclient,
|
||||
@ -1165,7 +1165,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope8'
|
||||
tag_value = 'test_08_volume_tag'
|
||||
|
||||
|
||||
if self.hypervisor.lower() == 'lxc':
|
||||
if not find_storage_pool_type(self.apiclient, storagetype='rbd'):
|
||||
self.skipTest("RBD storage type is required for data volumes for LXC")
|
||||
@ -1366,7 +1366,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope10'
|
||||
tag_value = 'test_10_network_tag'
|
||||
|
||||
|
||||
self.debug("Fetching the network details for account: %s" %
|
||||
self.account.name)
|
||||
networks = Network.list(
|
||||
@ -1465,7 +1465,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope11'
|
||||
tag_value = 'test_11_migrate_tagged_vm_del'
|
||||
|
||||
|
||||
if self.hypervisor.lower() in ['lxc']:
|
||||
self.skipTest("vm migrate feature is not supported on %s" % self.hypervisor.lower())
|
||||
|
||||
@ -1578,7 +1578,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope13'
|
||||
tag_value = 'test_13_tag_case_insensitive'
|
||||
|
||||
|
||||
self.debug("Creating a tag for user VM")
|
||||
tag_1 = Tag.create(
|
||||
self.apiclient,
|
||||
@ -1656,7 +1656,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope14'
|
||||
tag_value = 'test_14_special_char_mutiple_tags'
|
||||
|
||||
|
||||
self.debug("Creating a tag for user VM")
|
||||
tag = Tag.create(
|
||||
self.apiclient,
|
||||
@ -1729,7 +1729,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope15'
|
||||
tag_value = 'test_15_project_tag'
|
||||
|
||||
|
||||
# Create project as a domain admin
|
||||
project = Project.create(
|
||||
self.apiclient,
|
||||
@ -1824,9 +1824,9 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope16'
|
||||
tag_value = 'test_16_query_tags_other_account'
|
||||
|
||||
|
||||
self.debug("Creating user accounts..")
|
||||
|
||||
|
||||
user_account = Account.create(
|
||||
self.apiclient,
|
||||
self.services["user"],
|
||||
@ -1910,7 +1910,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
)
|
||||
except Exception as e:
|
||||
self.fail("Failed to delete the tag - %s" % e)
|
||||
|
||||
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "basic"], required_hardware="false")
|
||||
@ -1925,7 +1925,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope17'
|
||||
tag_value = 'test_17_query_tags_admin_account'
|
||||
|
||||
|
||||
self.debug("Creating user accounts..")
|
||||
|
||||
user_account = Account.create(
|
||||
@ -2000,7 +2000,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
)
|
||||
except Exception as e:
|
||||
self.fail("Failed to delete the tag - %s" % e)
|
||||
|
||||
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "basic", "simulator"], required_hardware="false")
|
||||
@ -2013,7 +2013,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope18'
|
||||
tag_value = 'test_18_invalid_list_parameters'
|
||||
|
||||
|
||||
self.debug("Creating a tag for user VM")
|
||||
tag = Tag.create(
|
||||
self.apiclient,
|
||||
@ -2060,8 +2060,8 @@ class TestResourceTags(cloudstackTestCase):
|
||||
# 2. Add same tag.
|
||||
|
||||
tag_key = 'scope19'
|
||||
tag_value = 'test_19_delete_add_same_tag'
|
||||
|
||||
tag_value = 'test_19_delete_add_same_tag'
|
||||
|
||||
self.debug("Creating a tag for user VM")
|
||||
tag = Tag.create(
|
||||
self.apiclient,
|
||||
@ -2165,9 +2165,9 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope20'
|
||||
tag_value = 'test_20_create_tags_multiple_resources'
|
||||
|
||||
|
||||
self.debug("Creating volume for account: %s " % self.account.name)
|
||||
|
||||
|
||||
volume = Volume.create(
|
||||
self.apiclient,
|
||||
self.services["volume"],
|
||||
@ -2272,8 +2272,8 @@ class TestResourceTags(cloudstackTestCase):
|
||||
"Test creation of tag on stopped vm."
|
||||
|
||||
tag_key = 'scope21'
|
||||
tag_value = 'test_21_create_tag_stopped_vm'
|
||||
|
||||
tag_value = 'test_21_create_tag_stopped_vm'
|
||||
|
||||
try:
|
||||
self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
|
||||
# Stop virtual machine
|
||||
@ -2326,7 +2326,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope22'
|
||||
tag_value = 'test_22_create_tag_destroyed_vm'
|
||||
|
||||
|
||||
self.debug("Destroying instance: %s" % self.vm_1.name)
|
||||
self.vm_1.delete(self.apiclient, expunge=False)
|
||||
|
||||
@ -2481,7 +2481,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key = 'scope24'
|
||||
tag_value = 'test_24_public_ip_tag'
|
||||
|
||||
|
||||
self.debug("Creating a sub-domain under: %s" % self.domain.name)
|
||||
self.child_domain = Domain.create(
|
||||
self.apiclient,
|
||||
@ -2652,7 +2652,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
received_tag_map = {}
|
||||
for t in received_tags:
|
||||
received_tag_map[t.key] = t.value
|
||||
|
||||
|
||||
self.assertEqual(
|
||||
set_tags,
|
||||
received_tag_map,
|
||||
@ -2680,7 +2680,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
"List tags should return empty list response when tags are removed."
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
@attr(tags=["advanced","basic"], required_hardware="false")
|
||||
def test_25_admin_account_tags(self):
|
||||
'''Test create, list, delete tag for admin account from admin account'''
|
||||
@ -2689,7 +2689,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
self.__test_account_tags(self.apiclient, admin_account[0])
|
||||
return
|
||||
|
||||
@attr(tags=["advanced","basic"], required_hardware="false")
|
||||
@attr(tags=["advanced","basic"], required_hardware="false")
|
||||
def test_26_domain_admin_account_tags(self):
|
||||
child_domain = Domain.create(
|
||||
self.apiclient,
|
||||
@ -2725,7 +2725,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
regular_account_api_client = self.testClient.getUserApiClient(UserName=regular_account.name, DomainName=self.domain.name)
|
||||
self.__test_account_tags(regular_account_api_client, regular_account)
|
||||
return
|
||||
|
||||
|
||||
@attr(tags=["advanced","basic"], required_hardware="false")
|
||||
def test_28_admin_access_domain_admin_account_tags(self):
|
||||
'''Test create, list, delete tag for domain admin account from admin account'''
|
||||
@ -2783,7 +2783,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
)
|
||||
# Cleanup the resources created at end of test
|
||||
self.cleanup.append(regular_account)
|
||||
|
||||
|
||||
# Cleanup the resources created at end of test
|
||||
self.cleanup.append(child_domain_admin)
|
||||
self.cleanup.append(child_domain)
|
||||
@ -2804,14 +2804,14 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key_admin = 'scope31_admin'
|
||||
tag_value_admin = 'test_31_user_cant_remove_update_admin_tags'
|
||||
|
||||
|
||||
regular_account = Account.create(
|
||||
self.apiclient,
|
||||
self.services["account"],
|
||||
admin=False
|
||||
)
|
||||
self.cleanup.append(regular_account)
|
||||
|
||||
|
||||
regular_account_api_client = self.testClient.getUserApiClient(UserName=regular_account.name, DomainName=self.domain.name)
|
||||
|
||||
def create_admin_tag():
|
||||
@ -2820,7 +2820,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
resourceIds=regular_account.id,
|
||||
resourceType='Account',
|
||||
tags={ tag_key_admin: tag_value_admin})
|
||||
|
||||
|
||||
|
||||
def create_user_tag():
|
||||
return Tag.create(
|
||||
@ -2828,7 +2828,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
resourceIds=regular_account.id,
|
||||
resourceType='Account',
|
||||
tags={ tag_key_user: tag_value_user})
|
||||
|
||||
|
||||
create_admin_tag()
|
||||
create_user_tag()
|
||||
|
||||
@ -2845,7 +2845,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
def tags_to_map(tags):
|
||||
m = {}
|
||||
for t in tags:
|
||||
m[t.key] = t.value
|
||||
m[t.key] = t.value
|
||||
return m
|
||||
|
||||
# admin requests user account tags and gets None (without listall)
|
||||
@ -2870,7 +2870,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
tags_to_map(received_tags_user),
|
||||
{tag_key_admin: tag_value_admin, tag_key_user: tag_value_user},
|
||||
"List (with listAll=false) tags should return information for user tags"
|
||||
)
|
||||
)
|
||||
|
||||
# user requests own account tags and receives all (with listall)
|
||||
received_tags_user_listall = list_tags(regular_account_api_client, True)
|
||||
@ -2879,11 +2879,11 @@ class TestResourceTags(cloudstackTestCase):
|
||||
{tag_key_admin: tag_value_admin, tag_key_user: tag_value_user},
|
||||
"List (with listAll=false) tags should return information for user tags"
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Delete test expressions
|
||||
#
|
||||
|
||||
|
||||
def delete_tags(apiclient, tags):
|
||||
Tag.delete(
|
||||
apiclient,
|
||||
@ -2891,12 +2891,12 @@ class TestResourceTags(cloudstackTestCase):
|
||||
resourceType='Account',
|
||||
tags=tags)
|
||||
|
||||
# user tries to delete admin tag on own account and succeeds
|
||||
# user tries to delete admin tag on own account and succeeds
|
||||
try:
|
||||
delete_tags(regular_account_api_client, {tag_key_admin: tag_value_admin})
|
||||
except Exception as e:
|
||||
self.fail("Regular user is not able to delete administrator tag on own account - %s" % e)
|
||||
|
||||
|
||||
# user tries to delete user tag and succeeds
|
||||
try:
|
||||
delete_tags(regular_account_api_client, {tag_key_user: tag_value_user})
|
||||
@ -2906,15 +2906,15 @@ class TestResourceTags(cloudstackTestCase):
|
||||
# recover tag to run admin tests
|
||||
create_user_tag()
|
||||
create_admin_tag()
|
||||
|
||||
|
||||
# admin tries to delete tags and succeeds
|
||||
try:
|
||||
delete_tags(self.apiclient, {tag_key_admin: tag_value_admin, tag_key_user: tag_value_user})
|
||||
except Exception as e:
|
||||
self.fail("Administrator is not able to delete a tag - %s" % e)
|
||||
self.fail("Administrator is not able to delete a tag - %s" % e)
|
||||
|
||||
return
|
||||
|
||||
|
||||
@attr(tags=["advanced","basic"], required_hardware="false")
|
||||
def test_32_user_a_doesnt_have_access_to_user_b_tags(self):
|
||||
'''Test resource security between regular accounts A and B'''
|
||||
@ -2924,7 +2924,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
|
||||
tag_key_user2 = 'scope32_user2'
|
||||
tag_value_user2 = 'test_32_user_a_doesnt_have_access_to_user_b_tags-user2'
|
||||
|
||||
|
||||
regular_account1 = Account.create(
|
||||
self.apiclient,
|
||||
self.services["account"],
|
||||
@ -2975,7 +2975,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
except Exception as e:
|
||||
pass
|
||||
else:
|
||||
self.fail("User1 has access to delete tags of User2.")
|
||||
self.fail("User1 has access to delete tags of User2.")
|
||||
|
||||
try:
|
||||
Tag.create(
|
||||
@ -2987,7 +2987,7 @@ class TestResourceTags(cloudstackTestCase):
|
||||
pass
|
||||
else:
|
||||
self.fail("User1 has access to create tags for User2.")
|
||||
|
||||
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "basic"], required_hardware="false")
|
||||
|
||||
@ -143,7 +143,7 @@ class TestUpdateResourceCount(cloudstackTestCase):
|
||||
)
|
||||
self.debug("Created account: %s" % self.account.name)
|
||||
self.cleanup.append(self.account)
|
||||
|
||||
|
||||
return
|
||||
|
||||
def tearDown(self):
|
||||
@ -165,7 +165,7 @@ class TestUpdateResourceCount(cloudstackTestCase):
|
||||
def test_01_updateResourceCount(self):
|
||||
"""Test update resource count for an account using a custom service offering to deploy a VM.
|
||||
"""
|
||||
|
||||
|
||||
# This test will execute the following steps to assure resource count update is working properly
|
||||
# 1. Create an account.
|
||||
# 2. Start 2 VMs; one with normal service offering and other with a custom service offering
|
||||
@ -173,7 +173,7 @@ class TestUpdateResourceCount(cloudstackTestCase):
|
||||
# The two VMs will add up to 3 CPUs and 1024Mb of RAM.
|
||||
# 4. If the return of updateResourceCount method matches with the expected one, the test passes; otherwise, it fails.
|
||||
# 5. Remove everything created by deleting the account
|
||||
|
||||
|
||||
vm_1 = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.services["virtual_machine"],
|
||||
@ -184,12 +184,12 @@ class TestUpdateResourceCount(cloudstackTestCase):
|
||||
customcpuspeed = 1000,
|
||||
custommemory = 512
|
||||
)
|
||||
|
||||
|
||||
self.debug("Deployed VM 1 in account: %s, ID: %s" % (
|
||||
self.account.name,
|
||||
vm_1.id
|
||||
))
|
||||
|
||||
|
||||
vm_2 = VirtualMachine.create(
|
||||
self.apiclient,
|
||||
self.services["virtual_machine"],
|
||||
@ -207,8 +207,8 @@ class TestUpdateResourceCount(cloudstackTestCase):
|
||||
resourcetype=8,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
self.debug("ResourceCount for CPU: %s" % (
|
||||
resourceCountCpu[0].resourcecount
|
||||
))
|
||||
@ -222,8 +222,8 @@ class TestUpdateResourceCount(cloudstackTestCase):
|
||||
resourcetype=9,
|
||||
account=self.account.name,
|
||||
domainid=self.account.domainid
|
||||
)
|
||||
|
||||
)
|
||||
|
||||
self.debug("ResourceCount for memory: %s" % (
|
||||
resourceCountMemory[0].resourcecount
|
||||
))
|
||||
|
||||
@ -353,13 +353,13 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
|
||||
|
||||
Steps:
|
||||
# 1. create vm without data disk, resource count increases.
|
||||
# 2. restore vm. resource count no changes.
|
||||
# 2. restore vm. resource count no changes.
|
||||
# 3. check old root disk , should be Destroy state
|
||||
# 4. recover old root disk. resource count increases.
|
||||
# 5. delete old root disk . resource count decreases.
|
||||
# 6. destroy vm (expunge=True). resource count decreased with size of root disk
|
||||
"""
|
||||
|
||||
|
||||
# Create vm
|
||||
try:
|
||||
virtual_machine_3 = VirtualMachine.create(
|
||||
@ -379,7 +379,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
|
||||
self.volumeTotal = self.volumeTotal + 1
|
||||
self.verify_resource_count_primary_storage(self.expectedCount, self.volumeTotal);
|
||||
|
||||
# Get id of root disk
|
||||
# Get id of root disk
|
||||
root_volumes_list = Volume.list(
|
||||
self.apiclient,
|
||||
virtualmachineid=virtual_machine_3.id,
|
||||
@ -440,7 +440,7 @@ class TestVolumeDestroyRecover(cloudstackTestCase):
|
||||
# 5. destroy volume (expunge = false), Exception happened. resource count no changes
|
||||
# 6. destroy volume (expunge = true). volume is not found. resource count no changes.
|
||||
"""
|
||||
|
||||
|
||||
# Create vm
|
||||
try:
|
||||
virtual_machine_4 = VirtualMachine.create(
|
||||
|
||||
@ -511,7 +511,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_03_VPC_CreateLBRuleInMultipleNetworksVRStoppedState(self):
|
||||
""" Test case no 222 : Create LB rules for a two/multiple virtual networks of a
|
||||
""" Test case no 222 : Create LB rules for a two/multiple virtual networks of a
|
||||
VPC using a new Public IP Address available with the VPC when the Virtual Router is in Stopped State
|
||||
|
||||
# Validate the following
|
||||
@ -544,7 +544,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
|
||||
|
||||
self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2])
|
||||
self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False)
|
||||
return
|
||||
return
|
||||
|
||||
@attr(tags=["advanced","advancedns", "intervlan"], required_hardware="true")
|
||||
def test_04_VPC_CreateLBRuleInMultipleNetworksVRStoppedState(self):
|
||||
@ -643,7 +643,7 @@ class TestVPCNetworkLBRules(cloudstackTestCase):
|
||||
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=False)
|
||||
lb_rule_nat.delete(self.apiclient)
|
||||
self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True)
|
||||
return
|
||||
return
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_07_VPC_CreateAndDeleteAllLBRule(self):
|
||||
|
||||
@ -378,7 +378,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_01_VPC_StaticNatRuleCreateStoppedState(self):
|
||||
""" Test case no extra :
|
||||
""" Test case no extra :
|
||||
|
||||
# Validate the following
|
||||
# 1. Create a VPC with cidr - 10.1.1.1/16
|
||||
@ -406,7 +406,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_02_VPC_CreateStaticNatRule(self):
|
||||
""" Test case no 229 : Create Static NAT Rule for a single virtual network of
|
||||
""" Test case no 229 : Create Static NAT Rule for a single virtual network of
|
||||
a VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State
|
||||
|
||||
# Validate the following
|
||||
@ -469,7 +469,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
|
||||
|
||||
@attr(tags=["advanced", "intervlan"], required_hardware="true")
|
||||
def test_04_VPC_CreateMultipleStaticNatRule(self):
|
||||
""" Test case no 230 : Create Static NAT Rules for a two/multiple virtual networks of
|
||||
""" Test case no 230 : Create Static NAT Rules for a two/multiple virtual networks of
|
||||
a VPC using a new Public IP Address available with the VPC when the Virtual Router is in Running State
|
||||
|
||||
# Validate the following
|
||||
@ -503,7 +503,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
|
||||
# was tags=["advanced", "intervlan"]
|
||||
@attr(tags=["TODO"], required_hardware="true")
|
||||
def test_05_network_services_VPC_DeleteAllPF(self):
|
||||
""" Test case no 232: Delete all Static NAT Rules for a single virtual network of
|
||||
""" Test case no 232: Delete all Static NAT Rules for a single virtual network of
|
||||
a VPC belonging to a single Public IP Address when the Virtual Router is in Running State
|
||||
|
||||
# Validate the following
|
||||
@ -536,7 +536,7 @@ class TestVPCNetworkPFRules(cloudstackTestCase):
|
||||
# was tags=["advanced", "intervlan"]
|
||||
@attr(tags=["TODO"], required_hardware="true")
|
||||
def test_06_network_services_VPC_DeleteAllMultiplePF(self):
|
||||
""" Test case no 233: Delete all Static NAT rules for two/multiple virtual networks of a VPC.
|
||||
""" Test case no 233: Delete all Static NAT rules for two/multiple virtual networks of a VPC.
|
||||
Observe the status of the Public IP Addresses of the rules when the Virtual Router is in Running State.
|
||||
|
||||
# Validate the following
|
||||
|
||||
@ -655,10 +655,10 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
|
||||
'Destroyed',
|
||||
"VM state should be destroyed"
|
||||
)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to stop the virtual instances, %s" % e)
|
||||
|
||||
|
||||
# Check if the network rules still exists after Vm stop
|
||||
self.debug("Checking if NAT rules ")
|
||||
nat_rules = NATRule.list(
|
||||
@ -703,7 +703,7 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to recover the virtual instances, %s" % e)
|
||||
|
||||
|
||||
try:
|
||||
self.vm_2.delete(self.apiclient, expunge=False)
|
||||
|
||||
@ -727,7 +727,7 @@ class TestVMLifeCycleVPC(cloudstackTestCase):
|
||||
self.fail("Failed to stop the virtual instances, %s" % e)
|
||||
|
||||
self.debug("Recovering the expunged virtual machine vm2 in account: %s" %
|
||||
self.account.name)
|
||||
self.account.name)
|
||||
try:
|
||||
self.vm_2.recover(self.apiclient)
|
||||
|
||||
@ -1779,10 +1779,10 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase):
|
||||
'Destroyed',
|
||||
"VM state should be destroyed"
|
||||
)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to stop the virtual instances, %s" % e)
|
||||
|
||||
|
||||
# Check if the network rules still exists after Vm stop
|
||||
self.debug("Checking if NAT rules ")
|
||||
nat_rules = NATRule.list(
|
||||
@ -1827,7 +1827,7 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase):
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to recover the virtual instances, %s" % e)
|
||||
|
||||
|
||||
try:
|
||||
self.vm_2.delete(self.apiclient, expunge=False)
|
||||
|
||||
@ -1848,7 +1848,7 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase):
|
||||
self.fail("Failed to stop the virtual instances, %s" % e)
|
||||
|
||||
self.debug("Recovering the expunged virtual machine vm2 in account: %s" %
|
||||
self.account.name)
|
||||
self.account.name)
|
||||
try:
|
||||
self.vm_2.recover(self.apiclient)
|
||||
|
||||
@ -2494,10 +2494,10 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
|
||||
'Destroyed',
|
||||
"VM state should be destroyed"
|
||||
)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to stop the virtual instances, %s" % e)
|
||||
|
||||
|
||||
# Check if the network rules still exists after Vm stop
|
||||
self.debug("Checking if NAT rules ")
|
||||
nat_rules = NATRule.list(
|
||||
@ -2542,7 +2542,7 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
|
||||
|
||||
except Exception as e:
|
||||
self.fail("Failed to recover the virtual instances, %s" % e)
|
||||
|
||||
|
||||
try:
|
||||
self.vm_2.delete(self.apiclient, expunge=False)
|
||||
|
||||
@ -2563,7 +2563,7 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
|
||||
self.fail("Failed to stop the virtual instances, %s" % e)
|
||||
|
||||
self.debug("Recovering the expunged virtual machine vm2 in account: %s" %
|
||||
self.account.name)
|
||||
self.account.name)
|
||||
try:
|
||||
self.vm_2.recover(self.apiclient)
|
||||
|
||||
|
||||
@ -339,7 +339,7 @@ class TestVolumes(cloudstackTestCase):
|
||||
2. Init Datera API connection
|
||||
3. Create ACS Primary storage
|
||||
4. Create ACS compute and disk offering.
|
||||
5. Create ACS data disk without attaching to a VM
|
||||
5. Create ACS data disk without attaching to a VM
|
||||
"""
|
||||
logger.info("Setting up Class")
|
||||
|
||||
|
||||
@ -79,7 +79,7 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaTariffList.quotaTariffListCmd()
|
||||
response = self.apiclient.quotaTariffList(cmd)
|
||||
|
||||
@ -105,7 +105,7 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaTariffList.quotaTariffListCmd()
|
||||
cmd.startdate='2015-07-06'
|
||||
response = self.apiclient.quotaTariffList(cmd)
|
||||
@ -125,7 +125,7 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaTariffList.quotaTariffListCmd()
|
||||
cmd.startdate='2015-07-06'
|
||||
cmd.usagetype='10'
|
||||
@ -149,7 +149,7 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaTariffList.quotaTariffListCmd()
|
||||
cmd.startdate='2015-07-06'
|
||||
cmd.usagetype='10'
|
||||
@ -205,7 +205,7 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaCredits.quotaCreditsCmd()
|
||||
cmd.domainid = self.account.domainid
|
||||
cmd.account = self.account.name
|
||||
@ -227,7 +227,7 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaBalance.quotaBalanceCmd()
|
||||
today = datetime.date.today()
|
||||
cmd.domainid = self.account.domainid
|
||||
@ -248,13 +248,13 @@ class TestQuota(cloudstackTestCase):
|
||||
name='quota.enable.service',
|
||||
value='true'):
|
||||
self.skipTest('quota.enable.service should be true. skipping')
|
||||
|
||||
|
||||
cmd = quotaBalance.quotaBalanceCmd()
|
||||
today = datetime.date.today()
|
||||
cmd.domainid = self.account.domainid
|
||||
cmd.account = self.account.name
|
||||
cmd.startdate = today - datetime.timedelta(days=2)
|
||||
cmd.enddate = today
|
||||
cmd.enddate = today
|
||||
response = self.apiclient.quotaBalance(cmd)
|
||||
|
||||
self.debug("Quota Balance: {response.balance}")
|
||||
|
||||
@ -5,9 +5,9 @@
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
|
||||
@ -38,7 +38,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
|
||||
cls.testClient = super(TestDeployVmWithAffinityGroup, cls).getClsTestClient()
|
||||
zone_name = cls.testClient.getZoneForTests()
|
||||
cls.apiclient = cls.testClient.getApiClient()
|
||||
cls.domain = get_domain(cls.apiclient)
|
||||
cls.domain = get_domain(cls.apiclient)
|
||||
cls.services = cls.testClient.getParsedTestDataConfig()
|
||||
# Get Zone, Domain and templates
|
||||
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
|
||||
@ -49,10 +49,10 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.hypervisor
|
||||
)
|
||||
|
||||
|
||||
if cls.template == FAILED:
|
||||
assert False, "get_template() failed to return template"
|
||||
|
||||
|
||||
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
|
||||
|
||||
cls.services["template"] = cls.template.id
|
||||
|
||||
@ -36,7 +36,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
|
||||
cls.testClient = super(TestDeployVmWithAffinityGroup, cls).getClsTestClient()
|
||||
zone_name = cls.testClient.getZoneForTests()
|
||||
cls.apiclient = cls.testClient.getApiClient()
|
||||
cls.domain = get_domain(cls.apiclient)
|
||||
cls.domain = get_domain(cls.apiclient)
|
||||
cls.services = cls.testClient.getParsedTestDataConfig()
|
||||
# Get Zone, Domain and templates
|
||||
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
|
||||
@ -47,7 +47,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase):
|
||||
cls.zone.id,
|
||||
cls.hypervisor
|
||||
)
|
||||
|
||||
|
||||
if cls.template == FAILED:
|
||||
assert False, "get_test_template() failed to return template"
|
||||
|
||||
|
||||
@ -53,17 +53,17 @@ class TestDummyBackupAndRecovery(cloudstackTestCase):
|
||||
Configurations.update(cls.api_client, 'backup.framework.enabled', value='true', zoneid=cls.zone.id)
|
||||
if cls.backup_provider != "dummy":
|
||||
Configurations.update(cls.api_client, 'backup.framework.provider.plugin', value='dummy', zoneid=cls.zone.id)
|
||||
|
||||
|
||||
if cls.hypervisor.lower() != 'simulator':
|
||||
return
|
||||
|
||||
|
||||
cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id)
|
||||
cls.offering = ServiceOffering.create(cls.api_client,cls.services["service_offerings"]["small"])
|
||||
cls.vm = VirtualMachine.create(cls.api_client, cls.services["small"], accountid=cls.account.name,
|
||||
domainid=cls.account.domainid, serviceofferingid=cls.offering.id,
|
||||
mode=cls.services["mode"])
|
||||
cls._cleanup = [cls.offering, cls.account]
|
||||
|
||||
|
||||
# Import a dummy backup offering to use on tests
|
||||
|
||||
cls.provider_offerings = BackupOffering.listExternal(cls.api_client, cls.zone.id)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user