def test(id=None): log.debug("Testing") if not id: id = 'test' containers = set(Container.get_by_id(id)) | set(Container.get_by_name(id)) containers = list(containers) print containers[0]
def _get_container(id): containers = set(Container.get_by_id(id)) | set(Container.get_by_name(id)) containers = list(containers) if len(containers) == 0: raise "No containers found matching id/name {}".format(id) elif len(containers) > 1: raise "Multiple containers returned for id/name {}".format(id) return containers[0]
def city_tweet_corpus_dict(): key = 'city_tweet_corpus_dict' n = session.query(Container).filter(Container.key==key).first() if not n: n={} tweet_to_city_dict = map_cities_to_tweets() for city in cities: city_tweet_corpus_dict = {} for tweet in tweet_to_city_dict[city.name]: tweet_text = tweet.text.encode("utf-8").lower().translate(string.maketrans("",""),string.punctuation).split() uniques = set(tweet_text) tweet_text = list(uniques) for word in tweet_text: if word not in city_tweet_corpus_dict: city_tweet_corpus_dict[word]=1 else: previous = city_tweet_corpus_dict[word] city_tweet_corpus_dict[word] = previous+1 n[city.name] = city_tweet_corpus_dict d = Container(key=key, value=json.dumps(n)) model.session.add(d) model.session.commit() else: n = json.loads(n.value) return n
def create_region_tweet_count(city): key = city.name.replace(' ', '_') + 'tweet_count' region_tweet_count = session.query(Container).filter(Container.key==key).first() if not region_tweet_count: tweet_to_cty_dict = map_cities_to_tweets() tweet_list = tweet_to_cty_dict[city.name] region_tweet_count = 0.0 for tweet in tweet_list: region_tweet_count += 1.0 d = Container(key=key, value=json.dumps(region_tweet_count)) model.session.add(d) model.session.commit() else: region_tweet_count = json.loads(region_tweet_count.value) return region_tweet_count
def create_tweet_total_count(): key = 'total_tweet_count' total_tweet_count = session.query(Container).filter(Container.key==key).first() if not total_tweet_count: tweet_to_cty_dict = map_cities_to_tweets() total_tweet_count = 0.0 for city in cities: tweet_list = tweet_to_cty_dict[city.name] for tweet in tweet_list: total_tweet_count += 1.0 d = Container(key=key, value=json.dumps(total_tweet_count)) model.session.add(d) model.session.commit() else: total_tweet_count = json.loads(total_tweet_count.value) return total_tweet_count
print("Update User: "******"r") cluinfo = json.loads(cluFile.read()) vcluster = VCluster(cluinfo['clusterid'], cluname, user, cluinfo['status'], cluinfo['size'], cluinfo['nextcid'], cluinfo['proxy_server_ip'], cluinfo['proxy_public_ip']) vcluster.create_time = datetime.strptime(cluinfo['create_time'], timeFormat) vcluster.start_time = cluinfo['start_time'] for coninfo in cluinfo['containers']: lastsavet = datetime.strptime(coninfo['lastsave'], timeFormat) con = Container(coninfo['containername'], coninfo['hostname'], coninfo['ip'], coninfo['host'], coninfo['image'], lastsavet, coninfo['setting']) vcluster.containers.append(con) for pminfo in cluinfo['port_mapping']: pm = PortMapping(pminfo['node_name'], pminfo['node_ip'], int(pminfo['node_port']), int(pminfo['host_port'])) vcluster.port_mapping.append(pm) if "billing_history" in cluinfo.keys(): for nodename in cluinfo['billing_history'].keys(): bhinfo = cluinfo['billing_history'][nodename] bh = BillingHistory(nodename, bhinfo['cpu'], bhinfo['mem'], bhinfo['disk'], bhinfo['port']) vcluster.billing_history.append(bh) try: db.session.add(vcluster)
def stop(): log.debug("Stopping all containers") running_containers = Container.get_containers(status=Status.Running) for container in running_containers: container.remove()
def remove_stopped(): log.debug("Removing stopped containers") stopped_containers = Container.get_containers(status=Status.Stopped) for container in stopped_containers: cmd = "docker rm {}".format(container.id) run_command(cmd)