mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
Remove /tools/test which is taken over by /tools/marvin
Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>
This commit is contained in:
parent
07592ccf63
commit
073a91544f
@ -1,68 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import cookielib
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import urllib2
|
||||
import urllib
|
||||
|
||||
|
||||
class ApiSession:
|
||||
"""an ApiSession represents one api session, with cookies."""
|
||||
def __init__(self, url, username, password):
|
||||
self._username = username
|
||||
self._password = hashlib.md5(password).hexdigest()
|
||||
self._url = url
|
||||
self._cj = cookielib.CookieJar()
|
||||
self._opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self._cj))
|
||||
|
||||
def _get(self, parameters):
|
||||
encoded = urllib.urlencode(parameters)
|
||||
url = "%s?%s"% (self._url, encoded)
|
||||
try:
|
||||
f = self._opener.open(url)
|
||||
return f.read()
|
||||
except urllib2.HTTPError as exn:
|
||||
print "Command %s failed" % parameters['command']
|
||||
print "Reason: %s" % json.loads(exn.read())
|
||||
|
||||
def GET(self, parameters):
|
||||
parameters['sessionkey'] = self._sessionkey
|
||||
parameters['response'] = 'json'
|
||||
return self._get(parameters)
|
||||
|
||||
def _post(self, parameters):
|
||||
return self._opener.open(self._url, urllib.urlencode(parameters)).read()
|
||||
|
||||
def POST(self, parameters):
|
||||
parameters['sessionkey'] = self._sessionkey
|
||||
parameters['response'] = 'json'
|
||||
return self._post(parameters)
|
||||
|
||||
def login(self):
|
||||
params = {'command':'login', 'response': 'json'}
|
||||
params['username'] = self._username
|
||||
params['password'] = self._password
|
||||
result = self._get(params)
|
||||
jsonresult = json.loads(result)
|
||||
jsessionid = None
|
||||
self._sessionkey = jsonresult['loginresponse']['sessionkey']
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
# 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.
|
||||
|
||||
from apisession import ApiSession
|
||||
from physicalresource import ZoneCreator
|
||||
from globalconfig import GlobalConfig
|
||||
from db import Database
|
||||
import random
|
||||
import uuid
|
||||
|
||||
def fix_default_db():
|
||||
database = Database()
|
||||
statement="""
|
||||
UPDATE vm_template SET url='%s'
|
||||
WHERE unique_name='%s' """
|
||||
database.update(statement % ('http://nfs1.lab.vmops.com/templates/dummy/systemvm.vhd', 'routing-1'))
|
||||
database.update(statement % ('http://nfs1.lab.vmops.com/templates/dummy/systemvm.qcow2', 'routing-3'))
|
||||
database.update(statement % ('http://nfs1.lab.vmops.com/templates/dummy/systemvm.ova', 'routing-8'))
|
||||
|
||||
database.update(statement % ('http://nfs1.lab.vmops.com/templates/dummy/builtin.vhd', 'centos53-x86_64'))
|
||||
database.update(statement % ('http://nfs1.lab.vmops.com/templates/dummy/builtin.ova', 'centos53-x64'))
|
||||
statement="""UPDATE vm_template SET checksum=NULL"""
|
||||
database.update(statement)
|
||||
|
||||
statement="""
|
||||
UPDATE vm_template SET url='%s', unique_name='%s', name='%s', display_text='%s'
|
||||
WHERE id=4 """
|
||||
database.update(statement % ('http://nfs1.lab.vmops.com/templates/rightscale/RightImage_CentOS_5.4_x64_v5.6.34.qcow2.bz2', 'Rightscale CentOS 5.4', 'Rightscale CentOS 5.4', 'Rightscale CentOS 5.4'))
|
||||
statement="""UPDATE disk_offering set use_local_storage=1"""
|
||||
database.update(statement)
|
||||
|
||||
def config():
|
||||
config = GlobalConfig(api)
|
||||
config.update('use.local.storage', 'true')
|
||||
config.update('max.template.iso.size', '20')
|
||||
|
||||
def create_zone():
|
||||
zonecreator = ZoneCreator(api, random.randint(2,1000))
|
||||
zoneid = zonecreator.create()
|
||||
database = Database()
|
||||
statement="""INSERT INTO data_center_details (dc_id, name, value)
|
||||
VALUES (%s, '%s', '0')"""
|
||||
database.update(statement % (zoneid, 'enable.secstorage.vm'))
|
||||
database.update(statement % (zoneid, 'enable.consoleproxy.vm'))
|
||||
statement="""INSERT INTO data_center_details (dc_id, name, value)
|
||||
VALUES (%s, '%s', '%s')"""
|
||||
database.update(statement % (zoneid, 'zone.dhcp.strategy', 'external'))
|
||||
|
||||
statement="""UPDATE data_center set dhcp_provider='ExternalDhcpServer' where id=%s"""
|
||||
database.update(statement % (zoneid))
|
||||
|
||||
if __name__ == "__main__":
|
||||
fix_default_db()
|
||||
|
||||
api = ApiSession('http://localhost:8080/client/api', 'admin', 'password')
|
||||
api.login()
|
||||
|
||||
config()
|
||||
|
||||
create_zone()
|
||||
|
||||
print "guid=%s" % str(uuid.uuid4())
|
||||
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import MySQLdb
|
||||
|
||||
class Database:
|
||||
"""Database connection"""
|
||||
def __init__(self, host='localhost', username='cloud', password='cloud', db='cloud'):
|
||||
self._conn = MySQLdb.connect (host, username, password, db)
|
||||
|
||||
def update(self, statement):
|
||||
cursor = self._conn.cursor ()
|
||||
#print statement
|
||||
cursor.execute (statement)
|
||||
#print "Number of rows updated: %d" % cursor.rowcount
|
||||
cursor.close ()
|
||||
self._conn.commit ()
|
||||
|
||||
def __del__(self):
|
||||
self._conn.close ()
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
|
||||
class GlobalConfig:
|
||||
"""Updates global configuration values"""
|
||||
def __init__(self, api):
|
||||
self._api = api
|
||||
|
||||
def update(self, key, value):
|
||||
jsonresult = self._api.GET({'command': 'updateConfiguration', 'name':key,
|
||||
'value':value})
|
||||
if jsonresult is None:
|
||||
print "Failed to update configuration"
|
||||
return 1
|
||||
|
||||
return 0
|
||||
@ -1,71 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
|
||||
class ZoneCreator:
|
||||
"""Creates a zone (and a pod and cluster for now)"""
|
||||
def __init__(self, api, zonenum, dns1='192.168.10.254',
|
||||
dns2='192.168.10.253', internaldns='192.168.10.254'):
|
||||
self._api = api
|
||||
self._zonenum = zonenum
|
||||
self._zonename = "ZONE%04d"%zonenum
|
||||
self._dns1 = dns1
|
||||
self._dns2 = dns2
|
||||
self._internaldns = internaldns
|
||||
|
||||
def create(self):
|
||||
jsonresult = self._api.GET({'command': 'createZone', 'networktype':'Basic',
|
||||
'name':self._zonename, 'dns1':self._dns1, 'dns2':self._dns2,
|
||||
'internaldns1':self._internaldns})
|
||||
if jsonresult is None:
|
||||
print "Failed to create zone"
|
||||
return 0
|
||||
jsonobj = json.loads(jsonresult)
|
||||
self._zoneid = jsonobj['createzoneresponse']['zone']['id']
|
||||
self._zonetoken = jsonobj['createzoneresponse']['zone']['zonetoken']
|
||||
print "Zone %s is created"%self._zonename
|
||||
print "zone=%s"%self._zonetoken
|
||||
#self.createPod()
|
||||
return self._zoneid
|
||||
|
||||
|
||||
def createPod(self):
|
||||
self._podname = "POD%04d"%self._zonenum
|
||||
self._clustername = "CLUSTER%04d"%self._zonenum
|
||||
jsonresult = self._api.GET({'command': 'createPod', 'zoneId':self._zoneid,
|
||||
'name':self._podname, 'gateway':'192.168.1.1', 'netmask':'255.255.255.0',
|
||||
'startIp':'192.168.1.100', 'endIp':'192.168.1.150'})
|
||||
if jsonresult is None:
|
||||
print "Failed to create pod"
|
||||
return 2
|
||||
jsonobj = json.loads(jsonresult)
|
||||
podid = jsonobj['createpodresponse']['pod']['id']
|
||||
jsonresult = self._api.GET({'command': 'addCluster', 'zoneId':self._zoneid,
|
||||
'clustername':self._clustername, 'podId':podid, 'hypervisor':'KVM',
|
||||
'clustertype':'CloudManaged'})
|
||||
if jsonresult is None:
|
||||
print "Failed to create cluster"
|
||||
return 3
|
||||
jsonobj = json.loads(jsonresult)
|
||||
clusterid = jsonobj['addclusterresponse']['cluster'][0]['id']
|
||||
print "pod=%s"%podid
|
||||
print "cluster=%s"%clusterid
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
# 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.
|
||||
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
import time
|
||||
#http://localhost:8080/client/api?_=1303171692177&command=listTemplates&templatefilter=featured&zoneid=1&pagesize=6&page=1&response=json&sessionkey=%2Bh3Gh4BffWpQdk4nXmcC88uEk9k%3D
|
||||
#http://localhost:8080/client/api?_=1303171711292&command=deployVirtualMachine&zoneId=1&hypervisor=KVM&templateId=4&serviceOfferingId=7&response=json&sessionkey=%2Bh3Gh4BffWpQdk4nXmcC88uEk9k%3D
|
||||
#http://localhost:8080/client/api?_=1303171934824&command=queryAsyncJobResult&jobId=20&response=json&sessionkey=%2Bh3Gh4BffWpQdk4nXmcC88uEk9k%3D
|
||||
|
||||
class VMCreator:
|
||||
"""Creates a VM """
|
||||
def __init__(self, api, params):
|
||||
self._api = api
|
||||
self._params = params
|
||||
|
||||
def create(self):
|
||||
cmd = {'command': 'deployVirtualMachine'}
|
||||
cmd.update(self._params)
|
||||
jsonresult = self._api.GET(cmd)
|
||||
if jsonresult is None:
|
||||
print "Failed to create VM"
|
||||
return 0
|
||||
jsonobj = json.loads(jsonresult)
|
||||
self._jobid = jsonobj['deployvirtualmachineresponse']['jobid']
|
||||
self._vmid = jsonobj['deployvirtualmachineresponse']['id']
|
||||
print "VM %s creation is scheduled, job=%s"%(self._vmid, self._jobid)
|
||||
|
||||
|
||||
def poll(self, tries, wait):
|
||||
jobstatus = -1
|
||||
while jobstatus < 1 and tries > 0:
|
||||
time.sleep(wait)
|
||||
cmd = {'command': 'queryAsyncJobResult', 'jobId': self._jobid}
|
||||
jsonresult = self._api.GET(cmd)
|
||||
if jsonresult is None:
|
||||
print "Failed to query VM creation job"
|
||||
return -1
|
||||
jsonobj = json.loads(jsonresult)
|
||||
jobstatus = jsonobj['queryasyncjobresultresponse']['jobstatus']
|
||||
print jobstatus, type(jobstatus)
|
||||
tries = tries - 1
|
||||
|
||||
if jobstatus == 1:
|
||||
jsonobj = json.loads(jsonresult)
|
||||
jobresult = jsonobj['queryasyncjobresultresponse']['jobresult']
|
||||
vm = jobresult['virtualmachine']
|
||||
print vm
|
||||
else:
|
||||
print "Failed to create vm"
|
||||
|
||||
return jobstatus
|
||||
|
||||
@ -1,36 +0,0 @@
|
||||
# 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.
|
||||
|
||||
from apisession import ApiSession
|
||||
from vm import VMCreator
|
||||
|
||||
#http://localhost:8080/client/api?_=1303171711292&command=deployVirtualMachine&zoneId=1&hypervisor=KVM&templateId=4&serviceOfferingId=7&response=json&sessionkey=%2Bh3Gh4BffWpQdk4nXmcC88uEk9k%3D
|
||||
|
||||
def create_vm():
|
||||
vmcreator = VMCreator(api, {'zoneId':1, 'hypervisor':'KVM', 'templateId':4,
|
||||
'serviceOfferingId':7,
|
||||
'userdata':'dGhpcyBpcyBhIHRlc3QK'})
|
||||
vmid = vmcreator.create()
|
||||
vmcreator.poll(10, 3)
|
||||
|
||||
if __name__ == "__main__":
|
||||
api = ApiSession('http://localhost:8080/client/api', 'admin', 'password')
|
||||
api.login()
|
||||
|
||||
create_vm()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user