def host_get(hst=None): if settings.app.demo_mode: resp = utils.demo_get_cache() if resp: return utils.jsonify(resp) if hst: resp = host.get_by_id(hst).dict() if settings.app.demo_mode: utils.demo_set_cache(resp) return utils.jsonify(resp) hosts = [] page = flask.request.args.get('page', None) page = int(page) if page else page for hst in host.iter_hosts_dict(page=page): hosts.append(hst) if page is not None: resp = { 'page': page, 'page_total': host.get_host_page_total(), 'hosts': hosts, } else: resp = hosts if settings.app.demo_mode: utils.demo_set_cache(resp) return utils.jsonify(resp)
def server_host_put(server_id, host_id): if settings.app.demo_mode: return utils.demo_blocked() svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'links')) hst = host.get_by_id(host_id, fields=('_id', 'name', 'public_address', 'auto_public_address')) try: svr.add_host(hst.id) except ServerLinkCommonHostError: return utils.jsonify({ 'error': SERVER_LINK_COMMON_HOST, 'error_msg': SERVER_LINK_COMMON_HOST_MSG, }, 400) svr.commit('hosts') event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({ 'id': hst.id, 'server': svr.id, 'status': OFFLINE, 'name': hst.name, 'address': hst.public_addr, })
def host_get(hst=None): if settings.app.demo_mode: resp = utils.demo_get_cache() if resp: return utils.jsonify(resp) if hst: resp = host.get_by_id(hst).dict() if settings.app.demo_mode: utils.demo_set_cache(resp) return utils.jsonify(resp) hosts = [] page = flask.request.args.get('page', None) page = int(page) if page else page for hst in host.iter_hosts_dict(page=page): if settings.app.demo_mode: hst['users_online'] = hst['user_count'] hosts.append(hst) if page is not None: resp = { 'page': page, 'page_total': host.get_host_page_total(), 'hosts': hosts, } else: resp = hosts if settings.app.demo_mode: utils.demo_set_cache(resp) return utils.jsonify(resp)
def host_delete(hst): hst = host.get_by_id(hst) hst.remove() logger.LogEntry(message='Deleted host "%s".' % hst.name) event.Event(type=HOSTS_UPDATED) return utils.jsonify({})
def host_delete(host_id): hst = host.get_by_id(host_id) hst.remove() logger.LogEntry(message='Deleted host "%s".' % hst.name) event.Event(type=HOSTS_UPDATED) return utils.jsonify({})
def host_put(hst=None): if settings.app.demo_mode: return utils.demo_blocked() hst = host.get_by_id(hst) if 'name' in flask.request.json: hst.name = utils.filter_str( flask.request.json['name']) or utils.random_name() if 'public_address' in flask.request.json: hst.public_address = utils.filter_str( flask.request.json['public_address']) if 'public_address6' in flask.request.json: hst.public_address6 = utils.filter_str( flask.request.json['public_address6']) if 'routed_subnet6' in flask.request.json: routed_subnet6 = flask.request.json['routed_subnet6'] if routed_subnet6: try: routed_subnet6 = ipaddress.IPv6Network( flask.request.json['routed_subnet6']) except (ipaddress.AddressValueError, ValueError): return utils.jsonify({ 'error': IPV6_SUBNET_INVALID, 'error_msg': IPV6_SUBNET_INVALID_MSG, }, 400) if routed_subnet6.prefixlen > 64: return utils.jsonify({ 'error': IPV6_SUBNET_SIZE_INVALID, 'error_msg': IPV6_SUBNET_SIZE_INVALID_MSG, }, 400) routed_subnet6 = str(routed_subnet6) else: routed_subnet6 = None if hst.routed_subnet6 != routed_subnet6: if server.get_online_ipv6_count(): return utils.jsonify({ 'error': IPV6_SUBNET_ONLINE, 'error_msg': IPV6_SUBNET_ONLINE_MSG, }, 400) hst.routed_subnet6 = routed_subnet6 if 'link_address' in flask.request.json: hst.link_address = utils.filter_str( flask.request.json['link_address']) hst.commit(hst.changed) event.Event(type=HOSTS_UPDATED) messenger.publish('hosts', 'updated') return utils.jsonify(hst.dict())
def link_instance(self, host_id): if self.interrupt: return instance_link = ServerInstanceLink( server=self.server, linked_server=self.server, linked_host=host.get_by_id(host_id), ) instance_link.start() self.replica_links[host_id] = instance_link
def host_get(host_id=None): if host_id: return utils.jsonify(host.get_by_id(host_id).dict()) hosts = [] for hst in host.iter_servers_dict(): hosts.append(hst) return utils.jsonify(hosts)
def host_delete(hst): if settings.app.demo_mode: return utils.demo_blocked() hst = host.get_by_id(hst) hst.remove() logger.LogEntry(message='Deleted host "%s".' % hst.name) event.Event(type=HOSTS_UPDATED) return utils.jsonify({})
def host_usage_get(hst, period): if settings.app.demo_mode: resp = utils.demo_get_cache() if resp: return utils.jsonify(resp) hst = host.get_by_id(hst) resp = hst.usage.get_period(period) if settings.app.demo_mode: utils.demo_set_cache(resp) return utils.jsonify(resp)
def host_put(hst=None): if settings.app.demo_mode: return utils.demo_blocked() hst = host.get_by_id(hst) if "name" in flask.request.json: hst.name = utils.filter_str(flask.request.json["name"]) or utils.random_name() if "public_address" in flask.request.json: hst.public_address = utils.filter_str(flask.request.json["public_address"]) if "public_address6" in flask.request.json: hst.public_address6 = utils.filter_str(flask.request.json["public_address6"]) if "routed_subnet6" in flask.request.json: routed_subnet6 = flask.request.json["routed_subnet6"] if routed_subnet6: try: routed_subnet6 = ipaddress.IPv6Network(flask.request.json["routed_subnet6"]) except (ipaddress.AddressValueError, ValueError): return utils.jsonify({"error": IPV6_SUBNET_INVALID, "error_msg": IPV6_SUBNET_INVALID_MSG}, 400) if routed_subnet6.prefixlen > 64: return utils.jsonify( {"error": IPV6_SUBNET_SIZE_INVALID, "error_msg": IPV6_SUBNET_SIZE_INVALID_MSG}, 400 ) routed_subnet6 = str(routed_subnet6) else: routed_subnet6 = None if hst.routed_subnet6 != routed_subnet6: if server.get_online_ipv6_count(): return utils.jsonify({"error": IPV6_SUBNET_ONLINE, "error_msg": IPV6_SUBNET_ONLINE_MSG}, 400) hst.routed_subnet6 = routed_subnet6 if "local_address" in flask.request.json: hst.local_address = utils.filter_str(flask.request.json["local_address"]) if "local_address6" in flask.request.json: hst.local_address6 = utils.filter_str(flask.request.json["local_address6"]) if "link_address" in flask.request.json: hst.link_address = utils.filter_str(flask.request.json["link_address"]) if "instance_id" in flask.request.json: hst.instance_id = utils.filter_str(flask.request.json["instance_id"]) hst.commit(hst.changed) event.Event(type=HOSTS_UPDATED) messenger.publish("hosts", "updated") return utils.jsonify(hst.dict())
def server_host_delete(server_id, host_id): svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'replica_count')) hst = host.get_by_id(host_id, fields=('_id', 'name')) svr.remove_host(hst.id) svr.commit('hosts') event.Event(type=SERVERS_UPDATED) event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({})
def server_host_delete(server_id, host_id): svr = server.get_by_id(server_id, fields=['_id', 'hosts']) hst = host.get_by_id(host_id, fields=['_id', 'name']) svr.remove_host(hst.id) svr.commit('hosts') event.Event(type=SERVERS_UPDATED) event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({})
def server_host_put(server_id, host_id): svr = server.get_by_id(server_id, fields=['_id', 'hosts']) hst = host.get_by_id(host_id, fields=['_id', 'name', 'public_address']) svr.add_host(hst.id) svr.commit('hosts') event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({ 'id': hst.id, 'server': svr.id, 'status': OFFLINE, 'name': hst.name, 'address': hst.public_addr, })
def server_host_delete(server_id, host_id): if settings.app.demo_mode: return utils.demo_blocked() svr = server.get_by_id(server_id, fields=('_id', 'hosts', 'replica_count')) hst = host.get_by_id(host_id, fields=('_id', 'name')) svr.remove_host(hst.id) svr.commit('hosts') event.Event(type=SERVERS_UPDATED) event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({})
def host_put(host_id=None): hst = host.get_by_id(host_id) if 'name' in flask.request.json: hst.name = utils.filter_str( flask.request.json['name']) or utils.random_name() if 'public_address' in flask.request.json: hst.public_address = utils.filter_str( flask.request.json['public_address']) if 'link_address' in flask.request.json: hst.link_address = utils.filter_str(flask.request.json['link_address']) hst.commit(hst.changed) event.Event(type=HOSTS_UPDATED) return utils.jsonify(hst.dict())
def host_put(host_id=None): hst = host.get_by_id(host_id) if 'name' in flask.request.json: hst.name = utils.filter_str( flask.request.json['name']) or utils.random_name() if 'public_address' in flask.request.json: hst.public_address = utils.filter_str( flask.request.json['public_address']) if 'link_address' in flask.request.json: hst.link_address = utils.filter_str( flask.request.json['link_address']) hst.commit(hst.changed) event.Event(type=HOSTS_UPDATED) return utils.jsonify(hst.dict())
def server_host_delete(server_id, host_id): if settings.app.demo_mode: return utils.demo_blocked() svr = server.get_by_id(server_id, fields=( '_id', 'hosts', 'replica_count')) if not svr: return flask.abort(404) hst = host.get_by_id(host_id, fields=('_id', 'name')) if not hst: return flask.abort(404) svr.remove_host(hst.id) svr.commit('hosts') event.Event(type=SERVERS_UPDATED) event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({})
def host_get(hst=None): if hst: return utils.jsonify(host.get_by_id(hst).dict()) hosts = [] page = flask.request.args.get('page', None) page = int(page) if page else page for hst in host.iter_hosts_dict(page=page): hosts.append(hst) if page is not None: return utils.jsonify({ 'page': page, 'page_total': host.get_host_page_total(), 'hosts': hosts, }) else: return utils.jsonify(hosts)
def server_host_put(server_id, host_id): if settings.app.demo_mode: return utils.demo_blocked() svr = server.get_by_id(server_id) if not svr: return flask.abort(404) hst = host.get_by_id(host_id, fields=('_id', 'name', 'public_address', 'auto_public_address', 'auto_public_host', 'public_address6', 'auto_public_address6', 'auto_public_host6')) if not svr: return flask.abort(404) try: svr.add_host(hst.id) except ServerLinkCommonHostError: return utils.jsonify( { 'error': SERVER_LINK_COMMON_HOST, 'error_msg': SERVER_LINK_COMMON_HOST_MSG, }, 400) err, err_msg = svr.validate_conf(allow_online=True) if err: return utils.jsonify({ 'error': err, 'error_msg': err_msg, }, 400) svr.commit('hosts') event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({ 'id': hst.id, 'server': svr.id, 'status': OFFLINE, 'name': hst.name, 'address': hst.public_addr, })
def server_host_put(server_id, host_id): if settings.app.demo_mode: return utils.demo_blocked() svr = server.get_by_id(server_id) if not svr: return flask.abort(404) hst = host.get_by_id(host_id, fields=('_id', 'name', 'public_address', 'auto_public_address', 'auto_public_host', 'public_address6', 'auto_public_address6', 'auto_public_host6')) if not svr: return flask.abort(404) try: svr.add_host(hst.id) except ServerLinkCommonHostError: return utils.jsonify({ 'error': SERVER_LINK_COMMON_HOST, 'error_msg': SERVER_LINK_COMMON_HOST_MSG, }, 400) err, err_msg = svr.validate_conf(allow_online=True) if err: return utils.jsonify({ 'error': err, 'error_msg': err_msg, }, 400) svr.commit('hosts') event.Event(type=SERVER_HOSTS_UPDATED, resource_id=svr.id) return utils.jsonify({ 'id': hst.id, 'server': svr.id, 'status': OFFLINE, 'name': hst.name, 'address': hst.public_addr, })
def get_by_id(self, host_id): if host_id in self.hosts: return host.get_by_id(host_id)
def host_put(hst=None): if settings.app.demo_mode: return utils.demo_blocked() hst = host.get_by_id(hst) if 'name' in flask.request.json: hst.name = utils.filter_str( flask.request.json['name']) or utils.random_name() if 'public_address' in flask.request.json: public_address = utils.filter_str(flask.request.json['public_address']) hst.public_address = public_address if 'public_address6' in flask.request.json: public_address6 = utils.filter_str( flask.request.json['public_address6']) hst.public_address6 = public_address6 if 'routed_subnet6' in flask.request.json: routed_subnet6 = flask.request.json['routed_subnet6'] if routed_subnet6: try: routed_subnet6 = ipaddress.IPv6Network( flask.request.json['routed_subnet6']) except (ipaddress.AddressValueError, ValueError): return utils.jsonify( { 'error': IPV6_SUBNET_INVALID, 'error_msg': IPV6_SUBNET_INVALID_MSG, }, 400) if routed_subnet6.prefixlen > 64: return utils.jsonify( { 'error': IPV6_SUBNET_SIZE_INVALID, 'error_msg': IPV6_SUBNET_SIZE_INVALID_MSG, }, 400) routed_subnet6 = str(routed_subnet6) else: routed_subnet6 = None if hst.routed_subnet6 != routed_subnet6: if server.get_online_ipv6_count(): return utils.jsonify( { 'error': IPV6_SUBNET_ONLINE, 'error_msg': IPV6_SUBNET_ONLINE_MSG, }, 400) hst.routed_subnet6 = routed_subnet6 if 'proxy_ndp' in flask.request.json: proxy_ndp = True if flask.request.json['proxy_ndp'] else False hst.proxy_ndp = proxy_ndp if 'local_address' in flask.request.json: local_address = utils.filter_str(flask.request.json['local_address']) hst.local_address = local_address if 'local_address6' in flask.request.json: local_address6 = utils.filter_str(flask.request.json['local_address6']) hst.local_address6 = local_address6 if 'link_address' in flask.request.json: link_address = utils.filter_str(flask.request.json['link_address']) hst.link_address = link_address if 'sync_address' in flask.request.json: sync_address = utils.filter_str(flask.request.json['sync_address']) hst.sync_address = sync_address if 'availability_group' in flask.request.json: hst.availability_group = utils.filter_str( flask.request.json['availability_group']) or DEFAULT if 'instance_id' in flask.request.json: instance_id = utils.filter_str(flask.request.json['instance_id']) if instance_id != hst.aws_id: hst.instance_id = instance_id hst.commit(hst.changed) event.Event(type=HOSTS_UPDATED) messenger.publish('hosts', 'updated') return utils.jsonify(hst.dict())
def host_usage_get(host_id, period): hst = host.get_by_id(host_id) return utils.jsonify(hst.usage.get_period(period))
def host_usage_get(hst, period): hst = host.get_by_id(hst) return utils.jsonify(hst.usage.get_period(period))