示例#1
0
  def server_floatip(self,action,serverid):
	if action == "ADD":
    		cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/os-floating-ips',
		'method':	'POST',
		'params':	'{"pool": "nova"}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
		}
    		try:
    			ips = access(None,None)._json_access(cmds)
			floatip=ips['floating_ip']['ip']
    		except Exception, e:
			for i in e:
				print i
    		cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/servers/'+serverid+'/action',
		'method':	'POST',
		'params':	'{"addFloatingIp": {"address": "'+floatip+'"}}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
		}
    		try:
    			dd = access(None,None)._json_access(cmds)
			return floatip
    		except Exception, e:
			for i in e:
				print i
示例#2
0
  def server_boot(self,servername=None,flavorRef="http://10.55.2.155:8774/v2/938b8b2c602d4640891a61289463b168/flavors/1",imageRef="http://10.55.2.155:8774/v2/938b8b2c602d4640891a61289463b168/images/6bdffc76-c890-476d-b0f1-bf0f9229c411",secgroup='"Management"',key_name='dtaylor-openstack'):
    cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/servers',
		'method':	'POST',
		'params':	'{"server": {"flavorRef": "'+flavorRef+'", "personality": [{"path": "", "contents": ""}], "name": "'+servername+'", "imageRef": "'+imageRef+'", "metadata": {"Server Name": "'+servername+'"}, "security_group": '+secgroup+', "key_name": "'+key_name+'"}}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
	}
    try:
    	dd = access(None,None)._json_access(cmds)
	return dd
    except Exception, e:
	for i in e:
		print i
示例#3
0
  def server_reboot(self,serverid=None,rebootType = "HARD"):
    cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/servers/'+serverid+'/action',
		'method':	'POST',
		'params':	'{"reboot": {"type": rebootType}}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
	}
    try:
    	dd = access(None,None)._json_access(cmds)
	return dd
    except Exception, e:
	for i in e:
		print i
示例#4
0
  def _poll(self,url,method='GET'):
    cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+url,
		'method':	method,
		'params':	'{"X-Auth-Token": self.apitoken}',
		'headers':	{"X-Auth-Token": self.apitoken}
	}
    try:
	print cmds
    	dd = access(None,None)._json_access(cmds)
	return dd
    except Exception, e:
	for i in e:
		print i
示例#5
0
  def server_terminate(self,serverid):
    cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/servers/'+serverid,
		'method':	'DELETE',
		'params':	'{}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
	}
    try:
    	dd = access(None,None)._json_access(cmds)
	return dd
    except Exception, e:
	for i in e:
		print i
示例#6
0
  def __init__(self,osuser=config.osuser,ospass=config.ospass,tenantid=config.tenantid,oshost=config.oshost):
    self.novahost=config.oshost+':8774'
    self.keystonehost=config.oshost+':5000'
    cmds = {	'host':	self.keystonehost,
		'url':	'/v2.0/tokens',
		'method':	'POST',
		'params':	'{"auth":{"passwordCredentials":{"username": "******", "password":"******"}, "tenantId":"'+tenantid+'"}}',
		'headers':	{"Content-Type": "application/json"}
	}
    self.tenantid=tenantid
    print cmds
    try:
    	dd = access(None,None)._json_access(cmds)
	self.apitoken = dd['access']['token']['id']
	#self.apiurl = dd['access']['serviceCatalog']['nova'][0]['publicURL']
	#self.apiurlt = urlparse(dd['access']['serviceCatalog']['nova'][0]['publicURL'])
    except Exception, e:
	print "openstack execption: aaaarch"
	for i in e:
		print i
示例#7
0
	def chef_bootstrap(self,cmds):
		msg="Performing bootstrap "+cmds
		self.debugit(msg)
		# sanity check
		
		# generate command to run
		try:
			cmd=devices(self.device_type,self.hostname,self.username,self.password).chefserver_bootstrap(cmds)
			# execute based on access_type to device_type mapping
			self.debugit("cmd chat script:")
			self.debugit(cmd)
		except:
			print "Exception generating chat script for device %s, continue..." % self.device_type
			pass
		try:
			if cmd:
				return access(self.device_type,self.hostname,"ubuntu",self.password,debug=self.debug,sshkey="/home/ubuntu/.ssh/dtaylor-openstack.priv")._ssh_access(cmd)
		except:
			print "Exception in chef bootstrap."
			pass
示例#8
0
				print i
    		cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/servers/'+serverid+'/action',
		'method':	'POST',
		'params':	'{"addFloatingIp": {"address": "'+floatip+'"}}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
		}
    		try:
    			dd = access(None,None)._json_access(cmds)
			return floatip
    		except Exception, e:
			for i in e:
				print i
	elif action == "DEL":
    		cmds = {	'host':	self.novahost,
		'url':	'/v2/'+self.tenantid+'/servers/'+serverid+'/action',
		'method':	'POST',
		'params':	'{"removeFloatingIp": {"address": "'+floatip+'"}}',
		'headers':	{"X-Auth-Token": self.apitoken,
				"Content-type": "application/json"}
		}
    		try:
    			dd = access(None,None)._json_access(cmds)
			return dd
    		except Exception, e:
			for i in e:
				print i
		
	return
示例#9
0
		# sanity check
		
		# generate command to run
		try:
			cmd=devices(self.device_type,self.hostname,self.username,self.password).chefserver_knife(cmds)
			# execute based on access_type to device_type mapping
			self.debugit("cmd chat script:")
			self.debugit(cmd)
		except Exception,e:
			print "Exception generating chat script for device %s, continue..." % self.device_type
			for i in e:
				print i
			pass
		try:
			if cmd:
				return access(self.device_type,self.hostname,self.username,self.password,sshkey=self.sshkey)._ssh_access(cmd)
		except:
			print "Exception in chef knife."
			pass
	def chef_bootstrap(self,cmds):
		msg="Performing bootstrap "+cmds
		self.debugit(msg)
		# sanity check
		
		# generate command to run
		try:
			cmd=devices(self.device_type,self.hostname,self.username,self.password).chefserver_bootstrap(cmds)
			# execute based on access_type to device_type mapping
			self.debugit("cmd chat script:")
			self.debugit(cmd)
		except: