Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove all time.time() to nova.util.utcnow_ts()

  • Loading branch information...
commit d453ec098bad079ac27e52b9b2179c13eb7b6f92 1 parent 95470d3
@hokerffb hokerffb authored
View
7 bin/api-client
@@ -24,6 +24,7 @@ import json
import zmq
from collections import OrderedDict
from datetime import datetime
+from dateutil.parser import parse
from kanyun.client import api_client
from kanyun.common import const
@@ -73,6 +74,7 @@ def main():
print "\tapi_client"
print "\tapi_client -l <metric>"
print "\tapi_client -t <timestamp>"
+ print "\tapi_client -d <timestring>"
# print "\tapi_client <id> vmnetwork <IP> <option> <period> " \
# "<time_from> <time_to>"
print "\tapi_client -get <id> <cf> <scf> <time_from> <time_to>"
@@ -106,6 +108,11 @@ def main():
elif sys.argv[1] == '-t':
timestamp = float(sys.argv[2])
print datetime.fromtimestamp(timestamp).isoformat()
+ elif sys.argv[1] == '-d':
+ timesstr = sys.argv[2]
+ timestamp = parse(timesstr)
+ timestamp = int(time.mktime(timestamp.timetuple()))
+ print timestamp
return
elif len(sys.argv) == 8:
row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[3]
View
10 kanyun/server/api_server.py
@@ -26,6 +26,8 @@
import zmq
from dateutil.parser import parse
from collections import OrderedDict
+
+from nova import utils
from kanyun.common.const import *
from kanyun.common.buffer import HallBuffer
from kanyun.database.cassadb import CassaDb
@@ -139,7 +141,7 @@ def get_data(self, row_id, cf_str, scf_str, time_from=0, time_to=0):
return None, 0, True
if time_to == 0:
- time_to = int(time.time())
+ time_to = int(utils.utcnow_ts())
print "get_data:", row_id, cf_str, scf_str, time_from, time_to
bufkey = str([row_id, cf_str, scf_str, time_from, time_to])
@@ -208,7 +210,7 @@ def get_instances_list(self, cf_str):
return None
ret = list()
limit = 20000
- time_to = int(time.time())
+ time_to = int(utils.utcnow_ts())
time_from = time_to - 24 * 60 * 60
db = self.get_db()
@@ -286,7 +288,7 @@ def query_usage_report(self, args, **kwargs):
# time_from = int(time.mktime(time_from.timetuple()))
time_from = parse(timestamp_from)
time_from = int(time.mktime(time_from.timetuple()))
- time_to = int(time.time())
+ time_to = int(utils.utcnow_ts())
if not timestamp_to is None:
# time_to = iso8601.parse_date(timestamp_to)
# time_to = int(time.mktime(time_to.timetuple()))
@@ -318,7 +320,7 @@ def query_usage_report(self, args, **kwargs):
ret_len = 0
result = ret, ret_len, all_data
- if (not result is None and time.time() - time_to > 120):
+ if (not result is None and utils.utcnow_ts() - time_to > 120):
self.buf.cleanup()
self.buf.save(bufkey, result)
return result
View
4 kanyun/worker/plugin_agent.py
@@ -21,6 +21,8 @@
from xml.etree import ElementTree
import libvirt
+from nova import utils
+
"""
collect info of vm
"""
@@ -102,7 +104,7 @@ def collect_info(self):
@staticmethod
def get_utc_sec():
- return time.time()
+ return utils.utcnow_ts()
@staticmethod
def get_xml_nodes(dom_xml, path):
View
3  kanyun/worker/plugin_traffic_accounting.py
@@ -19,6 +19,7 @@
import subprocess
import shlex
import time
+from nova import utils
"""
A worker plugin run in nova-network node, get the network traffic.
@@ -112,7 +113,7 @@ def get_traffic_accounting_info():
# save current value
_ip_bytes[instance_id] = float(out_bytes)
- ret[instance_id] = (instance_ip, int(time.time()), str(val))
+ ret[instance_id] = (instance_ip, int(utils.utcnow_ts()), str(val))
return ret
View
5 kanyun/worker/worker.py
@@ -25,6 +25,7 @@
import traceback
import ConfigParser
+from nova import utils
from kanyun.common.app import *
from kanyun.common.const import *
"""
@@ -35,7 +36,7 @@
# plugin
def plugin_heartbeat(worker_id, status=1):
"""status: 0:I will exit; 1:working"""
- info = [worker_id, time.time(), status]
+ info = [worker_id, utils.utcnow_ts(), status]
return MSG_TYPE.HEART_BEAT, info
@@ -159,7 +160,7 @@ def info_push(self, check_worktime=True):
return True
def end(self):
- info = [self.worker_id, time.time(), 0]
+ info = [self.worker_id, utils.utcnow_ts(), 0]
self.send(MSG_TYPE.HEART_BEAT, 0, json.dumps(info))
Please sign in to comment.
Something went wrong with that request. Please try again.