VPNService.go 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875
  1. //
  2. // Copyright 2016, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package cloudstack
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "net/url"
  21. "strconv"
  22. "strings"
  23. )
  24. type CreateRemoteAccessVpnParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateRemoteAccessVpnParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["account"]; found {
  33. u.Set("account", v.(string))
  34. }
  35. if v, found := p.p["domainid"]; found {
  36. u.Set("domainid", v.(string))
  37. }
  38. if v, found := p.p["fordisplay"]; found {
  39. vv := strconv.FormatBool(v.(bool))
  40. u.Set("fordisplay", vv)
  41. }
  42. if v, found := p.p["iprange"]; found {
  43. u.Set("iprange", v.(string))
  44. }
  45. if v, found := p.p["openfirewall"]; found {
  46. vv := strconv.FormatBool(v.(bool))
  47. u.Set("openfirewall", vv)
  48. }
  49. if v, found := p.p["publicipid"]; found {
  50. u.Set("publicipid", v.(string))
  51. }
  52. return u
  53. }
  54. func (p *CreateRemoteAccessVpnParams) SetAccount(v string) {
  55. if p.p == nil {
  56. p.p = make(map[string]interface{})
  57. }
  58. p.p["account"] = v
  59. return
  60. }
  61. func (p *CreateRemoteAccessVpnParams) SetDomainid(v string) {
  62. if p.p == nil {
  63. p.p = make(map[string]interface{})
  64. }
  65. p.p["domainid"] = v
  66. return
  67. }
  68. func (p *CreateRemoteAccessVpnParams) SetFordisplay(v bool) {
  69. if p.p == nil {
  70. p.p = make(map[string]interface{})
  71. }
  72. p.p["fordisplay"] = v
  73. return
  74. }
  75. func (p *CreateRemoteAccessVpnParams) SetIprange(v string) {
  76. if p.p == nil {
  77. p.p = make(map[string]interface{})
  78. }
  79. p.p["iprange"] = v
  80. return
  81. }
  82. func (p *CreateRemoteAccessVpnParams) SetOpenfirewall(v bool) {
  83. if p.p == nil {
  84. p.p = make(map[string]interface{})
  85. }
  86. p.p["openfirewall"] = v
  87. return
  88. }
  89. func (p *CreateRemoteAccessVpnParams) SetPublicipid(v string) {
  90. if p.p == nil {
  91. p.p = make(map[string]interface{})
  92. }
  93. p.p["publicipid"] = v
  94. return
  95. }
  96. // You should always use this function to get a new CreateRemoteAccessVpnParams instance,
  97. // as then you are sure you have configured all required params
  98. func (s *VPNService) NewCreateRemoteAccessVpnParams(publicipid string) *CreateRemoteAccessVpnParams {
  99. p := &CreateRemoteAccessVpnParams{}
  100. p.p = make(map[string]interface{})
  101. p.p["publicipid"] = publicipid
  102. return p
  103. }
  104. // Creates a l2tp/ipsec remote access vpn
  105. func (s *VPNService) CreateRemoteAccessVpn(p *CreateRemoteAccessVpnParams) (*CreateRemoteAccessVpnResponse, error) {
  106. resp, err := s.cs.newRequest("createRemoteAccessVpn", p.toURLValues())
  107. if err != nil {
  108. return nil, err
  109. }
  110. var r CreateRemoteAccessVpnResponse
  111. if err := json.Unmarshal(resp, &r); err != nil {
  112. return nil, err
  113. }
  114. // If we have a async client, we need to wait for the async result
  115. if s.cs.async {
  116. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  117. if err != nil {
  118. if err == AsyncTimeoutErr {
  119. return &r, err
  120. }
  121. return nil, err
  122. }
  123. b, err = getRawValue(b)
  124. if err != nil {
  125. return nil, err
  126. }
  127. if err := json.Unmarshal(b, &r); err != nil {
  128. return nil, err
  129. }
  130. }
  131. return &r, nil
  132. }
  133. type CreateRemoteAccessVpnResponse struct {
  134. JobID string `json:"jobid,omitempty"`
  135. Account string `json:"account,omitempty"`
  136. Domain string `json:"domain,omitempty"`
  137. Domainid string `json:"domainid,omitempty"`
  138. Fordisplay bool `json:"fordisplay,omitempty"`
  139. Id string `json:"id,omitempty"`
  140. Iprange string `json:"iprange,omitempty"`
  141. Presharedkey string `json:"presharedkey,omitempty"`
  142. Project string `json:"project,omitempty"`
  143. Projectid string `json:"projectid,omitempty"`
  144. Publicip string `json:"publicip,omitempty"`
  145. Publicipid string `json:"publicipid,omitempty"`
  146. State string `json:"state,omitempty"`
  147. }
  148. type DeleteRemoteAccessVpnParams struct {
  149. p map[string]interface{}
  150. }
  151. func (p *DeleteRemoteAccessVpnParams) toURLValues() url.Values {
  152. u := url.Values{}
  153. if p.p == nil {
  154. return u
  155. }
  156. if v, found := p.p["publicipid"]; found {
  157. u.Set("publicipid", v.(string))
  158. }
  159. return u
  160. }
  161. func (p *DeleteRemoteAccessVpnParams) SetPublicipid(v string) {
  162. if p.p == nil {
  163. p.p = make(map[string]interface{})
  164. }
  165. p.p["publicipid"] = v
  166. return
  167. }
  168. // You should always use this function to get a new DeleteRemoteAccessVpnParams instance,
  169. // as then you are sure you have configured all required params
  170. func (s *VPNService) NewDeleteRemoteAccessVpnParams(publicipid string) *DeleteRemoteAccessVpnParams {
  171. p := &DeleteRemoteAccessVpnParams{}
  172. p.p = make(map[string]interface{})
  173. p.p["publicipid"] = publicipid
  174. return p
  175. }
  176. // Destroys a l2tp/ipsec remote access vpn
  177. func (s *VPNService) DeleteRemoteAccessVpn(p *DeleteRemoteAccessVpnParams) (*DeleteRemoteAccessVpnResponse, error) {
  178. resp, err := s.cs.newRequest("deleteRemoteAccessVpn", p.toURLValues())
  179. if err != nil {
  180. return nil, err
  181. }
  182. var r DeleteRemoteAccessVpnResponse
  183. if err := json.Unmarshal(resp, &r); err != nil {
  184. return nil, err
  185. }
  186. // If we have a async client, we need to wait for the async result
  187. if s.cs.async {
  188. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  189. if err != nil {
  190. if err == AsyncTimeoutErr {
  191. return &r, err
  192. }
  193. return nil, err
  194. }
  195. if err := json.Unmarshal(b, &r); err != nil {
  196. return nil, err
  197. }
  198. }
  199. return &r, nil
  200. }
  201. type DeleteRemoteAccessVpnResponse struct {
  202. JobID string `json:"jobid,omitempty"`
  203. Displaytext string `json:"displaytext,omitempty"`
  204. Success bool `json:"success,omitempty"`
  205. }
  206. type ListRemoteAccessVpnsParams struct {
  207. p map[string]interface{}
  208. }
  209. func (p *ListRemoteAccessVpnsParams) toURLValues() url.Values {
  210. u := url.Values{}
  211. if p.p == nil {
  212. return u
  213. }
  214. if v, found := p.p["account"]; found {
  215. u.Set("account", v.(string))
  216. }
  217. if v, found := p.p["domainid"]; found {
  218. u.Set("domainid", v.(string))
  219. }
  220. if v, found := p.p["fordisplay"]; found {
  221. vv := strconv.FormatBool(v.(bool))
  222. u.Set("fordisplay", vv)
  223. }
  224. if v, found := p.p["id"]; found {
  225. u.Set("id", v.(string))
  226. }
  227. if v, found := p.p["isrecursive"]; found {
  228. vv := strconv.FormatBool(v.(bool))
  229. u.Set("isrecursive", vv)
  230. }
  231. if v, found := p.p["keyword"]; found {
  232. u.Set("keyword", v.(string))
  233. }
  234. if v, found := p.p["listall"]; found {
  235. vv := strconv.FormatBool(v.(bool))
  236. u.Set("listall", vv)
  237. }
  238. if v, found := p.p["networkid"]; found {
  239. u.Set("networkid", v.(string))
  240. }
  241. if v, found := p.p["page"]; found {
  242. vv := strconv.Itoa(v.(int))
  243. u.Set("page", vv)
  244. }
  245. if v, found := p.p["pagesize"]; found {
  246. vv := strconv.Itoa(v.(int))
  247. u.Set("pagesize", vv)
  248. }
  249. if v, found := p.p["projectid"]; found {
  250. u.Set("projectid", v.(string))
  251. }
  252. if v, found := p.p["publicipid"]; found {
  253. u.Set("publicipid", v.(string))
  254. }
  255. return u
  256. }
  257. func (p *ListRemoteAccessVpnsParams) SetAccount(v string) {
  258. if p.p == nil {
  259. p.p = make(map[string]interface{})
  260. }
  261. p.p["account"] = v
  262. return
  263. }
  264. func (p *ListRemoteAccessVpnsParams) SetDomainid(v string) {
  265. if p.p == nil {
  266. p.p = make(map[string]interface{})
  267. }
  268. p.p["domainid"] = v
  269. return
  270. }
  271. func (p *ListRemoteAccessVpnsParams) SetFordisplay(v bool) {
  272. if p.p == nil {
  273. p.p = make(map[string]interface{})
  274. }
  275. p.p["fordisplay"] = v
  276. return
  277. }
  278. func (p *ListRemoteAccessVpnsParams) SetId(v string) {
  279. if p.p == nil {
  280. p.p = make(map[string]interface{})
  281. }
  282. p.p["id"] = v
  283. return
  284. }
  285. func (p *ListRemoteAccessVpnsParams) SetIsrecursive(v bool) {
  286. if p.p == nil {
  287. p.p = make(map[string]interface{})
  288. }
  289. p.p["isrecursive"] = v
  290. return
  291. }
  292. func (p *ListRemoteAccessVpnsParams) SetKeyword(v string) {
  293. if p.p == nil {
  294. p.p = make(map[string]interface{})
  295. }
  296. p.p["keyword"] = v
  297. return
  298. }
  299. func (p *ListRemoteAccessVpnsParams) SetListall(v bool) {
  300. if p.p == nil {
  301. p.p = make(map[string]interface{})
  302. }
  303. p.p["listall"] = v
  304. return
  305. }
  306. func (p *ListRemoteAccessVpnsParams) SetNetworkid(v string) {
  307. if p.p == nil {
  308. p.p = make(map[string]interface{})
  309. }
  310. p.p["networkid"] = v
  311. return
  312. }
  313. func (p *ListRemoteAccessVpnsParams) SetPage(v int) {
  314. if p.p == nil {
  315. p.p = make(map[string]interface{})
  316. }
  317. p.p["page"] = v
  318. return
  319. }
  320. func (p *ListRemoteAccessVpnsParams) SetPagesize(v int) {
  321. if p.p == nil {
  322. p.p = make(map[string]interface{})
  323. }
  324. p.p["pagesize"] = v
  325. return
  326. }
  327. func (p *ListRemoteAccessVpnsParams) SetProjectid(v string) {
  328. if p.p == nil {
  329. p.p = make(map[string]interface{})
  330. }
  331. p.p["projectid"] = v
  332. return
  333. }
  334. func (p *ListRemoteAccessVpnsParams) SetPublicipid(v string) {
  335. if p.p == nil {
  336. p.p = make(map[string]interface{})
  337. }
  338. p.p["publicipid"] = v
  339. return
  340. }
  341. // You should always use this function to get a new ListRemoteAccessVpnsParams instance,
  342. // as then you are sure you have configured all required params
  343. func (s *VPNService) NewListRemoteAccessVpnsParams() *ListRemoteAccessVpnsParams {
  344. p := &ListRemoteAccessVpnsParams{}
  345. p.p = make(map[string]interface{})
  346. return p
  347. }
  348. // This is a courtesy helper function, which in some cases may not work as expected!
  349. func (s *VPNService) GetRemoteAccessVpnByID(id string, opts ...OptionFunc) (*RemoteAccessVpn, int, error) {
  350. p := &ListRemoteAccessVpnsParams{}
  351. p.p = make(map[string]interface{})
  352. p.p["id"] = id
  353. for _, fn := range opts {
  354. if err := fn(s.cs, p); err != nil {
  355. return nil, -1, err
  356. }
  357. }
  358. l, err := s.ListRemoteAccessVpns(p)
  359. if err != nil {
  360. if strings.Contains(err.Error(), fmt.Sprintf(
  361. "Invalid parameter id value=%s due to incorrect long value format, "+
  362. "or entity does not exist", id)) {
  363. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  364. }
  365. return nil, -1, err
  366. }
  367. if l.Count == 0 {
  368. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  369. }
  370. if l.Count == 1 {
  371. return l.RemoteAccessVpns[0], l.Count, nil
  372. }
  373. return nil, l.Count, fmt.Errorf("There is more then one result for RemoteAccessVpn UUID: %s!", id)
  374. }
  375. // Lists remote access vpns
  376. func (s *VPNService) ListRemoteAccessVpns(p *ListRemoteAccessVpnsParams) (*ListRemoteAccessVpnsResponse, error) {
  377. resp, err := s.cs.newRequest("listRemoteAccessVpns", p.toURLValues())
  378. if err != nil {
  379. return nil, err
  380. }
  381. var r ListRemoteAccessVpnsResponse
  382. if err := json.Unmarshal(resp, &r); err != nil {
  383. return nil, err
  384. }
  385. return &r, nil
  386. }
  387. type ListRemoteAccessVpnsResponse struct {
  388. Count int `json:"count"`
  389. RemoteAccessVpns []*RemoteAccessVpn `json:"remoteaccessvpn"`
  390. }
  391. type RemoteAccessVpn struct {
  392. Account string `json:"account,omitempty"`
  393. Domain string `json:"domain,omitempty"`
  394. Domainid string `json:"domainid,omitempty"`
  395. Fordisplay bool `json:"fordisplay,omitempty"`
  396. Id string `json:"id,omitempty"`
  397. Iprange string `json:"iprange,omitempty"`
  398. Presharedkey string `json:"presharedkey,omitempty"`
  399. Project string `json:"project,omitempty"`
  400. Projectid string `json:"projectid,omitempty"`
  401. Publicip string `json:"publicip,omitempty"`
  402. Publicipid string `json:"publicipid,omitempty"`
  403. State string `json:"state,omitempty"`
  404. }
  405. type UpdateRemoteAccessVpnParams struct {
  406. p map[string]interface{}
  407. }
  408. func (p *UpdateRemoteAccessVpnParams) toURLValues() url.Values {
  409. u := url.Values{}
  410. if p.p == nil {
  411. return u
  412. }
  413. if v, found := p.p["customid"]; found {
  414. u.Set("customid", v.(string))
  415. }
  416. if v, found := p.p["fordisplay"]; found {
  417. vv := strconv.FormatBool(v.(bool))
  418. u.Set("fordisplay", vv)
  419. }
  420. if v, found := p.p["id"]; found {
  421. u.Set("id", v.(string))
  422. }
  423. return u
  424. }
  425. func (p *UpdateRemoteAccessVpnParams) SetCustomid(v string) {
  426. if p.p == nil {
  427. p.p = make(map[string]interface{})
  428. }
  429. p.p["customid"] = v
  430. return
  431. }
  432. func (p *UpdateRemoteAccessVpnParams) SetFordisplay(v bool) {
  433. if p.p == nil {
  434. p.p = make(map[string]interface{})
  435. }
  436. p.p["fordisplay"] = v
  437. return
  438. }
  439. func (p *UpdateRemoteAccessVpnParams) SetId(v string) {
  440. if p.p == nil {
  441. p.p = make(map[string]interface{})
  442. }
  443. p.p["id"] = v
  444. return
  445. }
  446. // You should always use this function to get a new UpdateRemoteAccessVpnParams instance,
  447. // as then you are sure you have configured all required params
  448. func (s *VPNService) NewUpdateRemoteAccessVpnParams(id string) *UpdateRemoteAccessVpnParams {
  449. p := &UpdateRemoteAccessVpnParams{}
  450. p.p = make(map[string]interface{})
  451. p.p["id"] = id
  452. return p
  453. }
  454. // Updates remote access vpn
  455. func (s *VPNService) UpdateRemoteAccessVpn(p *UpdateRemoteAccessVpnParams) (*UpdateRemoteAccessVpnResponse, error) {
  456. resp, err := s.cs.newRequest("updateRemoteAccessVpn", p.toURLValues())
  457. if err != nil {
  458. return nil, err
  459. }
  460. var r UpdateRemoteAccessVpnResponse
  461. if err := json.Unmarshal(resp, &r); err != nil {
  462. return nil, err
  463. }
  464. // If we have a async client, we need to wait for the async result
  465. if s.cs.async {
  466. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  467. if err != nil {
  468. if err == AsyncTimeoutErr {
  469. return &r, err
  470. }
  471. return nil, err
  472. }
  473. b, err = getRawValue(b)
  474. if err != nil {
  475. return nil, err
  476. }
  477. if err := json.Unmarshal(b, &r); err != nil {
  478. return nil, err
  479. }
  480. }
  481. return &r, nil
  482. }
  483. type UpdateRemoteAccessVpnResponse struct {
  484. JobID string `json:"jobid,omitempty"`
  485. Account string `json:"account,omitempty"`
  486. Domain string `json:"domain,omitempty"`
  487. Domainid string `json:"domainid,omitempty"`
  488. Fordisplay bool `json:"fordisplay,omitempty"`
  489. Id string `json:"id,omitempty"`
  490. Iprange string `json:"iprange,omitempty"`
  491. Presharedkey string `json:"presharedkey,omitempty"`
  492. Project string `json:"project,omitempty"`
  493. Projectid string `json:"projectid,omitempty"`
  494. Publicip string `json:"publicip,omitempty"`
  495. Publicipid string `json:"publicipid,omitempty"`
  496. State string `json:"state,omitempty"`
  497. }
  498. type AddVpnUserParams struct {
  499. p map[string]interface{}
  500. }
  501. func (p *AddVpnUserParams) toURLValues() url.Values {
  502. u := url.Values{}
  503. if p.p == nil {
  504. return u
  505. }
  506. if v, found := p.p["account"]; found {
  507. u.Set("account", v.(string))
  508. }
  509. if v, found := p.p["domainid"]; found {
  510. u.Set("domainid", v.(string))
  511. }
  512. if v, found := p.p["password"]; found {
  513. u.Set("password", v.(string))
  514. }
  515. if v, found := p.p["projectid"]; found {
  516. u.Set("projectid", v.(string))
  517. }
  518. if v, found := p.p["username"]; found {
  519. u.Set("username", v.(string))
  520. }
  521. return u
  522. }
  523. func (p *AddVpnUserParams) SetAccount(v string) {
  524. if p.p == nil {
  525. p.p = make(map[string]interface{})
  526. }
  527. p.p["account"] = v
  528. return
  529. }
  530. func (p *AddVpnUserParams) SetDomainid(v string) {
  531. if p.p == nil {
  532. p.p = make(map[string]interface{})
  533. }
  534. p.p["domainid"] = v
  535. return
  536. }
  537. func (p *AddVpnUserParams) SetPassword(v string) {
  538. if p.p == nil {
  539. p.p = make(map[string]interface{})
  540. }
  541. p.p["password"] = v
  542. return
  543. }
  544. func (p *AddVpnUserParams) SetProjectid(v string) {
  545. if p.p == nil {
  546. p.p = make(map[string]interface{})
  547. }
  548. p.p["projectid"] = v
  549. return
  550. }
  551. func (p *AddVpnUserParams) SetUsername(v string) {
  552. if p.p == nil {
  553. p.p = make(map[string]interface{})
  554. }
  555. p.p["username"] = v
  556. return
  557. }
  558. // You should always use this function to get a new AddVpnUserParams instance,
  559. // as then you are sure you have configured all required params
  560. func (s *VPNService) NewAddVpnUserParams(password string, username string) *AddVpnUserParams {
  561. p := &AddVpnUserParams{}
  562. p.p = make(map[string]interface{})
  563. p.p["password"] = password
  564. p.p["username"] = username
  565. return p
  566. }
  567. // Adds vpn users
  568. func (s *VPNService) AddVpnUser(p *AddVpnUserParams) (*AddVpnUserResponse, error) {
  569. resp, err := s.cs.newRequest("addVpnUser", p.toURLValues())
  570. if err != nil {
  571. return nil, err
  572. }
  573. var r AddVpnUserResponse
  574. if err := json.Unmarshal(resp, &r); err != nil {
  575. return nil, err
  576. }
  577. // If we have a async client, we need to wait for the async result
  578. if s.cs.async {
  579. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  580. if err != nil {
  581. if err == AsyncTimeoutErr {
  582. return &r, err
  583. }
  584. return nil, err
  585. }
  586. b, err = getRawValue(b)
  587. if err != nil {
  588. return nil, err
  589. }
  590. if err := json.Unmarshal(b, &r); err != nil {
  591. return nil, err
  592. }
  593. }
  594. return &r, nil
  595. }
  596. type AddVpnUserResponse struct {
  597. JobID string `json:"jobid,omitempty"`
  598. Account string `json:"account,omitempty"`
  599. Domain string `json:"domain,omitempty"`
  600. Domainid string `json:"domainid,omitempty"`
  601. Id string `json:"id,omitempty"`
  602. Project string `json:"project,omitempty"`
  603. Projectid string `json:"projectid,omitempty"`
  604. State string `json:"state,omitempty"`
  605. Username string `json:"username,omitempty"`
  606. }
  607. type RemoveVpnUserParams struct {
  608. p map[string]interface{}
  609. }
  610. func (p *RemoveVpnUserParams) toURLValues() url.Values {
  611. u := url.Values{}
  612. if p.p == nil {
  613. return u
  614. }
  615. if v, found := p.p["account"]; found {
  616. u.Set("account", v.(string))
  617. }
  618. if v, found := p.p["domainid"]; found {
  619. u.Set("domainid", v.(string))
  620. }
  621. if v, found := p.p["projectid"]; found {
  622. u.Set("projectid", v.(string))
  623. }
  624. if v, found := p.p["username"]; found {
  625. u.Set("username", v.(string))
  626. }
  627. return u
  628. }
  629. func (p *RemoveVpnUserParams) SetAccount(v string) {
  630. if p.p == nil {
  631. p.p = make(map[string]interface{})
  632. }
  633. p.p["account"] = v
  634. return
  635. }
  636. func (p *RemoveVpnUserParams) SetDomainid(v string) {
  637. if p.p == nil {
  638. p.p = make(map[string]interface{})
  639. }
  640. p.p["domainid"] = v
  641. return
  642. }
  643. func (p *RemoveVpnUserParams) SetProjectid(v string) {
  644. if p.p == nil {
  645. p.p = make(map[string]interface{})
  646. }
  647. p.p["projectid"] = v
  648. return
  649. }
  650. func (p *RemoveVpnUserParams) SetUsername(v string) {
  651. if p.p == nil {
  652. p.p = make(map[string]interface{})
  653. }
  654. p.p["username"] = v
  655. return
  656. }
  657. // You should always use this function to get a new RemoveVpnUserParams instance,
  658. // as then you are sure you have configured all required params
  659. func (s *VPNService) NewRemoveVpnUserParams(username string) *RemoveVpnUserParams {
  660. p := &RemoveVpnUserParams{}
  661. p.p = make(map[string]interface{})
  662. p.p["username"] = username
  663. return p
  664. }
  665. // Removes vpn user
  666. func (s *VPNService) RemoveVpnUser(p *RemoveVpnUserParams) (*RemoveVpnUserResponse, error) {
  667. resp, err := s.cs.newRequest("removeVpnUser", p.toURLValues())
  668. if err != nil {
  669. return nil, err
  670. }
  671. var r RemoveVpnUserResponse
  672. if err := json.Unmarshal(resp, &r); err != nil {
  673. return nil, err
  674. }
  675. // If we have a async client, we need to wait for the async result
  676. if s.cs.async {
  677. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  678. if err != nil {
  679. if err == AsyncTimeoutErr {
  680. return &r, err
  681. }
  682. return nil, err
  683. }
  684. if err := json.Unmarshal(b, &r); err != nil {
  685. return nil, err
  686. }
  687. }
  688. return &r, nil
  689. }
  690. type RemoveVpnUserResponse struct {
  691. JobID string `json:"jobid,omitempty"`
  692. Displaytext string `json:"displaytext,omitempty"`
  693. Success bool `json:"success,omitempty"`
  694. }
  695. type ListVpnUsersParams struct {
  696. p map[string]interface{}
  697. }
  698. func (p *ListVpnUsersParams) toURLValues() url.Values {
  699. u := url.Values{}
  700. if p.p == nil {
  701. return u
  702. }
  703. if v, found := p.p["account"]; found {
  704. u.Set("account", v.(string))
  705. }
  706. if v, found := p.p["domainid"]; found {
  707. u.Set("domainid", v.(string))
  708. }
  709. if v, found := p.p["id"]; found {
  710. u.Set("id", v.(string))
  711. }
  712. if v, found := p.p["isrecursive"]; found {
  713. vv := strconv.FormatBool(v.(bool))
  714. u.Set("isrecursive", vv)
  715. }
  716. if v, found := p.p["keyword"]; found {
  717. u.Set("keyword", v.(string))
  718. }
  719. if v, found := p.p["listall"]; found {
  720. vv := strconv.FormatBool(v.(bool))
  721. u.Set("listall", vv)
  722. }
  723. if v, found := p.p["page"]; found {
  724. vv := strconv.Itoa(v.(int))
  725. u.Set("page", vv)
  726. }
  727. if v, found := p.p["pagesize"]; found {
  728. vv := strconv.Itoa(v.(int))
  729. u.Set("pagesize", vv)
  730. }
  731. if v, found := p.p["projectid"]; found {
  732. u.Set("projectid", v.(string))
  733. }
  734. if v, found := p.p["username"]; found {
  735. u.Set("username", v.(string))
  736. }
  737. return u
  738. }
  739. func (p *ListVpnUsersParams) SetAccount(v string) {
  740. if p.p == nil {
  741. p.p = make(map[string]interface{})
  742. }
  743. p.p["account"] = v
  744. return
  745. }
  746. func (p *ListVpnUsersParams) SetDomainid(v string) {
  747. if p.p == nil {
  748. p.p = make(map[string]interface{})
  749. }
  750. p.p["domainid"] = v
  751. return
  752. }
  753. func (p *ListVpnUsersParams) SetId(v string) {
  754. if p.p == nil {
  755. p.p = make(map[string]interface{})
  756. }
  757. p.p["id"] = v
  758. return
  759. }
  760. func (p *ListVpnUsersParams) SetIsrecursive(v bool) {
  761. if p.p == nil {
  762. p.p = make(map[string]interface{})
  763. }
  764. p.p["isrecursive"] = v
  765. return
  766. }
  767. func (p *ListVpnUsersParams) SetKeyword(v string) {
  768. if p.p == nil {
  769. p.p = make(map[string]interface{})
  770. }
  771. p.p["keyword"] = v
  772. return
  773. }
  774. func (p *ListVpnUsersParams) SetListall(v bool) {
  775. if p.p == nil {
  776. p.p = make(map[string]interface{})
  777. }
  778. p.p["listall"] = v
  779. return
  780. }
  781. func (p *ListVpnUsersParams) SetPage(v int) {
  782. if p.p == nil {
  783. p.p = make(map[string]interface{})
  784. }
  785. p.p["page"] = v
  786. return
  787. }
  788. func (p *ListVpnUsersParams) SetPagesize(v int) {
  789. if p.p == nil {
  790. p.p = make(map[string]interface{})
  791. }
  792. p.p["pagesize"] = v
  793. return
  794. }
  795. func (p *ListVpnUsersParams) SetProjectid(v string) {
  796. if p.p == nil {
  797. p.p = make(map[string]interface{})
  798. }
  799. p.p["projectid"] = v
  800. return
  801. }
  802. func (p *ListVpnUsersParams) SetUsername(v string) {
  803. if p.p == nil {
  804. p.p = make(map[string]interface{})
  805. }
  806. p.p["username"] = v
  807. return
  808. }
  809. // You should always use this function to get a new ListVpnUsersParams instance,
  810. // as then you are sure you have configured all required params
  811. func (s *VPNService) NewListVpnUsersParams() *ListVpnUsersParams {
  812. p := &ListVpnUsersParams{}
  813. p.p = make(map[string]interface{})
  814. return p
  815. }
  816. // This is a courtesy helper function, which in some cases may not work as expected!
  817. func (s *VPNService) GetVpnUserByID(id string, opts ...OptionFunc) (*VpnUser, int, error) {
  818. p := &ListVpnUsersParams{}
  819. p.p = make(map[string]interface{})
  820. p.p["id"] = id
  821. for _, fn := range opts {
  822. if err := fn(s.cs, p); err != nil {
  823. return nil, -1, err
  824. }
  825. }
  826. l, err := s.ListVpnUsers(p)
  827. if err != nil {
  828. if strings.Contains(err.Error(), fmt.Sprintf(
  829. "Invalid parameter id value=%s due to incorrect long value format, "+
  830. "or entity does not exist", id)) {
  831. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  832. }
  833. return nil, -1, err
  834. }
  835. if l.Count == 0 {
  836. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  837. }
  838. if l.Count == 1 {
  839. return l.VpnUsers[0], l.Count, nil
  840. }
  841. return nil, l.Count, fmt.Errorf("There is more then one result for VpnUser UUID: %s!", id)
  842. }
  843. // Lists vpn users
  844. func (s *VPNService) ListVpnUsers(p *ListVpnUsersParams) (*ListVpnUsersResponse, error) {
  845. resp, err := s.cs.newRequest("listVpnUsers", p.toURLValues())
  846. if err != nil {
  847. return nil, err
  848. }
  849. var r ListVpnUsersResponse
  850. if err := json.Unmarshal(resp, &r); err != nil {
  851. return nil, err
  852. }
  853. return &r, nil
  854. }
  855. type ListVpnUsersResponse struct {
  856. Count int `json:"count"`
  857. VpnUsers []*VpnUser `json:"vpnuser"`
  858. }
  859. type VpnUser struct {
  860. Account string `json:"account,omitempty"`
  861. Domain string `json:"domain,omitempty"`
  862. Domainid string `json:"domainid,omitempty"`
  863. Id string `json:"id,omitempty"`
  864. Project string `json:"project,omitempty"`
  865. Projectid string `json:"projectid,omitempty"`
  866. State string `json:"state,omitempty"`
  867. Username string `json:"username,omitempty"`
  868. }
  869. type CreateVpnCustomerGatewayParams struct {
  870. p map[string]interface{}
  871. }
  872. func (p *CreateVpnCustomerGatewayParams) toURLValues() url.Values {
  873. u := url.Values{}
  874. if p.p == nil {
  875. return u
  876. }
  877. if v, found := p.p["account"]; found {
  878. u.Set("account", v.(string))
  879. }
  880. if v, found := p.p["cidrlist"]; found {
  881. u.Set("cidrlist", v.(string))
  882. }
  883. if v, found := p.p["domainid"]; found {
  884. u.Set("domainid", v.(string))
  885. }
  886. if v, found := p.p["dpd"]; found {
  887. vv := strconv.FormatBool(v.(bool))
  888. u.Set("dpd", vv)
  889. }
  890. if v, found := p.p["esplifetime"]; found {
  891. vv := strconv.FormatInt(v.(int64), 10)
  892. u.Set("esplifetime", vv)
  893. }
  894. if v, found := p.p["esppolicy"]; found {
  895. u.Set("esppolicy", v.(string))
  896. }
  897. if v, found := p.p["forceencap"]; found {
  898. vv := strconv.FormatBool(v.(bool))
  899. u.Set("forceencap", vv)
  900. }
  901. if v, found := p.p["gateway"]; found {
  902. u.Set("gateway", v.(string))
  903. }
  904. if v, found := p.p["ikelifetime"]; found {
  905. vv := strconv.FormatInt(v.(int64), 10)
  906. u.Set("ikelifetime", vv)
  907. }
  908. if v, found := p.p["ikepolicy"]; found {
  909. u.Set("ikepolicy", v.(string))
  910. }
  911. if v, found := p.p["ipsecpsk"]; found {
  912. u.Set("ipsecpsk", v.(string))
  913. }
  914. if v, found := p.p["name"]; found {
  915. u.Set("name", v.(string))
  916. }
  917. if v, found := p.p["projectid"]; found {
  918. u.Set("projectid", v.(string))
  919. }
  920. return u
  921. }
  922. func (p *CreateVpnCustomerGatewayParams) SetAccount(v string) {
  923. if p.p == nil {
  924. p.p = make(map[string]interface{})
  925. }
  926. p.p["account"] = v
  927. return
  928. }
  929. func (p *CreateVpnCustomerGatewayParams) SetCidrlist(v string) {
  930. if p.p == nil {
  931. p.p = make(map[string]interface{})
  932. }
  933. p.p["cidrlist"] = v
  934. return
  935. }
  936. func (p *CreateVpnCustomerGatewayParams) SetDomainid(v string) {
  937. if p.p == nil {
  938. p.p = make(map[string]interface{})
  939. }
  940. p.p["domainid"] = v
  941. return
  942. }
  943. func (p *CreateVpnCustomerGatewayParams) SetDpd(v bool) {
  944. if p.p == nil {
  945. p.p = make(map[string]interface{})
  946. }
  947. p.p["dpd"] = v
  948. return
  949. }
  950. func (p *CreateVpnCustomerGatewayParams) SetEsplifetime(v int64) {
  951. if p.p == nil {
  952. p.p = make(map[string]interface{})
  953. }
  954. p.p["esplifetime"] = v
  955. return
  956. }
  957. func (p *CreateVpnCustomerGatewayParams) SetEsppolicy(v string) {
  958. if p.p == nil {
  959. p.p = make(map[string]interface{})
  960. }
  961. p.p["esppolicy"] = v
  962. return
  963. }
  964. func (p *CreateVpnCustomerGatewayParams) SetForceencap(v bool) {
  965. if p.p == nil {
  966. p.p = make(map[string]interface{})
  967. }
  968. p.p["forceencap"] = v
  969. return
  970. }
  971. func (p *CreateVpnCustomerGatewayParams) SetGateway(v string) {
  972. if p.p == nil {
  973. p.p = make(map[string]interface{})
  974. }
  975. p.p["gateway"] = v
  976. return
  977. }
  978. func (p *CreateVpnCustomerGatewayParams) SetIkelifetime(v int64) {
  979. if p.p == nil {
  980. p.p = make(map[string]interface{})
  981. }
  982. p.p["ikelifetime"] = v
  983. return
  984. }
  985. func (p *CreateVpnCustomerGatewayParams) SetIkepolicy(v string) {
  986. if p.p == nil {
  987. p.p = make(map[string]interface{})
  988. }
  989. p.p["ikepolicy"] = v
  990. return
  991. }
  992. func (p *CreateVpnCustomerGatewayParams) SetIpsecpsk(v string) {
  993. if p.p == nil {
  994. p.p = make(map[string]interface{})
  995. }
  996. p.p["ipsecpsk"] = v
  997. return
  998. }
  999. func (p *CreateVpnCustomerGatewayParams) SetName(v string) {
  1000. if p.p == nil {
  1001. p.p = make(map[string]interface{})
  1002. }
  1003. p.p["name"] = v
  1004. return
  1005. }
  1006. func (p *CreateVpnCustomerGatewayParams) SetProjectid(v string) {
  1007. if p.p == nil {
  1008. p.p = make(map[string]interface{})
  1009. }
  1010. p.p["projectid"] = v
  1011. return
  1012. }
  1013. // You should always use this function to get a new CreateVpnCustomerGatewayParams instance,
  1014. // as then you are sure you have configured all required params
  1015. func (s *VPNService) NewCreateVpnCustomerGatewayParams(cidrlist string, esppolicy string, gateway string, ikepolicy string, ipsecpsk string) *CreateVpnCustomerGatewayParams {
  1016. p := &CreateVpnCustomerGatewayParams{}
  1017. p.p = make(map[string]interface{})
  1018. p.p["cidrlist"] = cidrlist
  1019. p.p["esppolicy"] = esppolicy
  1020. p.p["gateway"] = gateway
  1021. p.p["ikepolicy"] = ikepolicy
  1022. p.p["ipsecpsk"] = ipsecpsk
  1023. return p
  1024. }
  1025. // Creates site to site vpn customer gateway
  1026. func (s *VPNService) CreateVpnCustomerGateway(p *CreateVpnCustomerGatewayParams) (*CreateVpnCustomerGatewayResponse, error) {
  1027. resp, err := s.cs.newRequest("createVpnCustomerGateway", p.toURLValues())
  1028. if err != nil {
  1029. return nil, err
  1030. }
  1031. var r CreateVpnCustomerGatewayResponse
  1032. if err := json.Unmarshal(resp, &r); err != nil {
  1033. return nil, err
  1034. }
  1035. // If we have a async client, we need to wait for the async result
  1036. if s.cs.async {
  1037. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1038. if err != nil {
  1039. if err == AsyncTimeoutErr {
  1040. return &r, err
  1041. }
  1042. return nil, err
  1043. }
  1044. b, err = getRawValue(b)
  1045. if err != nil {
  1046. return nil, err
  1047. }
  1048. if err := json.Unmarshal(b, &r); err != nil {
  1049. return nil, err
  1050. }
  1051. }
  1052. return &r, nil
  1053. }
  1054. type CreateVpnCustomerGatewayResponse struct {
  1055. JobID string `json:"jobid,omitempty"`
  1056. Account string `json:"account,omitempty"`
  1057. Cidrlist string `json:"cidrlist,omitempty"`
  1058. Domain string `json:"domain,omitempty"`
  1059. Domainid string `json:"domainid,omitempty"`
  1060. Dpd bool `json:"dpd,omitempty"`
  1061. Esplifetime int64 `json:"esplifetime,omitempty"`
  1062. Esppolicy string `json:"esppolicy,omitempty"`
  1063. Forceencap bool `json:"forceencap,omitempty"`
  1064. Gateway string `json:"gateway,omitempty"`
  1065. Id string `json:"id,omitempty"`
  1066. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  1067. Ikepolicy string `json:"ikepolicy,omitempty"`
  1068. Ipaddress string `json:"ipaddress,omitempty"`
  1069. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  1070. Name string `json:"name,omitempty"`
  1071. Project string `json:"project,omitempty"`
  1072. Projectid string `json:"projectid,omitempty"`
  1073. Removed string `json:"removed,omitempty"`
  1074. }
  1075. type CreateVpnGatewayParams struct {
  1076. p map[string]interface{}
  1077. }
  1078. func (p *CreateVpnGatewayParams) toURLValues() url.Values {
  1079. u := url.Values{}
  1080. if p.p == nil {
  1081. return u
  1082. }
  1083. if v, found := p.p["fordisplay"]; found {
  1084. vv := strconv.FormatBool(v.(bool))
  1085. u.Set("fordisplay", vv)
  1086. }
  1087. if v, found := p.p["vpcid"]; found {
  1088. u.Set("vpcid", v.(string))
  1089. }
  1090. return u
  1091. }
  1092. func (p *CreateVpnGatewayParams) SetFordisplay(v bool) {
  1093. if p.p == nil {
  1094. p.p = make(map[string]interface{})
  1095. }
  1096. p.p["fordisplay"] = v
  1097. return
  1098. }
  1099. func (p *CreateVpnGatewayParams) SetVpcid(v string) {
  1100. if p.p == nil {
  1101. p.p = make(map[string]interface{})
  1102. }
  1103. p.p["vpcid"] = v
  1104. return
  1105. }
  1106. // You should always use this function to get a new CreateVpnGatewayParams instance,
  1107. // as then you are sure you have configured all required params
  1108. func (s *VPNService) NewCreateVpnGatewayParams(vpcid string) *CreateVpnGatewayParams {
  1109. p := &CreateVpnGatewayParams{}
  1110. p.p = make(map[string]interface{})
  1111. p.p["vpcid"] = vpcid
  1112. return p
  1113. }
  1114. // Creates site to site vpn local gateway
  1115. func (s *VPNService) CreateVpnGateway(p *CreateVpnGatewayParams) (*CreateVpnGatewayResponse, error) {
  1116. resp, err := s.cs.newRequest("createVpnGateway", p.toURLValues())
  1117. if err != nil {
  1118. return nil, err
  1119. }
  1120. var r CreateVpnGatewayResponse
  1121. if err := json.Unmarshal(resp, &r); err != nil {
  1122. return nil, err
  1123. }
  1124. // If we have a async client, we need to wait for the async result
  1125. if s.cs.async {
  1126. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1127. if err != nil {
  1128. if err == AsyncTimeoutErr {
  1129. return &r, err
  1130. }
  1131. return nil, err
  1132. }
  1133. b, err = getRawValue(b)
  1134. if err != nil {
  1135. return nil, err
  1136. }
  1137. if err := json.Unmarshal(b, &r); err != nil {
  1138. return nil, err
  1139. }
  1140. }
  1141. return &r, nil
  1142. }
  1143. type CreateVpnGatewayResponse struct {
  1144. JobID string `json:"jobid,omitempty"`
  1145. Account string `json:"account,omitempty"`
  1146. Domain string `json:"domain,omitempty"`
  1147. Domainid string `json:"domainid,omitempty"`
  1148. Fordisplay bool `json:"fordisplay,omitempty"`
  1149. Id string `json:"id,omitempty"`
  1150. Project string `json:"project,omitempty"`
  1151. Projectid string `json:"projectid,omitempty"`
  1152. Publicip string `json:"publicip,omitempty"`
  1153. Removed string `json:"removed,omitempty"`
  1154. Vpcid string `json:"vpcid,omitempty"`
  1155. }
  1156. type CreateVpnConnectionParams struct {
  1157. p map[string]interface{}
  1158. }
  1159. func (p *CreateVpnConnectionParams) toURLValues() url.Values {
  1160. u := url.Values{}
  1161. if p.p == nil {
  1162. return u
  1163. }
  1164. if v, found := p.p["fordisplay"]; found {
  1165. vv := strconv.FormatBool(v.(bool))
  1166. u.Set("fordisplay", vv)
  1167. }
  1168. if v, found := p.p["passive"]; found {
  1169. vv := strconv.FormatBool(v.(bool))
  1170. u.Set("passive", vv)
  1171. }
  1172. if v, found := p.p["s2scustomergatewayid"]; found {
  1173. u.Set("s2scustomergatewayid", v.(string))
  1174. }
  1175. if v, found := p.p["s2svpngatewayid"]; found {
  1176. u.Set("s2svpngatewayid", v.(string))
  1177. }
  1178. return u
  1179. }
  1180. func (p *CreateVpnConnectionParams) SetFordisplay(v bool) {
  1181. if p.p == nil {
  1182. p.p = make(map[string]interface{})
  1183. }
  1184. p.p["fordisplay"] = v
  1185. return
  1186. }
  1187. func (p *CreateVpnConnectionParams) SetPassive(v bool) {
  1188. if p.p == nil {
  1189. p.p = make(map[string]interface{})
  1190. }
  1191. p.p["passive"] = v
  1192. return
  1193. }
  1194. func (p *CreateVpnConnectionParams) SetS2scustomergatewayid(v string) {
  1195. if p.p == nil {
  1196. p.p = make(map[string]interface{})
  1197. }
  1198. p.p["s2scustomergatewayid"] = v
  1199. return
  1200. }
  1201. func (p *CreateVpnConnectionParams) SetS2svpngatewayid(v string) {
  1202. if p.p == nil {
  1203. p.p = make(map[string]interface{})
  1204. }
  1205. p.p["s2svpngatewayid"] = v
  1206. return
  1207. }
  1208. // You should always use this function to get a new CreateVpnConnectionParams instance,
  1209. // as then you are sure you have configured all required params
  1210. func (s *VPNService) NewCreateVpnConnectionParams(s2scustomergatewayid string, s2svpngatewayid string) *CreateVpnConnectionParams {
  1211. p := &CreateVpnConnectionParams{}
  1212. p.p = make(map[string]interface{})
  1213. p.p["s2scustomergatewayid"] = s2scustomergatewayid
  1214. p.p["s2svpngatewayid"] = s2svpngatewayid
  1215. return p
  1216. }
  1217. // Create site to site vpn connection
  1218. func (s *VPNService) CreateVpnConnection(p *CreateVpnConnectionParams) (*CreateVpnConnectionResponse, error) {
  1219. resp, err := s.cs.newRequest("createVpnConnection", p.toURLValues())
  1220. if err != nil {
  1221. return nil, err
  1222. }
  1223. var r CreateVpnConnectionResponse
  1224. if err := json.Unmarshal(resp, &r); err != nil {
  1225. return nil, err
  1226. }
  1227. // If we have a async client, we need to wait for the async result
  1228. if s.cs.async {
  1229. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1230. if err != nil {
  1231. if err == AsyncTimeoutErr {
  1232. return &r, err
  1233. }
  1234. return nil, err
  1235. }
  1236. b, err = getRawValue(b)
  1237. if err != nil {
  1238. return nil, err
  1239. }
  1240. if err := json.Unmarshal(b, &r); err != nil {
  1241. return nil, err
  1242. }
  1243. }
  1244. return &r, nil
  1245. }
  1246. type CreateVpnConnectionResponse struct {
  1247. JobID string `json:"jobid,omitempty"`
  1248. Account string `json:"account,omitempty"`
  1249. Cidrlist string `json:"cidrlist,omitempty"`
  1250. Created string `json:"created,omitempty"`
  1251. Domain string `json:"domain,omitempty"`
  1252. Domainid string `json:"domainid,omitempty"`
  1253. Dpd bool `json:"dpd,omitempty"`
  1254. Esplifetime int64 `json:"esplifetime,omitempty"`
  1255. Esppolicy string `json:"esppolicy,omitempty"`
  1256. Forceencap bool `json:"forceencap,omitempty"`
  1257. Fordisplay bool `json:"fordisplay,omitempty"`
  1258. Gateway string `json:"gateway,omitempty"`
  1259. Id string `json:"id,omitempty"`
  1260. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  1261. Ikepolicy string `json:"ikepolicy,omitempty"`
  1262. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  1263. Passive bool `json:"passive,omitempty"`
  1264. Project string `json:"project,omitempty"`
  1265. Projectid string `json:"projectid,omitempty"`
  1266. Publicip string `json:"publicip,omitempty"`
  1267. Removed string `json:"removed,omitempty"`
  1268. S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"`
  1269. S2svpngatewayid string `json:"s2svpngatewayid,omitempty"`
  1270. State string `json:"state,omitempty"`
  1271. }
  1272. type DeleteVpnCustomerGatewayParams struct {
  1273. p map[string]interface{}
  1274. }
  1275. func (p *DeleteVpnCustomerGatewayParams) toURLValues() url.Values {
  1276. u := url.Values{}
  1277. if p.p == nil {
  1278. return u
  1279. }
  1280. if v, found := p.p["id"]; found {
  1281. u.Set("id", v.(string))
  1282. }
  1283. return u
  1284. }
  1285. func (p *DeleteVpnCustomerGatewayParams) SetId(v string) {
  1286. if p.p == nil {
  1287. p.p = make(map[string]interface{})
  1288. }
  1289. p.p["id"] = v
  1290. return
  1291. }
  1292. // You should always use this function to get a new DeleteVpnCustomerGatewayParams instance,
  1293. // as then you are sure you have configured all required params
  1294. func (s *VPNService) NewDeleteVpnCustomerGatewayParams(id string) *DeleteVpnCustomerGatewayParams {
  1295. p := &DeleteVpnCustomerGatewayParams{}
  1296. p.p = make(map[string]interface{})
  1297. p.p["id"] = id
  1298. return p
  1299. }
  1300. // Delete site to site vpn customer gateway
  1301. func (s *VPNService) DeleteVpnCustomerGateway(p *DeleteVpnCustomerGatewayParams) (*DeleteVpnCustomerGatewayResponse, error) {
  1302. resp, err := s.cs.newRequest("deleteVpnCustomerGateway", p.toURLValues())
  1303. if err != nil {
  1304. return nil, err
  1305. }
  1306. var r DeleteVpnCustomerGatewayResponse
  1307. if err := json.Unmarshal(resp, &r); err != nil {
  1308. return nil, err
  1309. }
  1310. // If we have a async client, we need to wait for the async result
  1311. if s.cs.async {
  1312. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1313. if err != nil {
  1314. if err == AsyncTimeoutErr {
  1315. return &r, err
  1316. }
  1317. return nil, err
  1318. }
  1319. if err := json.Unmarshal(b, &r); err != nil {
  1320. return nil, err
  1321. }
  1322. }
  1323. return &r, nil
  1324. }
  1325. type DeleteVpnCustomerGatewayResponse struct {
  1326. JobID string `json:"jobid,omitempty"`
  1327. Displaytext string `json:"displaytext,omitempty"`
  1328. Success bool `json:"success,omitempty"`
  1329. }
  1330. type DeleteVpnGatewayParams struct {
  1331. p map[string]interface{}
  1332. }
  1333. func (p *DeleteVpnGatewayParams) toURLValues() url.Values {
  1334. u := url.Values{}
  1335. if p.p == nil {
  1336. return u
  1337. }
  1338. if v, found := p.p["id"]; found {
  1339. u.Set("id", v.(string))
  1340. }
  1341. return u
  1342. }
  1343. func (p *DeleteVpnGatewayParams) SetId(v string) {
  1344. if p.p == nil {
  1345. p.p = make(map[string]interface{})
  1346. }
  1347. p.p["id"] = v
  1348. return
  1349. }
  1350. // You should always use this function to get a new DeleteVpnGatewayParams instance,
  1351. // as then you are sure you have configured all required params
  1352. func (s *VPNService) NewDeleteVpnGatewayParams(id string) *DeleteVpnGatewayParams {
  1353. p := &DeleteVpnGatewayParams{}
  1354. p.p = make(map[string]interface{})
  1355. p.p["id"] = id
  1356. return p
  1357. }
  1358. // Delete site to site vpn gateway
  1359. func (s *VPNService) DeleteVpnGateway(p *DeleteVpnGatewayParams) (*DeleteVpnGatewayResponse, error) {
  1360. resp, err := s.cs.newRequest("deleteVpnGateway", p.toURLValues())
  1361. if err != nil {
  1362. return nil, err
  1363. }
  1364. var r DeleteVpnGatewayResponse
  1365. if err := json.Unmarshal(resp, &r); err != nil {
  1366. return nil, err
  1367. }
  1368. // If we have a async client, we need to wait for the async result
  1369. if s.cs.async {
  1370. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1371. if err != nil {
  1372. if err == AsyncTimeoutErr {
  1373. return &r, err
  1374. }
  1375. return nil, err
  1376. }
  1377. if err := json.Unmarshal(b, &r); err != nil {
  1378. return nil, err
  1379. }
  1380. }
  1381. return &r, nil
  1382. }
  1383. type DeleteVpnGatewayResponse struct {
  1384. JobID string `json:"jobid,omitempty"`
  1385. Displaytext string `json:"displaytext,omitempty"`
  1386. Success bool `json:"success,omitempty"`
  1387. }
  1388. type DeleteVpnConnectionParams struct {
  1389. p map[string]interface{}
  1390. }
  1391. func (p *DeleteVpnConnectionParams) toURLValues() url.Values {
  1392. u := url.Values{}
  1393. if p.p == nil {
  1394. return u
  1395. }
  1396. if v, found := p.p["id"]; found {
  1397. u.Set("id", v.(string))
  1398. }
  1399. return u
  1400. }
  1401. func (p *DeleteVpnConnectionParams) SetId(v string) {
  1402. if p.p == nil {
  1403. p.p = make(map[string]interface{})
  1404. }
  1405. p.p["id"] = v
  1406. return
  1407. }
  1408. // You should always use this function to get a new DeleteVpnConnectionParams instance,
  1409. // as then you are sure you have configured all required params
  1410. func (s *VPNService) NewDeleteVpnConnectionParams(id string) *DeleteVpnConnectionParams {
  1411. p := &DeleteVpnConnectionParams{}
  1412. p.p = make(map[string]interface{})
  1413. p.p["id"] = id
  1414. return p
  1415. }
  1416. // Delete site to site vpn connection
  1417. func (s *VPNService) DeleteVpnConnection(p *DeleteVpnConnectionParams) (*DeleteVpnConnectionResponse, error) {
  1418. resp, err := s.cs.newRequest("deleteVpnConnection", p.toURLValues())
  1419. if err != nil {
  1420. return nil, err
  1421. }
  1422. var r DeleteVpnConnectionResponse
  1423. if err := json.Unmarshal(resp, &r); err != nil {
  1424. return nil, err
  1425. }
  1426. // If we have a async client, we need to wait for the async result
  1427. if s.cs.async {
  1428. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1429. if err != nil {
  1430. if err == AsyncTimeoutErr {
  1431. return &r, err
  1432. }
  1433. return nil, err
  1434. }
  1435. if err := json.Unmarshal(b, &r); err != nil {
  1436. return nil, err
  1437. }
  1438. }
  1439. return &r, nil
  1440. }
  1441. type DeleteVpnConnectionResponse struct {
  1442. JobID string `json:"jobid,omitempty"`
  1443. Displaytext string `json:"displaytext,omitempty"`
  1444. Success bool `json:"success,omitempty"`
  1445. }
  1446. type UpdateVpnCustomerGatewayParams struct {
  1447. p map[string]interface{}
  1448. }
  1449. func (p *UpdateVpnCustomerGatewayParams) toURLValues() url.Values {
  1450. u := url.Values{}
  1451. if p.p == nil {
  1452. return u
  1453. }
  1454. if v, found := p.p["account"]; found {
  1455. u.Set("account", v.(string))
  1456. }
  1457. if v, found := p.p["cidrlist"]; found {
  1458. u.Set("cidrlist", v.(string))
  1459. }
  1460. if v, found := p.p["domainid"]; found {
  1461. u.Set("domainid", v.(string))
  1462. }
  1463. if v, found := p.p["dpd"]; found {
  1464. vv := strconv.FormatBool(v.(bool))
  1465. u.Set("dpd", vv)
  1466. }
  1467. if v, found := p.p["esplifetime"]; found {
  1468. vv := strconv.FormatInt(v.(int64), 10)
  1469. u.Set("esplifetime", vv)
  1470. }
  1471. if v, found := p.p["esppolicy"]; found {
  1472. u.Set("esppolicy", v.(string))
  1473. }
  1474. if v, found := p.p["forceencap"]; found {
  1475. vv := strconv.FormatBool(v.(bool))
  1476. u.Set("forceencap", vv)
  1477. }
  1478. if v, found := p.p["gateway"]; found {
  1479. u.Set("gateway", v.(string))
  1480. }
  1481. if v, found := p.p["id"]; found {
  1482. u.Set("id", v.(string))
  1483. }
  1484. if v, found := p.p["ikelifetime"]; found {
  1485. vv := strconv.FormatInt(v.(int64), 10)
  1486. u.Set("ikelifetime", vv)
  1487. }
  1488. if v, found := p.p["ikepolicy"]; found {
  1489. u.Set("ikepolicy", v.(string))
  1490. }
  1491. if v, found := p.p["ipsecpsk"]; found {
  1492. u.Set("ipsecpsk", v.(string))
  1493. }
  1494. if v, found := p.p["name"]; found {
  1495. u.Set("name", v.(string))
  1496. }
  1497. return u
  1498. }
  1499. func (p *UpdateVpnCustomerGatewayParams) SetAccount(v string) {
  1500. if p.p == nil {
  1501. p.p = make(map[string]interface{})
  1502. }
  1503. p.p["account"] = v
  1504. return
  1505. }
  1506. func (p *UpdateVpnCustomerGatewayParams) SetCidrlist(v string) {
  1507. if p.p == nil {
  1508. p.p = make(map[string]interface{})
  1509. }
  1510. p.p["cidrlist"] = v
  1511. return
  1512. }
  1513. func (p *UpdateVpnCustomerGatewayParams) SetDomainid(v string) {
  1514. if p.p == nil {
  1515. p.p = make(map[string]interface{})
  1516. }
  1517. p.p["domainid"] = v
  1518. return
  1519. }
  1520. func (p *UpdateVpnCustomerGatewayParams) SetDpd(v bool) {
  1521. if p.p == nil {
  1522. p.p = make(map[string]interface{})
  1523. }
  1524. p.p["dpd"] = v
  1525. return
  1526. }
  1527. func (p *UpdateVpnCustomerGatewayParams) SetEsplifetime(v int64) {
  1528. if p.p == nil {
  1529. p.p = make(map[string]interface{})
  1530. }
  1531. p.p["esplifetime"] = v
  1532. return
  1533. }
  1534. func (p *UpdateVpnCustomerGatewayParams) SetEsppolicy(v string) {
  1535. if p.p == nil {
  1536. p.p = make(map[string]interface{})
  1537. }
  1538. p.p["esppolicy"] = v
  1539. return
  1540. }
  1541. func (p *UpdateVpnCustomerGatewayParams) SetForceencap(v bool) {
  1542. if p.p == nil {
  1543. p.p = make(map[string]interface{})
  1544. }
  1545. p.p["forceencap"] = v
  1546. return
  1547. }
  1548. func (p *UpdateVpnCustomerGatewayParams) SetGateway(v string) {
  1549. if p.p == nil {
  1550. p.p = make(map[string]interface{})
  1551. }
  1552. p.p["gateway"] = v
  1553. return
  1554. }
  1555. func (p *UpdateVpnCustomerGatewayParams) SetId(v string) {
  1556. if p.p == nil {
  1557. p.p = make(map[string]interface{})
  1558. }
  1559. p.p["id"] = v
  1560. return
  1561. }
  1562. func (p *UpdateVpnCustomerGatewayParams) SetIkelifetime(v int64) {
  1563. if p.p == nil {
  1564. p.p = make(map[string]interface{})
  1565. }
  1566. p.p["ikelifetime"] = v
  1567. return
  1568. }
  1569. func (p *UpdateVpnCustomerGatewayParams) SetIkepolicy(v string) {
  1570. if p.p == nil {
  1571. p.p = make(map[string]interface{})
  1572. }
  1573. p.p["ikepolicy"] = v
  1574. return
  1575. }
  1576. func (p *UpdateVpnCustomerGatewayParams) SetIpsecpsk(v string) {
  1577. if p.p == nil {
  1578. p.p = make(map[string]interface{})
  1579. }
  1580. p.p["ipsecpsk"] = v
  1581. return
  1582. }
  1583. func (p *UpdateVpnCustomerGatewayParams) SetName(v string) {
  1584. if p.p == nil {
  1585. p.p = make(map[string]interface{})
  1586. }
  1587. p.p["name"] = v
  1588. return
  1589. }
  1590. // You should always use this function to get a new UpdateVpnCustomerGatewayParams instance,
  1591. // as then you are sure you have configured all required params
  1592. func (s *VPNService) NewUpdateVpnCustomerGatewayParams(cidrlist string, esppolicy string, gateway string, id string, ikepolicy string, ipsecpsk string) *UpdateVpnCustomerGatewayParams {
  1593. p := &UpdateVpnCustomerGatewayParams{}
  1594. p.p = make(map[string]interface{})
  1595. p.p["cidrlist"] = cidrlist
  1596. p.p["esppolicy"] = esppolicy
  1597. p.p["gateway"] = gateway
  1598. p.p["id"] = id
  1599. p.p["ikepolicy"] = ikepolicy
  1600. p.p["ipsecpsk"] = ipsecpsk
  1601. return p
  1602. }
  1603. // Update site to site vpn customer gateway
  1604. func (s *VPNService) UpdateVpnCustomerGateway(p *UpdateVpnCustomerGatewayParams) (*UpdateVpnCustomerGatewayResponse, error) {
  1605. resp, err := s.cs.newRequest("updateVpnCustomerGateway", p.toURLValues())
  1606. if err != nil {
  1607. return nil, err
  1608. }
  1609. var r UpdateVpnCustomerGatewayResponse
  1610. if err := json.Unmarshal(resp, &r); err != nil {
  1611. return nil, err
  1612. }
  1613. // If we have a async client, we need to wait for the async result
  1614. if s.cs.async {
  1615. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1616. if err != nil {
  1617. if err == AsyncTimeoutErr {
  1618. return &r, err
  1619. }
  1620. return nil, err
  1621. }
  1622. b, err = getRawValue(b)
  1623. if err != nil {
  1624. return nil, err
  1625. }
  1626. if err := json.Unmarshal(b, &r); err != nil {
  1627. return nil, err
  1628. }
  1629. }
  1630. return &r, nil
  1631. }
  1632. type UpdateVpnCustomerGatewayResponse struct {
  1633. JobID string `json:"jobid,omitempty"`
  1634. Account string `json:"account,omitempty"`
  1635. Cidrlist string `json:"cidrlist,omitempty"`
  1636. Domain string `json:"domain,omitempty"`
  1637. Domainid string `json:"domainid,omitempty"`
  1638. Dpd bool `json:"dpd,omitempty"`
  1639. Esplifetime int64 `json:"esplifetime,omitempty"`
  1640. Esppolicy string `json:"esppolicy,omitempty"`
  1641. Forceencap bool `json:"forceencap,omitempty"`
  1642. Gateway string `json:"gateway,omitempty"`
  1643. Id string `json:"id,omitempty"`
  1644. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  1645. Ikepolicy string `json:"ikepolicy,omitempty"`
  1646. Ipaddress string `json:"ipaddress,omitempty"`
  1647. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  1648. Name string `json:"name,omitempty"`
  1649. Project string `json:"project,omitempty"`
  1650. Projectid string `json:"projectid,omitempty"`
  1651. Removed string `json:"removed,omitempty"`
  1652. }
  1653. type ResetVpnConnectionParams struct {
  1654. p map[string]interface{}
  1655. }
  1656. func (p *ResetVpnConnectionParams) toURLValues() url.Values {
  1657. u := url.Values{}
  1658. if p.p == nil {
  1659. return u
  1660. }
  1661. if v, found := p.p["account"]; found {
  1662. u.Set("account", v.(string))
  1663. }
  1664. if v, found := p.p["domainid"]; found {
  1665. u.Set("domainid", v.(string))
  1666. }
  1667. if v, found := p.p["id"]; found {
  1668. u.Set("id", v.(string))
  1669. }
  1670. return u
  1671. }
  1672. func (p *ResetVpnConnectionParams) SetAccount(v string) {
  1673. if p.p == nil {
  1674. p.p = make(map[string]interface{})
  1675. }
  1676. p.p["account"] = v
  1677. return
  1678. }
  1679. func (p *ResetVpnConnectionParams) SetDomainid(v string) {
  1680. if p.p == nil {
  1681. p.p = make(map[string]interface{})
  1682. }
  1683. p.p["domainid"] = v
  1684. return
  1685. }
  1686. func (p *ResetVpnConnectionParams) SetId(v string) {
  1687. if p.p == nil {
  1688. p.p = make(map[string]interface{})
  1689. }
  1690. p.p["id"] = v
  1691. return
  1692. }
  1693. // You should always use this function to get a new ResetVpnConnectionParams instance,
  1694. // as then you are sure you have configured all required params
  1695. func (s *VPNService) NewResetVpnConnectionParams(id string) *ResetVpnConnectionParams {
  1696. p := &ResetVpnConnectionParams{}
  1697. p.p = make(map[string]interface{})
  1698. p.p["id"] = id
  1699. return p
  1700. }
  1701. // Reset site to site vpn connection
  1702. func (s *VPNService) ResetVpnConnection(p *ResetVpnConnectionParams) (*ResetVpnConnectionResponse, error) {
  1703. resp, err := s.cs.newRequest("resetVpnConnection", p.toURLValues())
  1704. if err != nil {
  1705. return nil, err
  1706. }
  1707. var r ResetVpnConnectionResponse
  1708. if err := json.Unmarshal(resp, &r); err != nil {
  1709. return nil, err
  1710. }
  1711. // If we have a async client, we need to wait for the async result
  1712. if s.cs.async {
  1713. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1714. if err != nil {
  1715. if err == AsyncTimeoutErr {
  1716. return &r, err
  1717. }
  1718. return nil, err
  1719. }
  1720. b, err = getRawValue(b)
  1721. if err != nil {
  1722. return nil, err
  1723. }
  1724. if err := json.Unmarshal(b, &r); err != nil {
  1725. return nil, err
  1726. }
  1727. }
  1728. return &r, nil
  1729. }
  1730. type ResetVpnConnectionResponse struct {
  1731. JobID string `json:"jobid,omitempty"`
  1732. Account string `json:"account,omitempty"`
  1733. Cidrlist string `json:"cidrlist,omitempty"`
  1734. Created string `json:"created,omitempty"`
  1735. Domain string `json:"domain,omitempty"`
  1736. Domainid string `json:"domainid,omitempty"`
  1737. Dpd bool `json:"dpd,omitempty"`
  1738. Esplifetime int64 `json:"esplifetime,omitempty"`
  1739. Esppolicy string `json:"esppolicy,omitempty"`
  1740. Forceencap bool `json:"forceencap,omitempty"`
  1741. Fordisplay bool `json:"fordisplay,omitempty"`
  1742. Gateway string `json:"gateway,omitempty"`
  1743. Id string `json:"id,omitempty"`
  1744. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  1745. Ikepolicy string `json:"ikepolicy,omitempty"`
  1746. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  1747. Passive bool `json:"passive,omitempty"`
  1748. Project string `json:"project,omitempty"`
  1749. Projectid string `json:"projectid,omitempty"`
  1750. Publicip string `json:"publicip,omitempty"`
  1751. Removed string `json:"removed,omitempty"`
  1752. S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"`
  1753. S2svpngatewayid string `json:"s2svpngatewayid,omitempty"`
  1754. State string `json:"state,omitempty"`
  1755. }
  1756. type ListVpnCustomerGatewaysParams struct {
  1757. p map[string]interface{}
  1758. }
  1759. func (p *ListVpnCustomerGatewaysParams) toURLValues() url.Values {
  1760. u := url.Values{}
  1761. if p.p == nil {
  1762. return u
  1763. }
  1764. if v, found := p.p["account"]; found {
  1765. u.Set("account", v.(string))
  1766. }
  1767. if v, found := p.p["domainid"]; found {
  1768. u.Set("domainid", v.(string))
  1769. }
  1770. if v, found := p.p["id"]; found {
  1771. u.Set("id", v.(string))
  1772. }
  1773. if v, found := p.p["isrecursive"]; found {
  1774. vv := strconv.FormatBool(v.(bool))
  1775. u.Set("isrecursive", vv)
  1776. }
  1777. if v, found := p.p["keyword"]; found {
  1778. u.Set("keyword", v.(string))
  1779. }
  1780. if v, found := p.p["listall"]; found {
  1781. vv := strconv.FormatBool(v.(bool))
  1782. u.Set("listall", vv)
  1783. }
  1784. if v, found := p.p["page"]; found {
  1785. vv := strconv.Itoa(v.(int))
  1786. u.Set("page", vv)
  1787. }
  1788. if v, found := p.p["pagesize"]; found {
  1789. vv := strconv.Itoa(v.(int))
  1790. u.Set("pagesize", vv)
  1791. }
  1792. if v, found := p.p["projectid"]; found {
  1793. u.Set("projectid", v.(string))
  1794. }
  1795. return u
  1796. }
  1797. func (p *ListVpnCustomerGatewaysParams) SetAccount(v string) {
  1798. if p.p == nil {
  1799. p.p = make(map[string]interface{})
  1800. }
  1801. p.p["account"] = v
  1802. return
  1803. }
  1804. func (p *ListVpnCustomerGatewaysParams) SetDomainid(v string) {
  1805. if p.p == nil {
  1806. p.p = make(map[string]interface{})
  1807. }
  1808. p.p["domainid"] = v
  1809. return
  1810. }
  1811. func (p *ListVpnCustomerGatewaysParams) SetId(v string) {
  1812. if p.p == nil {
  1813. p.p = make(map[string]interface{})
  1814. }
  1815. p.p["id"] = v
  1816. return
  1817. }
  1818. func (p *ListVpnCustomerGatewaysParams) SetIsrecursive(v bool) {
  1819. if p.p == nil {
  1820. p.p = make(map[string]interface{})
  1821. }
  1822. p.p["isrecursive"] = v
  1823. return
  1824. }
  1825. func (p *ListVpnCustomerGatewaysParams) SetKeyword(v string) {
  1826. if p.p == nil {
  1827. p.p = make(map[string]interface{})
  1828. }
  1829. p.p["keyword"] = v
  1830. return
  1831. }
  1832. func (p *ListVpnCustomerGatewaysParams) SetListall(v bool) {
  1833. if p.p == nil {
  1834. p.p = make(map[string]interface{})
  1835. }
  1836. p.p["listall"] = v
  1837. return
  1838. }
  1839. func (p *ListVpnCustomerGatewaysParams) SetPage(v int) {
  1840. if p.p == nil {
  1841. p.p = make(map[string]interface{})
  1842. }
  1843. p.p["page"] = v
  1844. return
  1845. }
  1846. func (p *ListVpnCustomerGatewaysParams) SetPagesize(v int) {
  1847. if p.p == nil {
  1848. p.p = make(map[string]interface{})
  1849. }
  1850. p.p["pagesize"] = v
  1851. return
  1852. }
  1853. func (p *ListVpnCustomerGatewaysParams) SetProjectid(v string) {
  1854. if p.p == nil {
  1855. p.p = make(map[string]interface{})
  1856. }
  1857. p.p["projectid"] = v
  1858. return
  1859. }
  1860. // You should always use this function to get a new ListVpnCustomerGatewaysParams instance,
  1861. // as then you are sure you have configured all required params
  1862. func (s *VPNService) NewListVpnCustomerGatewaysParams() *ListVpnCustomerGatewaysParams {
  1863. p := &ListVpnCustomerGatewaysParams{}
  1864. p.p = make(map[string]interface{})
  1865. return p
  1866. }
  1867. // This is a courtesy helper function, which in some cases may not work as expected!
  1868. func (s *VPNService) GetVpnCustomerGatewayID(keyword string, opts ...OptionFunc) (string, int, error) {
  1869. p := &ListVpnCustomerGatewaysParams{}
  1870. p.p = make(map[string]interface{})
  1871. p.p["keyword"] = keyword
  1872. for _, fn := range opts {
  1873. if err := fn(s.cs, p); err != nil {
  1874. return "", -1, err
  1875. }
  1876. }
  1877. l, err := s.ListVpnCustomerGateways(p)
  1878. if err != nil {
  1879. return "", -1, err
  1880. }
  1881. if l.Count == 0 {
  1882. return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
  1883. }
  1884. if l.Count == 1 {
  1885. return l.VpnCustomerGateways[0].Id, l.Count, nil
  1886. }
  1887. if l.Count > 1 {
  1888. for _, v := range l.VpnCustomerGateways {
  1889. if v.Name == keyword {
  1890. return v.Id, l.Count, nil
  1891. }
  1892. }
  1893. }
  1894. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
  1895. }
  1896. // This is a courtesy helper function, which in some cases may not work as expected!
  1897. func (s *VPNService) GetVpnCustomerGatewayByName(name string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) {
  1898. id, count, err := s.GetVpnCustomerGatewayID(name, opts...)
  1899. if err != nil {
  1900. return nil, count, err
  1901. }
  1902. r, count, err := s.GetVpnCustomerGatewayByID(id, opts...)
  1903. if err != nil {
  1904. return nil, count, err
  1905. }
  1906. return r, count, nil
  1907. }
  1908. // This is a courtesy helper function, which in some cases may not work as expected!
  1909. func (s *VPNService) GetVpnCustomerGatewayByID(id string, opts ...OptionFunc) (*VpnCustomerGateway, int, error) {
  1910. p := &ListVpnCustomerGatewaysParams{}
  1911. p.p = make(map[string]interface{})
  1912. p.p["id"] = id
  1913. for _, fn := range opts {
  1914. if err := fn(s.cs, p); err != nil {
  1915. return nil, -1, err
  1916. }
  1917. }
  1918. l, err := s.ListVpnCustomerGateways(p)
  1919. if err != nil {
  1920. if strings.Contains(err.Error(), fmt.Sprintf(
  1921. "Invalid parameter id value=%s due to incorrect long value format, "+
  1922. "or entity does not exist", id)) {
  1923. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1924. }
  1925. return nil, -1, err
  1926. }
  1927. if l.Count == 0 {
  1928. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1929. }
  1930. if l.Count == 1 {
  1931. return l.VpnCustomerGateways[0], l.Count, nil
  1932. }
  1933. return nil, l.Count, fmt.Errorf("There is more then one result for VpnCustomerGateway UUID: %s!", id)
  1934. }
  1935. // Lists site to site vpn customer gateways
  1936. func (s *VPNService) ListVpnCustomerGateways(p *ListVpnCustomerGatewaysParams) (*ListVpnCustomerGatewaysResponse, error) {
  1937. resp, err := s.cs.newRequest("listVpnCustomerGateways", p.toURLValues())
  1938. if err != nil {
  1939. return nil, err
  1940. }
  1941. var r ListVpnCustomerGatewaysResponse
  1942. if err := json.Unmarshal(resp, &r); err != nil {
  1943. return nil, err
  1944. }
  1945. return &r, nil
  1946. }
  1947. type ListVpnCustomerGatewaysResponse struct {
  1948. Count int `json:"count"`
  1949. VpnCustomerGateways []*VpnCustomerGateway `json:"vpncustomergateway"`
  1950. }
  1951. type VpnCustomerGateway struct {
  1952. Account string `json:"account,omitempty"`
  1953. Cidrlist string `json:"cidrlist,omitempty"`
  1954. Domain string `json:"domain,omitempty"`
  1955. Domainid string `json:"domainid,omitempty"`
  1956. Dpd bool `json:"dpd,omitempty"`
  1957. Esplifetime int64 `json:"esplifetime,omitempty"`
  1958. Esppolicy string `json:"esppolicy,omitempty"`
  1959. Forceencap bool `json:"forceencap,omitempty"`
  1960. Gateway string `json:"gateway,omitempty"`
  1961. Id string `json:"id,omitempty"`
  1962. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  1963. Ikepolicy string `json:"ikepolicy,omitempty"`
  1964. Ipaddress string `json:"ipaddress,omitempty"`
  1965. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  1966. Name string `json:"name,omitempty"`
  1967. Project string `json:"project,omitempty"`
  1968. Projectid string `json:"projectid,omitempty"`
  1969. Removed string `json:"removed,omitempty"`
  1970. }
  1971. type ListVpnGatewaysParams struct {
  1972. p map[string]interface{}
  1973. }
  1974. func (p *ListVpnGatewaysParams) toURLValues() url.Values {
  1975. u := url.Values{}
  1976. if p.p == nil {
  1977. return u
  1978. }
  1979. if v, found := p.p["account"]; found {
  1980. u.Set("account", v.(string))
  1981. }
  1982. if v, found := p.p["domainid"]; found {
  1983. u.Set("domainid", v.(string))
  1984. }
  1985. if v, found := p.p["fordisplay"]; found {
  1986. vv := strconv.FormatBool(v.(bool))
  1987. u.Set("fordisplay", vv)
  1988. }
  1989. if v, found := p.p["id"]; found {
  1990. u.Set("id", v.(string))
  1991. }
  1992. if v, found := p.p["isrecursive"]; found {
  1993. vv := strconv.FormatBool(v.(bool))
  1994. u.Set("isrecursive", vv)
  1995. }
  1996. if v, found := p.p["keyword"]; found {
  1997. u.Set("keyword", v.(string))
  1998. }
  1999. if v, found := p.p["listall"]; found {
  2000. vv := strconv.FormatBool(v.(bool))
  2001. u.Set("listall", vv)
  2002. }
  2003. if v, found := p.p["page"]; found {
  2004. vv := strconv.Itoa(v.(int))
  2005. u.Set("page", vv)
  2006. }
  2007. if v, found := p.p["pagesize"]; found {
  2008. vv := strconv.Itoa(v.(int))
  2009. u.Set("pagesize", vv)
  2010. }
  2011. if v, found := p.p["projectid"]; found {
  2012. u.Set("projectid", v.(string))
  2013. }
  2014. if v, found := p.p["vpcid"]; found {
  2015. u.Set("vpcid", v.(string))
  2016. }
  2017. return u
  2018. }
  2019. func (p *ListVpnGatewaysParams) SetAccount(v string) {
  2020. if p.p == nil {
  2021. p.p = make(map[string]interface{})
  2022. }
  2023. p.p["account"] = v
  2024. return
  2025. }
  2026. func (p *ListVpnGatewaysParams) SetDomainid(v string) {
  2027. if p.p == nil {
  2028. p.p = make(map[string]interface{})
  2029. }
  2030. p.p["domainid"] = v
  2031. return
  2032. }
  2033. func (p *ListVpnGatewaysParams) SetFordisplay(v bool) {
  2034. if p.p == nil {
  2035. p.p = make(map[string]interface{})
  2036. }
  2037. p.p["fordisplay"] = v
  2038. return
  2039. }
  2040. func (p *ListVpnGatewaysParams) SetId(v string) {
  2041. if p.p == nil {
  2042. p.p = make(map[string]interface{})
  2043. }
  2044. p.p["id"] = v
  2045. return
  2046. }
  2047. func (p *ListVpnGatewaysParams) SetIsrecursive(v bool) {
  2048. if p.p == nil {
  2049. p.p = make(map[string]interface{})
  2050. }
  2051. p.p["isrecursive"] = v
  2052. return
  2053. }
  2054. func (p *ListVpnGatewaysParams) SetKeyword(v string) {
  2055. if p.p == nil {
  2056. p.p = make(map[string]interface{})
  2057. }
  2058. p.p["keyword"] = v
  2059. return
  2060. }
  2061. func (p *ListVpnGatewaysParams) SetListall(v bool) {
  2062. if p.p == nil {
  2063. p.p = make(map[string]interface{})
  2064. }
  2065. p.p["listall"] = v
  2066. return
  2067. }
  2068. func (p *ListVpnGatewaysParams) SetPage(v int) {
  2069. if p.p == nil {
  2070. p.p = make(map[string]interface{})
  2071. }
  2072. p.p["page"] = v
  2073. return
  2074. }
  2075. func (p *ListVpnGatewaysParams) SetPagesize(v int) {
  2076. if p.p == nil {
  2077. p.p = make(map[string]interface{})
  2078. }
  2079. p.p["pagesize"] = v
  2080. return
  2081. }
  2082. func (p *ListVpnGatewaysParams) SetProjectid(v string) {
  2083. if p.p == nil {
  2084. p.p = make(map[string]interface{})
  2085. }
  2086. p.p["projectid"] = v
  2087. return
  2088. }
  2089. func (p *ListVpnGatewaysParams) SetVpcid(v string) {
  2090. if p.p == nil {
  2091. p.p = make(map[string]interface{})
  2092. }
  2093. p.p["vpcid"] = v
  2094. return
  2095. }
  2096. // You should always use this function to get a new ListVpnGatewaysParams instance,
  2097. // as then you are sure you have configured all required params
  2098. func (s *VPNService) NewListVpnGatewaysParams() *ListVpnGatewaysParams {
  2099. p := &ListVpnGatewaysParams{}
  2100. p.p = make(map[string]interface{})
  2101. return p
  2102. }
  2103. // This is a courtesy helper function, which in some cases may not work as expected!
  2104. func (s *VPNService) GetVpnGatewayByID(id string, opts ...OptionFunc) (*VpnGateway, int, error) {
  2105. p := &ListVpnGatewaysParams{}
  2106. p.p = make(map[string]interface{})
  2107. p.p["id"] = id
  2108. for _, fn := range opts {
  2109. if err := fn(s.cs, p); err != nil {
  2110. return nil, -1, err
  2111. }
  2112. }
  2113. l, err := s.ListVpnGateways(p)
  2114. if err != nil {
  2115. if strings.Contains(err.Error(), fmt.Sprintf(
  2116. "Invalid parameter id value=%s due to incorrect long value format, "+
  2117. "or entity does not exist", id)) {
  2118. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  2119. }
  2120. return nil, -1, err
  2121. }
  2122. if l.Count == 0 {
  2123. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  2124. }
  2125. if l.Count == 1 {
  2126. return l.VpnGateways[0], l.Count, nil
  2127. }
  2128. return nil, l.Count, fmt.Errorf("There is more then one result for VpnGateway UUID: %s!", id)
  2129. }
  2130. // Lists site 2 site vpn gateways
  2131. func (s *VPNService) ListVpnGateways(p *ListVpnGatewaysParams) (*ListVpnGatewaysResponse, error) {
  2132. resp, err := s.cs.newRequest("listVpnGateways", p.toURLValues())
  2133. if err != nil {
  2134. return nil, err
  2135. }
  2136. var r ListVpnGatewaysResponse
  2137. if err := json.Unmarshal(resp, &r); err != nil {
  2138. return nil, err
  2139. }
  2140. return &r, nil
  2141. }
  2142. type ListVpnGatewaysResponse struct {
  2143. Count int `json:"count"`
  2144. VpnGateways []*VpnGateway `json:"vpngateway"`
  2145. }
  2146. type VpnGateway struct {
  2147. Account string `json:"account,omitempty"`
  2148. Domain string `json:"domain,omitempty"`
  2149. Domainid string `json:"domainid,omitempty"`
  2150. Fordisplay bool `json:"fordisplay,omitempty"`
  2151. Id string `json:"id,omitempty"`
  2152. Project string `json:"project,omitempty"`
  2153. Projectid string `json:"projectid,omitempty"`
  2154. Publicip string `json:"publicip,omitempty"`
  2155. Removed string `json:"removed,omitempty"`
  2156. Vpcid string `json:"vpcid,omitempty"`
  2157. }
  2158. type ListVpnConnectionsParams struct {
  2159. p map[string]interface{}
  2160. }
  2161. func (p *ListVpnConnectionsParams) toURLValues() url.Values {
  2162. u := url.Values{}
  2163. if p.p == nil {
  2164. return u
  2165. }
  2166. if v, found := p.p["account"]; found {
  2167. u.Set("account", v.(string))
  2168. }
  2169. if v, found := p.p["domainid"]; found {
  2170. u.Set("domainid", v.(string))
  2171. }
  2172. if v, found := p.p["fordisplay"]; found {
  2173. vv := strconv.FormatBool(v.(bool))
  2174. u.Set("fordisplay", vv)
  2175. }
  2176. if v, found := p.p["id"]; found {
  2177. u.Set("id", v.(string))
  2178. }
  2179. if v, found := p.p["isrecursive"]; found {
  2180. vv := strconv.FormatBool(v.(bool))
  2181. u.Set("isrecursive", vv)
  2182. }
  2183. if v, found := p.p["keyword"]; found {
  2184. u.Set("keyword", v.(string))
  2185. }
  2186. if v, found := p.p["listall"]; found {
  2187. vv := strconv.FormatBool(v.(bool))
  2188. u.Set("listall", vv)
  2189. }
  2190. if v, found := p.p["page"]; found {
  2191. vv := strconv.Itoa(v.(int))
  2192. u.Set("page", vv)
  2193. }
  2194. if v, found := p.p["pagesize"]; found {
  2195. vv := strconv.Itoa(v.(int))
  2196. u.Set("pagesize", vv)
  2197. }
  2198. if v, found := p.p["projectid"]; found {
  2199. u.Set("projectid", v.(string))
  2200. }
  2201. if v, found := p.p["vpcid"]; found {
  2202. u.Set("vpcid", v.(string))
  2203. }
  2204. return u
  2205. }
  2206. func (p *ListVpnConnectionsParams) SetAccount(v string) {
  2207. if p.p == nil {
  2208. p.p = make(map[string]interface{})
  2209. }
  2210. p.p["account"] = v
  2211. return
  2212. }
  2213. func (p *ListVpnConnectionsParams) SetDomainid(v string) {
  2214. if p.p == nil {
  2215. p.p = make(map[string]interface{})
  2216. }
  2217. p.p["domainid"] = v
  2218. return
  2219. }
  2220. func (p *ListVpnConnectionsParams) SetFordisplay(v bool) {
  2221. if p.p == nil {
  2222. p.p = make(map[string]interface{})
  2223. }
  2224. p.p["fordisplay"] = v
  2225. return
  2226. }
  2227. func (p *ListVpnConnectionsParams) SetId(v string) {
  2228. if p.p == nil {
  2229. p.p = make(map[string]interface{})
  2230. }
  2231. p.p["id"] = v
  2232. return
  2233. }
  2234. func (p *ListVpnConnectionsParams) SetIsrecursive(v bool) {
  2235. if p.p == nil {
  2236. p.p = make(map[string]interface{})
  2237. }
  2238. p.p["isrecursive"] = v
  2239. return
  2240. }
  2241. func (p *ListVpnConnectionsParams) SetKeyword(v string) {
  2242. if p.p == nil {
  2243. p.p = make(map[string]interface{})
  2244. }
  2245. p.p["keyword"] = v
  2246. return
  2247. }
  2248. func (p *ListVpnConnectionsParams) SetListall(v bool) {
  2249. if p.p == nil {
  2250. p.p = make(map[string]interface{})
  2251. }
  2252. p.p["listall"] = v
  2253. return
  2254. }
  2255. func (p *ListVpnConnectionsParams) SetPage(v int) {
  2256. if p.p == nil {
  2257. p.p = make(map[string]interface{})
  2258. }
  2259. p.p["page"] = v
  2260. return
  2261. }
  2262. func (p *ListVpnConnectionsParams) SetPagesize(v int) {
  2263. if p.p == nil {
  2264. p.p = make(map[string]interface{})
  2265. }
  2266. p.p["pagesize"] = v
  2267. return
  2268. }
  2269. func (p *ListVpnConnectionsParams) SetProjectid(v string) {
  2270. if p.p == nil {
  2271. p.p = make(map[string]interface{})
  2272. }
  2273. p.p["projectid"] = v
  2274. return
  2275. }
  2276. func (p *ListVpnConnectionsParams) SetVpcid(v string) {
  2277. if p.p == nil {
  2278. p.p = make(map[string]interface{})
  2279. }
  2280. p.p["vpcid"] = v
  2281. return
  2282. }
  2283. // You should always use this function to get a new ListVpnConnectionsParams instance,
  2284. // as then you are sure you have configured all required params
  2285. func (s *VPNService) NewListVpnConnectionsParams() *ListVpnConnectionsParams {
  2286. p := &ListVpnConnectionsParams{}
  2287. p.p = make(map[string]interface{})
  2288. return p
  2289. }
  2290. // This is a courtesy helper function, which in some cases may not work as expected!
  2291. func (s *VPNService) GetVpnConnectionByID(id string, opts ...OptionFunc) (*VpnConnection, int, error) {
  2292. p := &ListVpnConnectionsParams{}
  2293. p.p = make(map[string]interface{})
  2294. p.p["id"] = id
  2295. for _, fn := range opts {
  2296. if err := fn(s.cs, p); err != nil {
  2297. return nil, -1, err
  2298. }
  2299. }
  2300. l, err := s.ListVpnConnections(p)
  2301. if err != nil {
  2302. if strings.Contains(err.Error(), fmt.Sprintf(
  2303. "Invalid parameter id value=%s due to incorrect long value format, "+
  2304. "or entity does not exist", id)) {
  2305. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  2306. }
  2307. return nil, -1, err
  2308. }
  2309. if l.Count == 0 {
  2310. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  2311. }
  2312. if l.Count == 1 {
  2313. return l.VpnConnections[0], l.Count, nil
  2314. }
  2315. return nil, l.Count, fmt.Errorf("There is more then one result for VpnConnection UUID: %s!", id)
  2316. }
  2317. // Lists site to site vpn connection gateways
  2318. func (s *VPNService) ListVpnConnections(p *ListVpnConnectionsParams) (*ListVpnConnectionsResponse, error) {
  2319. resp, err := s.cs.newRequest("listVpnConnections", p.toURLValues())
  2320. if err != nil {
  2321. return nil, err
  2322. }
  2323. var r ListVpnConnectionsResponse
  2324. if err := json.Unmarshal(resp, &r); err != nil {
  2325. return nil, err
  2326. }
  2327. return &r, nil
  2328. }
  2329. type ListVpnConnectionsResponse struct {
  2330. Count int `json:"count"`
  2331. VpnConnections []*VpnConnection `json:"vpnconnection"`
  2332. }
  2333. type VpnConnection struct {
  2334. Account string `json:"account,omitempty"`
  2335. Cidrlist string `json:"cidrlist,omitempty"`
  2336. Created string `json:"created,omitempty"`
  2337. Domain string `json:"domain,omitempty"`
  2338. Domainid string `json:"domainid,omitempty"`
  2339. Dpd bool `json:"dpd,omitempty"`
  2340. Esplifetime int64 `json:"esplifetime,omitempty"`
  2341. Esppolicy string `json:"esppolicy,omitempty"`
  2342. Forceencap bool `json:"forceencap,omitempty"`
  2343. Fordisplay bool `json:"fordisplay,omitempty"`
  2344. Gateway string `json:"gateway,omitempty"`
  2345. Id string `json:"id,omitempty"`
  2346. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  2347. Ikepolicy string `json:"ikepolicy,omitempty"`
  2348. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  2349. Passive bool `json:"passive,omitempty"`
  2350. Project string `json:"project,omitempty"`
  2351. Projectid string `json:"projectid,omitempty"`
  2352. Publicip string `json:"publicip,omitempty"`
  2353. Removed string `json:"removed,omitempty"`
  2354. S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"`
  2355. S2svpngatewayid string `json:"s2svpngatewayid,omitempty"`
  2356. State string `json:"state,omitempty"`
  2357. }
  2358. type UpdateVpnConnectionParams struct {
  2359. p map[string]interface{}
  2360. }
  2361. func (p *UpdateVpnConnectionParams) toURLValues() url.Values {
  2362. u := url.Values{}
  2363. if p.p == nil {
  2364. return u
  2365. }
  2366. if v, found := p.p["customid"]; found {
  2367. u.Set("customid", v.(string))
  2368. }
  2369. if v, found := p.p["fordisplay"]; found {
  2370. vv := strconv.FormatBool(v.(bool))
  2371. u.Set("fordisplay", vv)
  2372. }
  2373. if v, found := p.p["id"]; found {
  2374. u.Set("id", v.(string))
  2375. }
  2376. return u
  2377. }
  2378. func (p *UpdateVpnConnectionParams) SetCustomid(v string) {
  2379. if p.p == nil {
  2380. p.p = make(map[string]interface{})
  2381. }
  2382. p.p["customid"] = v
  2383. return
  2384. }
  2385. func (p *UpdateVpnConnectionParams) SetFordisplay(v bool) {
  2386. if p.p == nil {
  2387. p.p = make(map[string]interface{})
  2388. }
  2389. p.p["fordisplay"] = v
  2390. return
  2391. }
  2392. func (p *UpdateVpnConnectionParams) SetId(v string) {
  2393. if p.p == nil {
  2394. p.p = make(map[string]interface{})
  2395. }
  2396. p.p["id"] = v
  2397. return
  2398. }
  2399. // You should always use this function to get a new UpdateVpnConnectionParams instance,
  2400. // as then you are sure you have configured all required params
  2401. func (s *VPNService) NewUpdateVpnConnectionParams(id string) *UpdateVpnConnectionParams {
  2402. p := &UpdateVpnConnectionParams{}
  2403. p.p = make(map[string]interface{})
  2404. p.p["id"] = id
  2405. return p
  2406. }
  2407. // Updates site to site vpn connection
  2408. func (s *VPNService) UpdateVpnConnection(p *UpdateVpnConnectionParams) (*UpdateVpnConnectionResponse, error) {
  2409. resp, err := s.cs.newRequest("updateVpnConnection", p.toURLValues())
  2410. if err != nil {
  2411. return nil, err
  2412. }
  2413. var r UpdateVpnConnectionResponse
  2414. if err := json.Unmarshal(resp, &r); err != nil {
  2415. return nil, err
  2416. }
  2417. // If we have a async client, we need to wait for the async result
  2418. if s.cs.async {
  2419. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2420. if err != nil {
  2421. if err == AsyncTimeoutErr {
  2422. return &r, err
  2423. }
  2424. return nil, err
  2425. }
  2426. b, err = getRawValue(b)
  2427. if err != nil {
  2428. return nil, err
  2429. }
  2430. if err := json.Unmarshal(b, &r); err != nil {
  2431. return nil, err
  2432. }
  2433. }
  2434. return &r, nil
  2435. }
  2436. type UpdateVpnConnectionResponse struct {
  2437. JobID string `json:"jobid,omitempty"`
  2438. Account string `json:"account,omitempty"`
  2439. Cidrlist string `json:"cidrlist,omitempty"`
  2440. Created string `json:"created,omitempty"`
  2441. Domain string `json:"domain,omitempty"`
  2442. Domainid string `json:"domainid,omitempty"`
  2443. Dpd bool `json:"dpd,omitempty"`
  2444. Esplifetime int64 `json:"esplifetime,omitempty"`
  2445. Esppolicy string `json:"esppolicy,omitempty"`
  2446. Forceencap bool `json:"forceencap,omitempty"`
  2447. Fordisplay bool `json:"fordisplay,omitempty"`
  2448. Gateway string `json:"gateway,omitempty"`
  2449. Id string `json:"id,omitempty"`
  2450. Ikelifetime int64 `json:"ikelifetime,omitempty"`
  2451. Ikepolicy string `json:"ikepolicy,omitempty"`
  2452. Ipsecpsk string `json:"ipsecpsk,omitempty"`
  2453. Passive bool `json:"passive,omitempty"`
  2454. Project string `json:"project,omitempty"`
  2455. Projectid string `json:"projectid,omitempty"`
  2456. Publicip string `json:"publicip,omitempty"`
  2457. Removed string `json:"removed,omitempty"`
  2458. S2scustomergatewayid string `json:"s2scustomergatewayid,omitempty"`
  2459. S2svpngatewayid string `json:"s2svpngatewayid,omitempty"`
  2460. State string `json:"state,omitempty"`
  2461. }
  2462. type UpdateVpnGatewayParams struct {
  2463. p map[string]interface{}
  2464. }
  2465. func (p *UpdateVpnGatewayParams) toURLValues() url.Values {
  2466. u := url.Values{}
  2467. if p.p == nil {
  2468. return u
  2469. }
  2470. if v, found := p.p["customid"]; found {
  2471. u.Set("customid", v.(string))
  2472. }
  2473. if v, found := p.p["fordisplay"]; found {
  2474. vv := strconv.FormatBool(v.(bool))
  2475. u.Set("fordisplay", vv)
  2476. }
  2477. if v, found := p.p["id"]; found {
  2478. u.Set("id", v.(string))
  2479. }
  2480. return u
  2481. }
  2482. func (p *UpdateVpnGatewayParams) SetCustomid(v string) {
  2483. if p.p == nil {
  2484. p.p = make(map[string]interface{})
  2485. }
  2486. p.p["customid"] = v
  2487. return
  2488. }
  2489. func (p *UpdateVpnGatewayParams) SetFordisplay(v bool) {
  2490. if p.p == nil {
  2491. p.p = make(map[string]interface{})
  2492. }
  2493. p.p["fordisplay"] = v
  2494. return
  2495. }
  2496. func (p *UpdateVpnGatewayParams) SetId(v string) {
  2497. if p.p == nil {
  2498. p.p = make(map[string]interface{})
  2499. }
  2500. p.p["id"] = v
  2501. return
  2502. }
  2503. // You should always use this function to get a new UpdateVpnGatewayParams instance,
  2504. // as then you are sure you have configured all required params
  2505. func (s *VPNService) NewUpdateVpnGatewayParams(id string) *UpdateVpnGatewayParams {
  2506. p := &UpdateVpnGatewayParams{}
  2507. p.p = make(map[string]interface{})
  2508. p.p["id"] = id
  2509. return p
  2510. }
  2511. // Updates site to site vpn local gateway
  2512. func (s *VPNService) UpdateVpnGateway(p *UpdateVpnGatewayParams) (*UpdateVpnGatewayResponse, error) {
  2513. resp, err := s.cs.newRequest("updateVpnGateway", p.toURLValues())
  2514. if err != nil {
  2515. return nil, err
  2516. }
  2517. var r UpdateVpnGatewayResponse
  2518. if err := json.Unmarshal(resp, &r); err != nil {
  2519. return nil, err
  2520. }
  2521. // If we have a async client, we need to wait for the async result
  2522. if s.cs.async {
  2523. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2524. if err != nil {
  2525. if err == AsyncTimeoutErr {
  2526. return &r, err
  2527. }
  2528. return nil, err
  2529. }
  2530. b, err = getRawValue(b)
  2531. if err != nil {
  2532. return nil, err
  2533. }
  2534. if err := json.Unmarshal(b, &r); err != nil {
  2535. return nil, err
  2536. }
  2537. }
  2538. return &r, nil
  2539. }
  2540. type UpdateVpnGatewayResponse struct {
  2541. JobID string `json:"jobid,omitempty"`
  2542. Account string `json:"account,omitempty"`
  2543. Domain string `json:"domain,omitempty"`
  2544. Domainid string `json:"domainid,omitempty"`
  2545. Fordisplay bool `json:"fordisplay,omitempty"`
  2546. Id string `json:"id,omitempty"`
  2547. Project string `json:"project,omitempty"`
  2548. Projectid string `json:"projectid,omitempty"`
  2549. Publicip string `json:"publicip,omitempty"`
  2550. Removed string `json:"removed,omitempty"`
  2551. Vpcid string `json:"vpcid,omitempty"`
  2552. }