network.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package compute
  15. import (
  16. "yunion.io/x/cloudmux/pkg/apis/compute"
  17. "yunion.io/x/onecloud/pkg/apis"
  18. "yunion.io/x/onecloud/pkg/cloudcommon/types"
  19. )
  20. type TAddressType string
  21. const (
  22. AddressTypeIPv4 = TAddressType("ipv4")
  23. AddressTypeIPv6 = TAddressType("ipv6")
  24. )
  25. const (
  26. NETWORK_TYPE_VPC = compute.NETWORK_TYPE_VPC
  27. NETWORK_TYPE_CLASSIC = compute.NETWORK_TYPE_CLASSIC
  28. )
  29. type WireResourceInput struct {
  30. // 二层网络(ID或Name)的资源
  31. WireId string `json:"wire_id"`
  32. // swagger:ignore
  33. // Deprecated
  34. // fitler by wire id
  35. Wire string `json:"wire" yunion-deprecated-by:"wire_id"`
  36. }
  37. type WireFilterListBase struct {
  38. WireResourceInput
  39. // 以二层网络名称排序
  40. OrderByWire string `json:"order_by_wire"`
  41. }
  42. type WireFilterListInput struct {
  43. VpcFilterListInput
  44. ZonalFilterListBase
  45. WireFilterListBase
  46. }
  47. type NetworkResourceInput struct {
  48. // IP子网(ID或Name)
  49. NetworkId string `json:"network_id"`
  50. // swagger:ignore
  51. // Deprecated
  52. // filter by networkId
  53. Network string `json:"network" yunion-deprecated-by:"network_id"`
  54. }
  55. type NetworkFilterListBase struct {
  56. NetworkResourceInput
  57. // 以IP子网的名称排序
  58. OrderByNetwork string `json:"order_by_network"`
  59. }
  60. type NetworkFilterListInput struct {
  61. WireFilterListInput
  62. NetworkFilterListBase
  63. }
  64. type NetworkIpMacListInput struct {
  65. apis.StandaloneAnonResourceListInput
  66. NetworkId string `json:"network_id"`
  67. MacAddr []string `json:"mac_addr"`
  68. IpAddr []string `json:"ip_addr"`
  69. }
  70. type NetworkListInput struct {
  71. apis.SharableVirtualResourceListInput
  72. apis.ExternalizedResourceBaseListInput
  73. SchedtagResourceInput
  74. WireFilterListInput
  75. HostResourceInput
  76. StorageResourceInput
  77. UsableResourceListInput
  78. // filter by route table which associate with it
  79. RouteTableId string `json:"route_table_id"`
  80. // description: Exact matching ip address in network.
  81. // example: 10.168.222.1
  82. Ip []string `json:"ip"`
  83. // description: Fuzzy matching ip address in network.
  84. // example: 10.168.222.1
  85. IpMatch []string `json:"ip_match"`
  86. IfnameHint []string `json:"ifname_hint"`
  87. // 起始IP地址
  88. GuestIpStart []string `json:"guest_ip_start"`
  89. // 接收IP地址
  90. GuestIpEnd []string `json:"guest_ip_end"`
  91. // 掩码
  92. GuestIpMask []int8 `json:"guest_ip_mask"`
  93. // 网关地址
  94. GuestGateway string `json:"guest_gateway"`
  95. // DNS
  96. GuestDns []string `json:"guest_dns"`
  97. // allow multiple dhcp, seperated by ","
  98. GuestDhcp []string `json:"guest_dhcp"`
  99. // NTP
  100. GuestNtp []string `json:"guest_ntp"`
  101. GuestDomain []string `json:"guest_domain"`
  102. GuestIp6Start []string `json:"guest_ip6_start"`
  103. GuestIp6End []string `json:"guest_ip6_end"`
  104. GuestIp6Mask []int8 `json:"guest_ip6_mask"`
  105. GuestGateway6 []string `json:"guest_gateway6"`
  106. GuestDns6 []string `json:"guest_dns6"`
  107. GuestDomain6 []string `json:"guest_domain6"`
  108. // vlanId 1~4096
  109. VlanId []int `json:"vlan_id"`
  110. // 服务器类型
  111. // example: server
  112. ServerType []string `json:"server_type"`
  113. // 分配策略
  114. AllocPolicy []string `json:"alloc_policy"`
  115. // 是否加入自动分配地址池
  116. IsAutoAlloc *bool `json:"is_auto_alloc"`
  117. // 是否为基础网络(underlay)
  118. IsClassic *bool `json:"is_classic"`
  119. // filter by Host schedtag
  120. HostSchedtagId string `json:"host_schedtag_id"`
  121. // filter by BGP types
  122. BgpType []string `json:"bgp_type"`
  123. HostType string `json:"host_type"`
  124. // 按起始ip地址排序
  125. // pattern:asc|desc
  126. OrderByIpStart string `json:"order_by_ip_start"`
  127. // 按终止ip地址排序
  128. // pattern:asc|desc
  129. OrderByIpEnd string `json:"order_by_ip_end"`
  130. }
  131. type NetworkResourceInfoBase struct {
  132. // IP子网名称
  133. Network string `json:"network"`
  134. }
  135. type NetworkResourceInfo struct {
  136. NetworkResourceInfoBase
  137. // 二层网络ID
  138. WireId string `json:"wire_id"`
  139. WireResourceInfo
  140. }
  141. type NetworkIpMacCreateInput struct {
  142. apis.StandaloneAnonResourceCreateInput
  143. NetworkId string `json:"network_id"`
  144. MacAddr string `json:"mac_addr"`
  145. IpAddr string `json:"ip_addr"`
  146. }
  147. type NetworkCreateInput struct {
  148. apis.SharableVirtualResourceCreateInput
  149. // description: ip range of guest, if not set, you shoud set guest_ip_start,guest_ip_end and guest_ip_mask params
  150. // example: 10.168.222.1/24
  151. GuestIpPrefix string `json:"guest_ip_prefix"`
  152. // description: ip range of guest ip start, if set guest_ip_prefix, this parameter will be ignored
  153. // example: 10.168.222.1
  154. GuestIpStart string `json:"guest_ip_start"`
  155. // description: ip range of guest ip end, if set guest_ip_prefix, this parameter will be ignored
  156. // example: 10.168.222.100
  157. GuestIpEnd string `json:"guest_ip_end"`
  158. // description: ip range of guest ip mask, if set guest_ip_prefix, this parameter will be ignored
  159. // example: 24
  160. // maximum: 30
  161. // minimum: 12
  162. GuestIpMask int8 `json:"guest_ip_mask"`
  163. IfnameHint string `json:"ifname_hint"`
  164. // description: guest gateway
  165. // example: 192.168.222.1
  166. GuestGateway string `json:"guest_gateway"`
  167. // description: ipv6 range of guest, if not set, you shoud set guest_ip6_start,guest_ip6_end and guest_ip6_mask params
  168. // example: 3ffe:3200:2001:2300::/64
  169. GuestIp6Prefix string `json:"guest_ip6_prefix"`
  170. // description: ipv6 range of guest ip start, if set guest_ip6_prefix, this parameter will be ignored
  171. // example: 3ffe:3200:2001:2300::1
  172. GuestIp6Start string `json:"guest_ip6_start"`
  173. // description: ipv6 range of guest ip end, if set guest_ip6_prefix, this parameter will be ignored
  174. // example: 3ffe:3200:2001:2300:ffff:ffff:ffff:ffff
  175. GuestIp6End string `json:"guest_ip6_end"`
  176. // description: ipv6 range of guest ip mask, if set guest_ip6_prefix, this parameter will be ignored
  177. // example: 64
  178. // maximum: 126
  179. // minimum: 48
  180. GuestIp6Mask uint8 `json:"guest_ip6_mask"`
  181. // description: guest gateway of IPv6
  182. // example: 3ffe:3200:2001:2300::1
  183. GuestGateway6 string `json:"guest_gateway6"`
  184. // description: guest dns
  185. // example: 114.114.114.114,8.8.8.8
  186. GuestDns string `json:"guest_dns"`
  187. // description: guest dhcp
  188. // example: 192.168.222.1,192.168.222.4
  189. GuestDHCP string `json:"guest_dhcp"`
  190. // description: guest ntp
  191. // example: cn.pool.ntp.org,0.cn.pool.ntp.org
  192. GuestNtp string `json:"guest_ntp"`
  193. // swagger:ignore
  194. WireId string `json:"wire_id"`
  195. // description: wire id or name
  196. Wire string `json:"wire"`
  197. // description: zone id or name
  198. Zone string `json:"zone"`
  199. // description: vpc id or name
  200. Vpc string `json:"vpc"`
  201. // description: server type
  202. // enum: ["guest","baremetal","pxe","ipmi","hostlocal"]
  203. // default: guest
  204. ServerType TNetworkType `json:"server_type"`
  205. // 是否加入自动分配地址池
  206. IsAutoAlloc *bool `json:"is_auto_alloc"`
  207. // VlanId
  208. VlanId *int `json:"vlan_id"`
  209. // deprecated
  210. // swagger:ignore
  211. Vlan *int `json:"vlan" yunion-deprecated-by:"vlan_id"`
  212. // 线路类型
  213. BgpType string `json:"bgp_type"`
  214. // 是否申请ip时自动挂载公网ip,仅对aws生效
  215. AssignPublicIp bool `json:"assign_public_ip"`
  216. }
  217. type SNetworkNics struct {
  218. // 虚拟机网卡数量
  219. Vnics int `json:"vnics"`
  220. // IPv4地址数量
  221. Vnics4 int `json:"vnics4"`
  222. // IPv6地址数量
  223. Vnics6 int `json:"vnics6"`
  224. // 裸金属网卡数量
  225. BmVnics int `json:"bm_vnics"`
  226. // 负载均衡网卡数量
  227. LbVnics int `json:"lb_vnics"`
  228. // 浮动Ip网卡数量
  229. EipVnics int `json:"eip_vnics"`
  230. // VIP数量
  231. GroupVnics int `json:"group_vnics"`
  232. // 预留IPv4数量
  233. ReserveVnics4 int `json:"reserve_vnics4"`
  234. // 预留IPv6数量
  235. ReserveVnics6 int `json:"reserve_vnics6"`
  236. // RDS网卡数量
  237. RdsVnics int `json:"rds_vnics"`
  238. // NAT网关网卡数量
  239. NatVnics int `json:"nat_vnics"`
  240. BmReusedVnics int `json:"bm_reused_vnics"`
  241. // 弹性网卡数量
  242. NetworkinterfaceVnics int `json:"networkinterface_vnics"`
  243. // 已使用端口数量
  244. PortsUsed int `json:"ports_used"`
  245. Total int `json:"total"`
  246. // 已使用IPv4端口数量
  247. Ports6Used int `json:"ports6_used"`
  248. Total6 int `json:"total6"`
  249. }
  250. func (self *SNetworkNics) SumTotal() {
  251. self.Total = self.Vnics4 +
  252. self.BmVnics +
  253. self.LbVnics +
  254. self.LbVnics +
  255. self.EipVnics +
  256. self.GroupVnics +
  257. self.ReserveVnics4 +
  258. self.RdsVnics +
  259. self.NetworkinterfaceVnics +
  260. self.NatVnics -
  261. self.BmReusedVnics
  262. self.Total6 = self.Vnics6 +
  263. self.ReserveVnics6
  264. self.PortsUsed = self.Total
  265. self.Ports6Used = self.Total6
  266. }
  267. type NetworkDetails struct {
  268. apis.SharableVirtualResourceDetails
  269. WireResourceInfo
  270. SNetwork
  271. SNetworkNics
  272. // 是否是内网
  273. Exit bool `json:"exit"`
  274. // 端口数量
  275. Ports int `json:"ports"`
  276. Dns string `json:"dns"`
  277. // 路由信息
  278. Routes []types.SRoute `json:"routes"`
  279. Schedtags []SchedtagShortDescDetails `json:"schedtags"`
  280. IsClassic bool `json:"is_classic"`
  281. AdditionalWires []SSimpleWire `json:"additional_wires"`
  282. }
  283. type NetworkIpMacDetails struct {
  284. apis.StandaloneAnonResourceDetails
  285. NetworkId string `json:"network_id"`
  286. IpAddr string `json:"ip_addr"`
  287. MacAddr string `json:"mac_addr"`
  288. }
  289. type NetworkReserveIpInput struct {
  290. apis.Meta
  291. // description: reserved ip list
  292. // required: true
  293. // example: [10.168.222.131, 10.168.222.134]
  294. Ips []string `json:"ips"`
  295. // description: the comment
  296. // example: reserve ip for test
  297. Notes string `json:"notes"`
  298. Status string `json:"status"`
  299. // description: The reserved cycle
  300. // required: false
  301. Duration string `json:"duration"`
  302. }
  303. type NetworkReleaseReservedIpInput struct {
  304. apis.Meta
  305. // description: IP to be released
  306. // required: true
  307. // example: 10.168.222.121
  308. Ip string `json:"ip"`
  309. }
  310. type NetworkPurgeInput struct {
  311. apis.Meta
  312. }
  313. type NetworkMergeInput struct {
  314. apis.Meta
  315. // description: network id or name to be merged
  316. // required: true
  317. // example: test-network
  318. Target string `json:"target"`
  319. }
  320. type NetworkSplitInput struct {
  321. apis.Meta
  322. // description: The middle - separated IP must belong to the network
  323. // required: true
  324. // example: 10.168.222.181
  325. SplitIp string `json:"split_ip"`
  326. // description: another network name after split
  327. // required: false
  328. Name string `json:"name"`
  329. }
  330. type NetworkTryCreateNetworkInput struct {
  331. apis.Meta
  332. Ip string `json:"ip"`
  333. Mask int `json:"mask"`
  334. IsOnPremise bool `json:"is_on_premise"`
  335. ServerType TNetworkType `json:"server_type"`
  336. }
  337. type NetworkSyncInput struct {
  338. apis.Meta
  339. }
  340. type NetworkIpMacUpdateInput struct {
  341. apis.StandaloneAnonResourceBaseUpdateInput
  342. MacAddr string `json:"mac_addr"`
  343. IpAddr string `json:"ip_addr"`
  344. }
  345. type NetworkUpdateInput struct {
  346. apis.SharableVirtualResourceBaseUpdateInput
  347. // 起始IP地址
  348. GuestIpStart string `json:"guest_ip_start"`
  349. // 结束IP地址
  350. GuestIpEnd string `json:"guest_ip_end"`
  351. // 掩码
  352. GuestIpMask int8 `json:"guest_ip_mask"`
  353. // 网关地址
  354. GuestGateway *string `json:"guest_gateway"`
  355. // DNS
  356. GuestDns *string `json:"guest_dns"`
  357. // allow multiple dhcp, seperated by ","
  358. GuestDhcp *string `json:"guest_dhcp"`
  359. // NTP
  360. GuestNtp *string `json:"guest_ntp"`
  361. // 起始IP6地址
  362. GuestIp6Start *string `json:"guest_ip6_start"`
  363. // 结束IP6地址
  364. GuestIp6End *string `json:"guest_ip6_end"`
  365. // IP6子网掩码长度
  366. GuestIp6Mask *uint8 `json:"guest_ip6_mask"`
  367. // IP6网关地址
  368. GuestGateway6 *string `json:"guest_gateway6"`
  369. GuestDomain *string `json:"guest_domain"`
  370. VlanId *int `json:"vlan_id"`
  371. // 分配策略
  372. AllocPolicy string `json:"alloc_policy"`
  373. // 是否加入自动分配地址池
  374. IsAutoAlloc *bool `json:"is_auto_alloc"`
  375. // 更新网络类型
  376. ServerType TNetworkType `json:"server_type"`
  377. }
  378. type GetNetworkAddressesInput struct {
  379. // 获取资源的范围,例如 project|domain|system
  380. Scope string `json:"scope"`
  381. }
  382. type GetNetworkAddressesOutput struct {
  383. // IP子网地址记录
  384. Addresses []SNetworkUsedAddress `json:"addresses"`
  385. // IPv6子网地址记录
  386. Addresses6 []SNetworkUsedAddress `json:"addresses6"`
  387. }
  388. type GetNetworkAvailableAddressesInput struct {
  389. }
  390. type GetNetworkAvailableAddressesOutput struct {
  391. // IP子网地址记录
  392. Addresses []string `json:"addresses"`
  393. // IPv6子网地址记录
  394. Addresses6 []string `json:"addresses6"`
  395. }
  396. type NetworkSetBgpTypeInput struct {
  397. apis.Meta
  398. // description: new BgpType name
  399. // required: true
  400. // example: ChinaTelecom, BGP, etc.
  401. BgpType string `json:"bgp_type"`
  402. }
  403. type NetworkIpMacBatchCreateInput struct {
  404. NetworkId string `json:"network_id"`
  405. IpMac map[string]string `json:"ip_mac"`
  406. }
  407. type NetworkSwitchWireInput struct {
  408. apis.Meta
  409. // description: new wire Id or name
  410. // required: true
  411. // example: bcast0
  412. WireId string `json:"wire_id"`
  413. }
  414. type NetworSyncAdditionalWiresInput struct {
  415. apis.Meta
  416. WireIds []string `json:"wire_ids"`
  417. }