-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
添加虚拟机备份、编辑磁盘描述 #170
添加虚拟机备份、编辑磁盘描述 #170
Changes from 6 commits
1144240
aa4f9e5
043149b
9a71c0d
5669183
a6e4d39
f5267c0
880a3ea
0713ee7
715a67b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,23 @@ | |
import os | ||
import errno | ||
import time | ||
import ConfigParser | ||
|
||
pro_path = os.path.split(os.path.realpath(__file__))[0] | ||
LOG_PATH = os.path.join(pro_path, "log") # 日志路径 | ||
DB_PATH = os.path.join(pro_path, "db.sqlite3") | ||
CONFIG_PATH = os.path.join(pro_path,"setting.conf") | ||
LOG_FLAG = True # 日志开关 | ||
POLL_TIME_INCR = 0.5 | ||
IP_keystone = "192.168.190.11" | ||
PORT_keystone = "5000" | ||
IP_nova = "192.168.190.11" | ||
PORT_nova = "8774" | ||
IP_cinder = "192.168.190.11" | ||
PORT_cinder = "8774" | ||
#读取配置文件 | ||
cf = ConfigParser.ConfigParser() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么要读取配置文件啊?不是都在settings里面直接引用吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这些都属于可配置项,在settings里面如果给出的是pyc的文件就不能修改了 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 现在配置都提取到yaml文件中了。你可以看看这个issue. #143 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个版本里面配置文件还没改,版本合过去后我把这几个配置写到yaml里面去 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的。 |
||
cf.read(CONFIG_PATH) | ||
IP_keystone = cf.get("global","IP_keystone") | ||
PORT_keystone = cf.get("global","PORT_keystone") | ||
IP_nova = cf.get("global","IP_nova") | ||
PORT_nova = cf.get("global","PORT_nova") | ||
IP_cinder = cf.get("global","IP_cinder") | ||
PORT_cinder = cf.get("global","PORT_cinder") | ||
TIMEOUT = 60 | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[global] | ||
IP_keystone=192.168.190.11 | ||
PORT_keystone=5000 | ||
IP_nova=192.168.190.11 | ||
PORT_nova=8774 | ||
IP_cinder=192.168.190.11 | ||
PORT_cinder=8776 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,25 @@ def extend(self,volume_id,size): | |
assert ret != 1, "send_request error" | ||
return ret | ||
|
||
@plog("Volume.change") | ||
def change(self,volume_id,name="",description=""): | ||
''' | ||
修改磁盘信息 | ||
:return: | ||
''' | ||
assert self.token != "","not login" | ||
path = "/v2/%s/volumes/%s"%(self.project_id, volume_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里的path。不要写在代码里面了。提取出来放在一个单独的文件中统一管理。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. path会随着用户和操作对象的变化而变化,如果只是把相同的部分放在公用变量里面再拼接起来好像没什么意义 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不用拼接吧。url统一定义成模版的形式使用的时候渲染然后集中放在一个地方比较好管理一点。 opensatckUrl = "/v1/{project_id}/volumes/{volume_id}" 使用的时候渲染就可以了。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不是我们程序的url地址,是openstack cinder API的地址,我不确定我们理解的是不是一样的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你说的openstack cinder API的地址不是可以理解为第3方服务的api地址么? |
||
method = "PUT" | ||
head = {"Content-Type": "application/json", "X-Auth-Token": self.token} | ||
params = {"volume":{}} | ||
if name: | ||
params["volume"].update({"name":name}) | ||
if description: | ||
params["volume"].update({"description":description}) | ||
ret = send_request(method,IP_cinder,PORT_cinder,path,params,head) | ||
assert ret != 1,"send_request error" | ||
return ret | ||
|
||
class Volume_snaps(): | ||
def __init__(self): | ||
self.token = get_token() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面两行:
这两个不是全部已经配置了吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改成从settings里面获取项目路径