import
MySQLdb,sys
ip
=
sys.argv[
1
]
size
=
sys.argv[
2
]
size_info
=
{
'1'
:
'55800df7-5579-45c3-b4b3-584454aa2b77'
,
'2'
:
'6fe54364-e066-460b-89a2-ffe19cb26ae7'
,
'4'
:
'7a457be6-b1a0-48cd-88e1-c4e21d0518c1'
,
'6'
:
'7105ad91-3e49-43ed-9575-1a0535694578'
,
'8'
:
'61fc938c-234a-406b-b102-d535264e914d'
,
'12'
:
'dc5ffd92-eedf-4851-a40a-90e657f799a2'
,
'16'
:
'5c7af872-2089-4ece-bba7-4099d2a3ef24'
,
}
to_size
=
size_info[size]
get_flavor_info_sql
=
"select
id
,memory_mb,vcpus
from
instance_types \
where flavorid
=
'%s'
;"
%
\
to_size
class
mysqlEng():
def
__init__(
self
,host
=
'127.0.0.1'
,user
=
'root'
,passwd
=
'
',db='
None
',port='
3306
'):
self
.conn
=
MySQLdb.connect(host
=
host,user
=
user,passwd
=
passwd,db
=
db,port
=
3306
)
self
.cur
=
self
.conn.cursor()
def
select(
self
,sql
=
'show tables;'
):
self
.cur.execute(sql)
ret
=
self
.cur.fetchall()
return
ret
def
update(
self
,sql
=
''):
self
.cur.execute(sql)
self
.conn.commit()
def
__del__(
self
):
self
.cur.close()
self
.conn.close()
mysql_object
=
mysqlEng(host
=
'127.0.0.1'
,user
=
'root'
,passwd
=
'123456'
,db
=
'nova'
)
flavor_info
=
mysql_object.select(get_flavor_info_sql)
flavor_id
=
flavor_info[
0
][
0
]
mem
=
flavor_info[
0
][
1
]
vcpus
=
flavor_info[
0
][
2
]
update_flavor_info_sql
=
"update instances
set
instance_type_id
=
'%d'
,vcpus
=
'%d'
,memory_mb
=
'%d'
\
where hostname
=
'%s'
AND vm_state !
=
'deleted'
AND vm_state !
=
'error'
;"
%
\
(flavor_id,vcpus,mem,ip)
mysql_object.update(update_flavor_info_sql)
after_update_info_sql
=
"select vcpus,memory_mb
from
instances \
where hostname
=
'%s'
AND vm_state !
=
'deleted'
AND vm_state !
=
'error'
;"
%
\
ip
after_update_info
=
mysql_object.select(after_update_info_sql)
print
'+'
*
80
+
'\n'
print
"This server %s now flavor : cpu=%s , mem=%s\n"
%
\
(ip,after_update_info[
0
][
0
],after_update_info[
0
][
1
])
print
'+'
*
80
+
'\n'