晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /proc/self/root/lib/python3.6/site-packages/cloudinit/sources/helpers/ |
Upload File : |
# Author: Antti Myyrä <antti.myyra@upcloud.com>
#
# This file is part of cloud-init. See LICENSE file for license information.
import json
import logging
from cloudinit import dmi
from cloudinit import net as cloudnet
from cloudinit import url_helper
LOG = logging.getLogger(__name__)
def convert_to_network_config_v1(config):
"""
Convert the UpCloud network metadata description into
Cloud-init's version 1 netconfig format.
Example JSON:
{
"interfaces": [
{
"index": 1,
"ip_addresses": [
{
"address": "94.237.105.53",
"dhcp": true,
"dns": [
"94.237.127.9",
"94.237.40.9"
],
"family": "IPv4",
"floating": false,
"gateway": "94.237.104.1",
"network": "94.237.104.0/22"
},
{
"address": "94.237.105.50",
"dhcp": false,
"dns": [],
"family": "IPv4",
"floating": true,
"gateway": "",
"network": "94.237.105.50/32"
}
],
"mac": "32:d5:ba:4a:36:e7",
"network_id": "031457f4-0f8c-483c-96f2-eccede02909c",
"type": "public"
},
{
"index": 2,
"ip_addresses": [
{
"address": "10.6.3.27",
"dhcp": true,
"dns": [],
"family": "IPv4",
"floating": false,
"gateway": "10.6.0.1",
"network": "10.6.0.0/22"
}
],
"mac": "32:d5:ba:4a:84:cc",
"network_id": "03d82553-5bea-4132-b29a-e1cf67ec2dd1",
"type": "utility"
},
{
"index": 3,
"ip_addresses": [
{
"address": "2a04:3545:1000:720:38d6:baff:fe4a:63e7",
"dhcp": true,
"dns": [
"2a04:3540:53::1",
"2a04:3544:53::1"
],
"family": "IPv6",
"floating": false,
"gateway": "2a04:3545:1000:720::1",
"network": "2a04:3545:1000:720::/64"
}
],
"mac": "32:d5:ba:4a:63:e7",
"network_id": "03000000-0000-4000-8046-000000000000",
"type": "public"
},
{
"index": 4,
"ip_addresses": [
{
"address": "172.30.1.10",
"dhcp": true,
"dns": [],
"family": "IPv4",
"floating": false,
"gateway": "172.30.1.1",
"network": "172.30.1.0/24"
}
],
"mac": "32:d5:ba:4a:8a:e1",
"network_id": "035a0a4a-77b4-4de5-820d-189fc8135714",
"type": "private"
}
],
"dns": [
"94.237.127.9",
"94.237.40.9"
]
}
"""
def _get_subnet_config(ip_addr, dns):
if ip_addr.get("dhcp"):
dhcp_type = "dhcp"
if ip_addr.get("family") == "IPv6":
# UpCloud currently passes IPv6 addresses via
# StateLess Address Auto Configuration (SLAAC)
dhcp_type = "ipv6_dhcpv6-stateless"
return {"type": dhcp_type}
static_type = "static"
if ip_addr.get("family") == "IPv6":
static_type = "static6"
subpart = {
"type": static_type,
"control": "auto",
"address": ip_addr.get("address"),
}
if ip_addr.get("gateway"):
subpart["gateway"] = ip_addr.get("gateway")
if "/" in ip_addr.get("network"):
subpart["netmask"] = ip_addr.get("network").split("/")[1]
if dns != ip_addr.get("dns") and ip_addr.get("dns"):
subpart["dns_nameservers"] = ip_addr.get("dns")
return subpart
nic_configs = []
macs_to_interfaces = cloudnet.get_interfaces_by_mac()
LOG.debug("NIC mapping: %s", macs_to_interfaces)
for raw_iface in config.get("interfaces"):
LOG.debug("Considering %s", raw_iface)
mac_address = raw_iface.get("mac")
if mac_address not in macs_to_interfaces:
raise RuntimeError(
"Did not find network interface on system "
"with mac '%s'. Cannot apply configuration: %s"
% (mac_address, raw_iface)
)
iface_type = raw_iface.get("type")
sysfs_name = macs_to_interfaces.get(mac_address)
LOG.debug(
"Found %s interface '%s' with address '%s' (index %d)",
iface_type,
sysfs_name,
mac_address,
raw_iface.get("index"),
)
interface = {
"type": "physical",
"name": sysfs_name,
"mac_address": mac_address,
}
subnets = []
for ip_address in raw_iface.get("ip_addresses"):
sub_part = _get_subnet_config(ip_address, config.get("dns"))
subnets.append(sub_part)
interface["subnets"] = subnets
nic_configs.append(interface)
if config.get("dns"):
LOG.debug("Setting DNS nameservers to %s", config.get("dns"))
nic_configs.append(
{"type": "nameserver", "address": config.get("dns")}
)
return {"version": 1, "config": nic_configs}
def convert_network_config(config):
return convert_to_network_config_v1(config)
def read_metadata(url, timeout=2, sec_between=2, retries=30):
response = url_helper.readurl(
url, timeout=timeout, sec_between=sec_between, retries=retries
)
if not response.ok():
raise RuntimeError("unable to read metadata at %s" % url)
return json.loads(response.contents.decode())
def read_sysinfo():
# UpCloud embeds vendor ID and server UUID in the
# SMBIOS information
# Detect if we are on UpCloud and return the UUID
vendor_name = dmi.read_dmi_data("system-manufacturer")
if vendor_name != "UpCloud":
return False, None
server_uuid = dmi.read_dmi_data("system-uuid")
if server_uuid:
LOG.debug(
"system identified via SMBIOS as UpCloud server: %s", server_uuid
)
else:
msg = (
"system identified via SMBIOS as a UpCloud server, but "
"did not provide an ID. Please contact support via"
"https://hub.upcloud.com or via email with support@upcloud.com"
)
LOG.critical(msg)
raise RuntimeError(msg)
return True, server_uuid