├── .gitignore ├── .travis.yml ├── CNAME ├── Dockerfile ├── Dockerfile.alpine ├── LICENSE ├── README.md ├── _config.yml ├── archive └── packet-2.3.tar.gz ├── cmd ├── admin.go ├── api.go ├── baremetal.go ├── client.go ├── genautocomplete.go ├── gendoc.go ├── network.go ├── releaseNotes.go ├── root.go ├── storage.go ├── util.go └── version.go ├── doc ├── packet.md ├── packet_admin.md ├── packet_admin_add-profile.md ├── packet_admin_create-org.md ├── packet_admin_create-project.md ├── packet_admin_create-sshkey.md ├── packet_admin_delete-org.md ├── packet_admin_delete-profile.md ├── packet_admin_delete-project.md ├── packet_admin_delete-sshkey.md ├── packet_admin_list-facilities.md ├── packet_admin_list-org.md ├── packet_admin_list-orgs.md ├── packet_admin_list-os.md ├── packet_admin_list-payment-methods.md ├── packet_admin_list-plans.md ├── packet_admin_list-profiles.md ├── packet_admin_list-project-events.md ├── packet_admin_list-project.md ├── packet_admin_list-projects.md ├── packet_admin_list-sshkey.md ├── packet_admin_list-sshkeys.md ├── packet_admin_spot-prices.md ├── packet_admin_update-org.md ├── packet_admin_update-project.md ├── packet_admin_update-sshkey.md ├── packet_baremetal.md ├── packet_baremetal_create-device.md ├── packet_baremetal_delete-device.md ├── packet_baremetal_list-device.md ├── packet_baremetal_list-devices.md ├── packet_baremetal_list-events.md ├── packet_baremetal_lock-device.md ├── packet_baremetal_poweroff-device.md ├── packet_baremetal_poweron-device.md ├── packet_baremetal_reboot-device.md ├── packet_baremetal_unlock-device.md ├── packet_baremetal_update-device.md ├── packet_network.md ├── packet_network_assign-ip.md ├── packet_network_list-ip-reservation.md ├── packet_network_list-ip-reservations.md ├── packet_network_list-ip.md ├── packet_network_remove-ip-reservation.md ├── packet_network_request-more-ip-reservations.md ├── packet_network_unassign-ip.md ├── packet_storage.md ├── packet_storage_attach-volume.md ├── packet_storage_clone-volume.md ├── packet_storage_create-snapshot-policy.md ├── packet_storage_create-snapshot.md ├── packet_storage_create-volume.md ├── packet_storage_delete-snapshot-policy.md ├── packet_storage_delete-snapshot.md ├── packet_storage_delete-volume.md ├── packet_storage_detach-volume.md ├── packet_storage_list-snapshots.md ├── packet_storage_list-volume-events.md ├── packet_storage_list-volume.md ├── packet_storage_list-volumes.md ├── packet_storage_restore-volume.md ├── packet_storage_update-snapshot-policy.md └── packet_storage_update-volume.md ├── extpackngo ├── events.go ├── extpackngo.go ├── ip.go └── volumes.go └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | packet.wiki 3 | .vscode 4 | .idea 5 | .DS_Store 6 | homebrew-packet 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.8 5 | - 1.9 6 | - 1.7 7 | - 1.6 8 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | packetcli.ebsarr.com -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu 2 | 3 | RUN export GOPATH=$HOME/go && \ 4 | apt-get update && \ 5 | apt-get install -y git && \ 6 | apt-get install -y golang && \ 7 | apt-get install -y bash-completion && \ 8 | apt-get install -y ca-certificates && \ 9 | go get -u github.com/ebsarr/packet && \ 10 | mv $GOPATH/bin/packet /usr/local/bin && \ 11 | /usr/local/bin/packet genautocomplete && \ 12 | mv packet-autocomplete.sh /etc/bash_completion.d/packet &&\ 13 | sed -i -e 's/\#if \[ -f \/etc\/bash_completion/if \[ -f \/etc\/bash_completion/' -e 's/\# \. \/etc\/bash_completion/ \. \/etc\/bash_completion/' -e 's/\#fi$/fi/' $HOME/.bashrc &&\ 14 | rm -rf $HOME/go &&\ 15 | apt-get purge -y --auto-remove golang &&\ 16 | apt-get purge -y --auto-remove git 17 | 18 | CMD /usr/local/bin/packet -h 19 | -------------------------------------------------------------------------------- /Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM alpine:latest as build 2 | 3 | RUN apk -U --no-cache add \ 4 | build-base \ 5 | go \ 6 | git \ 7 | && go get --ldflags '-linkmode external -extldflags "-static"' -u github.com/ebsarr/packet 8 | 9 | FROM scratch 10 | COPY --from=build /etc/ssl /etc/ssl 11 | COPY --from=build /root/go/bin/packet /packet 12 | ENTRYPOINT ["/packet"] 13 | CMD ["-h"] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Bassirou Sarr . 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | 25 | 26 | packngo ( The packngo AUTHORS ) 27 | 28 | Copyright (c) 2014 The packngo AUTHORS. All rights reserved. 29 | 30 | MIT License 31 | 32 | Permission is hereby granted, free of charge, to any person obtaining 33 | a copy of this software and associated documentation files (the 34 | "Software"), to deal in the Software without restriction, including 35 | without limitation the rights to use, copy, modify, merge, publish, 36 | distribute, sublicense, and/or sell copies of the Software, and to 37 | permit persons to whom the Software is furnished to do so, subject to 38 | the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be 41 | included in all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 44 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 45 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 46 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 47 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 48 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 49 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 50 | 51 | ====================== 52 | Portions of the client are based on code at: 53 | https://github.com/google/go-github/ and 54 | https://github.com/digitalocean/godo 55 | 56 | Copyright (c) 2013 The go-github AUTHORS. All rights reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without 59 | modification, are permitted provided that the following conditions are 60 | met: 61 | 62 | * Redistributions of source code must retain the above copyright 63 | notice, this list of conditions and the following disclaimer. 64 | * Redistributions in binary form must reproduce the above 65 | copyright notice, this list of conditions and the following disclaimer 66 | in the documentation and/or other materials provided with the 67 | distribution. 68 | * Neither the name of Google Inc. nor the names of its 69 | contributors may be used to endorse or promote products derived from 70 | this software without specific prior written permission. 71 | 72 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 73 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 74 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 75 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 76 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 77 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 78 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 79 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 80 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 81 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 82 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 83 | 84 | 85 | cobra ( the cobra AUTHORS ) 86 | Apache License 87 | Version 2.0, January 2004 88 | http://www.apache.org/licenses/ 89 | 90 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 91 | 92 | 1. Definitions. 93 | 94 | "License" shall mean the terms and conditions for use, reproduction, 95 | and distribution as defined by Sections 1 through 9 of this document. 96 | 97 | "Licensor" shall mean the copyright owner or entity authorized by 98 | the copyright owner that is granting the License. 99 | 100 | "Legal Entity" shall mean the union of the acting entity and all 101 | other entities that control, are controlled by, or are under common 102 | control with that entity. For the purposes of this definition, 103 | "control" means (i) the power, direct or indirect, to cause the 104 | direction or management of such entity, whether by contract or 105 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 106 | outstanding shares, or (iii) beneficial ownership of such entity. 107 | 108 | "You" (or "Your") shall mean an individual or Legal Entity 109 | exercising permissions granted by this License. 110 | 111 | "Source" form shall mean the preferred form for making modifications, 112 | including but not limited to software source code, documentation 113 | source, and configuration files. 114 | 115 | "Object" form shall mean any form resulting from mechanical 116 | transformation or translation of a Source form, including but 117 | not limited to compiled object code, generated documentation, 118 | and conversions to other media types. 119 | 120 | "Work" shall mean the work of authorship, whether in Source or 121 | Object form, made available under the License, as indicated by a 122 | copyright notice that is included in or attached to the work 123 | (an example is provided in the Appendix below). 124 | 125 | "Derivative Works" shall mean any work, whether in Source or Object 126 | form, that is based on (or derived from) the Work and for which the 127 | editorial revisions, annotations, elaborations, or other modifications 128 | represent, as a whole, an original work of authorship. For the purposes 129 | of this License, Derivative Works shall not include works that remain 130 | separable from, or merely link (or bind by name) to the interfaces of, 131 | the Work and Derivative Works thereof. 132 | 133 | "Contribution" shall mean any work of authorship, including 134 | the original version of the Work and any modifications or additions 135 | to that Work or Derivative Works thereof, that is intentionally 136 | submitted to Licensor for inclusion in the Work by the copyright owner 137 | or by an individual or Legal Entity authorized to submit on behalf of 138 | the copyright owner. For the purposes of this definition, "submitted" 139 | means any form of electronic, verbal, or written communication sent 140 | to the Licensor or its representatives, including but not limited to 141 | communication on electronic mailing lists, source code control systems, 142 | and issue tracking systems that are managed by, or on behalf of, the 143 | Licensor for the purpose of discussing and improving the Work, but 144 | excluding communication that is conspicuously marked or otherwise 145 | designated in writing by the copyright owner as "Not a Contribution." 146 | 147 | "Contributor" shall mean Licensor and any individual or Legal Entity 148 | on behalf of whom a Contribution has been received by Licensor and 149 | subsequently incorporated within the Work. 150 | 151 | 2. Grant of Copyright License. Subject to the terms and conditions of 152 | this License, each Contributor hereby grants to You a perpetual, 153 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 154 | copyright license to reproduce, prepare Derivative Works of, 155 | publicly display, publicly perform, sublicense, and distribute the 156 | Work and such Derivative Works in Source or Object form. 157 | 158 | 3. Grant of Patent License. Subject to the terms and conditions of 159 | this License, each Contributor hereby grants to You a perpetual, 160 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 161 | (except as stated in this section) patent license to make, have made, 162 | use, offer to sell, sell, import, and otherwise transfer the Work, 163 | where such license applies only to those patent claims licensable 164 | by such Contributor that are necessarily infringed by their 165 | Contribution(s) alone or by combination of their Contribution(s) 166 | with the Work to which such Contribution(s) was submitted. If You 167 | institute patent litigation against any entity (including a 168 | cross-claim or counterclaim in a lawsuit) alleging that the Work 169 | or a Contribution incorporated within the Work constitutes direct 170 | or contributory patent infringement, then any patent licenses 171 | granted to You under this License for that Work shall terminate 172 | as of the date such litigation is filed. 173 | 174 | 4. Redistribution. You may reproduce and distribute copies of the 175 | Work or Derivative Works thereof in any medium, with or without 176 | modifications, and in Source or Object form, provided that You 177 | meet the following conditions: 178 | 179 | (a) You must give any other recipients of the Work or 180 | Derivative Works a copy of this License; and 181 | 182 | (b) You must cause any modified files to carry prominent notices 183 | stating that You changed the files; and 184 | 185 | (c) You must retain, in the Source form of any Derivative Works 186 | that You distribute, all copyright, patent, trademark, and 187 | attribution notices from the Source form of the Work, 188 | excluding those notices that do not pertain to any part of 189 | the Derivative Works; and 190 | 191 | (d) If the Work includes a "NOTICE" text file as part of its 192 | distribution, then any Derivative Works that You distribute must 193 | include a readable copy of the attribution notices contained 194 | within such NOTICE file, excluding those notices that do not 195 | pertain to any part of the Derivative Works, in at least one 196 | of the following places: within a NOTICE text file distributed 197 | as part of the Derivative Works; within the Source form or 198 | documentation, if provided along with the Derivative Works; or, 199 | within a display generated by the Derivative Works, if and 200 | wherever such third-party notices normally appear. The contents 201 | of the NOTICE file are for informational purposes only and 202 | do not modify the License. You may add Your own attribution 203 | notices within Derivative Works that You distribute, alongside 204 | or as an addendum to the NOTICE text from the Work, provided 205 | that such additional attribution notices cannot be construed 206 | as modifying the License. 207 | 208 | You may add Your own copyright statement to Your modifications and 209 | may provide additional or different license terms and conditions 210 | for use, reproduction, or distribution of Your modifications, or 211 | for any such Derivative Works as a whole, provided Your use, 212 | reproduction, and distribution of the Work otherwise complies with 213 | the conditions stated in this License. 214 | 215 | 5. Submission of Contributions. Unless You explicitly state otherwise, 216 | any Contribution intentionally submitted for inclusion in the Work 217 | by You to the Licensor shall be under the terms and conditions of 218 | this License, without any additional terms or conditions. 219 | Notwithstanding the above, nothing herein shall supersede or modify 220 | the terms of any separate license agreement you may have executed 221 | with Licensor regarding such Contributions. 222 | 223 | 6. Trademarks. This License does not grant permission to use the trade 224 | names, trademarks, service marks, or product names of the Licensor, 225 | except as required for reasonable and customary use in describing the 226 | origin of the Work and reproducing the content of the NOTICE file. 227 | 228 | 7. Disclaimer of Warranty. Unless required by applicable law or 229 | agreed to in writing, Licensor provides the Work (and each 230 | Contributor provides its Contributions) on an "AS IS" BASIS, 231 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 232 | implied, including, without limitation, any warranties or conditions 233 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 234 | PARTICULAR PURPOSE. You are solely responsible for determining the 235 | appropriateness of using or redistributing the Work and assume any 236 | risks associated with Your exercise of permissions under this License. 237 | 238 | 8. Limitation of Liability. In no event and under no legal theory, 239 | whether in tort (including negligence), contract, or otherwise, 240 | unless required by applicable law (such as deliberate and grossly 241 | negligent acts) or agreed to in writing, shall any Contributor be 242 | liable to You for damages, including any direct, indirect, special, 243 | incidental, or consequential damages of any character arising as a 244 | result of this License or out of the use or inability to use the 245 | Work (including but not limited to damages for loss of goodwill, 246 | work stoppage, computer failure or malfunction, or any and all 247 | other commercial damages or losses), even if such Contributor 248 | has been advised of the possibility of such damages. 249 | 250 | 9. Accepting Warranty or Additional Liability. While redistributing 251 | the Work or Derivative Works thereof, You may choose to offer, 252 | and charge a fee for, acceptance of support, warranty, indemnity, 253 | or other liability obligations and/or rights consistent with this 254 | License. However, in accepting such obligations, You may act only 255 | on Your own behalf and on Your sole responsibility, not on behalf 256 | of any other Contributor, and only if You agree to indemnify, 257 | defend, and hold each Contributor harmless for any liability 258 | incurred by, or claims asserted against, such Contributor by reason 259 | of your accepting any such warranty or additional liability. 260 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # packet, a CLI tool to manage Packet services 2 | [![Latest Version](https://img.shields.io/badge/release-v2.3.1-yellowgreen.svg)](https://github.com/ebsarr/packet/releases) [![Build Status](https://travis-ci.org/ebsarr/packet.svg?branch=master)](https://travis-ci.org/ebsarr/packet) [![Go Report Card](https://goreportcard.com/badge/github.com/ebsarr/packet)](https://goreportcard.com/report/github.com/ebsarr/packet) [![GoDoc](https://godoc.org/github.com/ebsarr/packet?status.svg)](https://godoc.org/github.com/ebsarr/packet) 3 | 4 | packet is a CLI tool to manage [packet.net](https://www.packet.net) services. You can browse the help [here](doc/packet.md). 5 | 6 | .--~~~~~~~~~~~~~------. 7 | /--===============------\\ 8 | | |^^^^^^^^^^^^^^^| | 9 | | | | | 10 | | | > packet | | 11 | | | | | 12 | | |_______________| | 13 | | ::::| 14 | '=======================' 15 | //-"-"-"-"-"-"-"-"-"-"-\\\\ 16 | //_"_"_"_"_"_"_"_"_"_"_"_\\\\ 17 | [-------------------------] 18 | \\_________________________/ 19 | 20 | # Installation 21 | 22 | Install with `go get` 23 | ``` 24 | $ go get -u github.com/ebsarr/packet 25 | ``` 26 | `packet` executable will be installed in `$GOPATH/bin` 27 |
28 |
29 | You can also run it in a docker container: 30 | ``` 31 | $ docker run -it ebsarr/packet bash 32 | ``` 33 | 34 | Try the help 35 | ``` 36 | $ packet -h 37 | CLI tool to manage packet.net services 38 | 39 | Usage: 40 | packet [flags] 41 | packet [command] 42 | 43 | Available Commands: 44 | admin Manage projects, ssh keys, etc... 45 | baremetal Manage server devices. 46 | network Manage packet network services 47 | storage Manage your storages 48 | 49 | Flags: 50 | -k, --key string API key 51 | -p, --profile string Profile name (default "default") 52 | -v, --version Show version and exit 53 | 54 | Use "packet [command] --help" for more information about a command. 55 | ``` 56 | 57 | # Getting started 58 | 59 | ## Configure your API key by adding a profile 60 | Command syntax: `packet admin add-profile` 61 | ``` 62 | $ packet admin add-profile 63 | Enter your API key [ *****y7wi ]: 64 | Enter your default project ID [ ]: 65 | ``` 66 | This command will add a profile named "default". 67 |
68 | **NOTE:** Without your API key configured, you'll need to specify it in every command in the form: `packet --key `. You can also optionnaly configure a default project ID. 69 | 70 | If you have multiple accounts, or if you are working on multiple projects, you can set profiles to make it easy to switch between accounts or projects. After setting multiple profiles, you can use `-p` or `--profile` option to switch between accounts and projects. 71 | 72 | ### Setting a profile 73 | Here I'm creating a new profile named `ebsarr` 74 | ``` 75 | $ packet admin add-profile -n ebsarr 76 | Enter your API key [ *****y7wi ]: 77 | Enter your default project ID [ ]: 78 | ``` 79 | Without the `-n` switch, the `add-profile` command sets up a profile named "default". You can view your profiles with the `list-profiles` command: 80 | ``` 81 | $ packet admin list-profiles 82 | NAME APIKEY DEFAULT PROJECT 83 | ---- ------ --------------- 84 | default XMiR---------------------------- 13935598-d08c-4bd8------------------ 85 | ebsarr XMiR---------------------------- e30d25da-728d-47fe------------------ 86 | ``` 87 | Now I can switch easily between projects when running the `packet` command: 88 | ``` 89 | $ packet -p ebsarr baremetal list-devices 90 | [] 91 | ``` 92 | Without the `-p` option, the default profile will be used: 93 | ``` 94 | $ packet baremetal list-devices 95 | [ 96 | { 97 | "id": "69148e7c-44e1-4b4a-ac1a-f9e08b552fe8", 98 | "href": "/devices/69148e7c-44e1-4b4a-ac1a-f9e08b552fe8", 99 | "hostname": "ebsarrtest01", 100 | "state": "active", 101 | "created_at": "2016-07-15T07:16:28Z", 102 | "updated_at": "2016-07-15T07:31:27Z", 103 | "billing_cycle": "hourly", 104 | "ip_addresses": [ 105 | ... 106 | ``` 107 | 108 | # Available commands 109 | 110 | ## `packet admin` : project management 111 | 112 | Syntax: `packet admin [subcommand]` 113 | 114 | |Subcommand | Description | 115 | |-----------|-------------| 116 | | `add-profile` | Set default configs for the packet cli | 117 | | `create-project` | Create a new project | 118 | | `create-sshkey` | Configure a new SSH key | 119 | | `delete-profile` | Delete a profile | 120 | | `delete-project` | Delete a project | 121 | | `delete-sshkey` | Delete SSH key associated with the given ID | 122 | | `list-facilities` | View a list of facilities(packet DCs) | 123 | | `list-os` | View available operating systems | 124 | | `list-plans` | View available plans | 125 | | `list-orgs` | List organizations associated to user | 126 | | `list-org` | List organization by ID | 127 | | `create-org` | Create a new organization | 128 | | `update-org` | update a organization | 129 | | `delete-org` | Delete organization by ID | 130 | | `list-payment-methods` | List payment methods by organization ID | 131 | | `list-profiles` | List configured profiles | 132 | | `list-project` | Retrieve a project by ID | 133 | | `list-project-events` | View events by project ID | 134 | | `list-projects` | Retrieve all projects | 135 | | `list-sshkey` | View configured SSH key associated with the given ID | 136 | | `list-sshkeys` | View all configured SSH keys | 137 | | `spot-prices` | View spot market prices. For more details on the Packet spot market, see the [Packet spot market documentation](https://help.packet.net/technical/deployment-options/spot-market). | 138 | | `update-project` | Update a project | 139 | | `update-sshkey` | Update a SSH key: change the key or its label | 140 | 141 | ## `packet baremetal`: Manage server devices 142 | 143 | Syntax: `packet baremetal [subcommand]` 144 | 145 | |Subcommand | Description | 146 | |-----------|-------------| 147 | | `create-device` | Create a new device | 148 | | `delete-device` | Delete a device | 149 | | `list-device` | Retrieve a device | 150 | | `list-devices` | Retrieve all devices in a project | 151 | | `list-events` | View events by device ID | 152 | | `lock-device` | Lock a device | 153 | | `poweroff-device` | Power off a device | 154 | | `poweron-device` | Power on a device | 155 | | `reboot-device` | Reboot a device | 156 | | `unlock-device` | Unlock a device | 157 | | `update-device` | Update a device | 158 | 159 | ## `packet network`: Manage packet network services 160 | 161 | Syntax: `packet network [subcommand]` 162 | 163 | |Subcommand | Description | 164 | |-----------|-------------| 165 | | `assign-ip` | Assign IP address to a device by ID | 166 | | `list-ip` | Retrieve IP address by ID | 167 | | `list-ip-reservation` | Retrieve a single IP reservation object by ID | 168 | | `list-ip-reservations` | Retrieve IP resevations for a single project | 169 | | `remove-ip-reservation` | Remove IP reservation | 170 | | `request-more-ip-reservations` | Request more IP space | 171 | | `unassign-ip` | Unassign IP address from a device | 172 | 173 | ## `packet storage`: manage your storages 174 | 175 | Syntax: `package storage [subcommand]` 176 |
177 | Some of the snapshot related commands may not make sense. I will revisit the API and correct this on the next update. 178 | 179 | |Subcommand | Description | 180 | |-----------|-------------| 181 | | `attach-volume` | Attach a volume to a device | 182 | | `clone-volume` | Clone a volume or snapshot into a new volume | 183 | | `create-snapshot` | Create a snapshot of your volume | 184 | | `create-snapshot-policy` | Create a snapshot policy | 185 | | `create-volume` | Create a volume | 186 | | `delete-snapshot` | Delete a snapshot of your volume | 187 | | `delete-snapshot-policy` | Delete a snapshot policy | 188 | | `delete-volume` | Delete storage | 189 | | `detach-volume` | Detach a volume from a device | 190 | | `list-snapshots` | View a list of the current volume’s snapshots | 191 | | `list-volume` | Retrieve a volume by ID | 192 | | `list-volume-events` | View a list of the current volume's events | 193 | | `list-volumes` | Retrieve all volumes | 194 | | `restore-volume` | Restore a volume to the given snapshot | 195 | | `update-snapshot-policy` | Update a snapshot policy | 196 | | `update-volume` | Update a volume | 197 | 198 | ## For more help 199 | Type `packet -h` in your console or browse the help [here](doc/packet.md) to view command options. 200 | 201 | ## License 202 | [![MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) 203 | 204 | ## Changelog 205 | 206 | | Version | Description | 207 | |---------|-------------| 208 | | **2.3.1** | Allow creating volumes without a snapshot policy by passing `--count 0` | 209 | | **2.3** | Added support for the "organization" API | 210 | | | Support pagination for packet baremetal list-devices | 211 | | | ~~Install with homebrew on macOS~~ | 212 | | **2.2.2** | Fixed a bug that blows away all tags on device updates | 213 | | | Added `--tags` flag(not mandatory) to `create-device` and `update-device` commands | 214 | | **2.2.1** | Fixed compilation issue that emerged with the updated Packet API | 215 | | **2.2** | "update-device" command added; more options for "create-device" command | 216 | | **2.1.3** | Fixed an issue that emerged with the updated Packet API | 217 | | **2.1.2** | Fixed an issue that emerged with the updated Packet API | 218 | | **2.1.1** | Bug fix around profile configuration. Now you can use `--name` or `-n` to configure and name a profile | 219 | | **2.1** | Add support for spot market | 220 | | **2.0** | Changed command structure, many bugs fixed| 221 | | **1.3** | Can now delete profiles | 222 | | **1.2** | Added profile support: use `--profile` option to switch between profiles | 223 | | | `ssh` command now reads keys from files, use `--file` instead of `ssh-key` to read from files. | 224 | | **1.1** | Added support for userdata | 225 | | **1.0** | First version | 226 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /archive/packet-2.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ebsarr/packet/c4324ae798c8bb6627bd27e4eaa971798d3ddbbe/archive/packet-2.3.tar.gz -------------------------------------------------------------------------------- /cmd/admin.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | // adminCmd represents the admin command 11 | var adminCmd = &cobra.Command{ 12 | Use: "admin", 13 | Short: "Manage projects, ssh keys, etc...", 14 | } 15 | 16 | // Organizations command 17 | 18 | var listOrganizationsCmd = &cobra.Command{ 19 | Use: "list-orgs", 20 | Short: "List organizations associated to user", 21 | RunE: func(cmd *cobra.Command, args []string) error { 22 | err := ListOrganizations() 23 | return err 24 | }, 25 | } 26 | 27 | var listOrganizationCmd = &cobra.Command{ 28 | Use: "list-org", 29 | Short: "List organization by ID", 30 | RunE: func(cmd *cobra.Command, args []string) error { 31 | orgID := cmd.Flag("org-id").Value.String() 32 | err := ListOrganization(orgID) 33 | return err 34 | }, 35 | } 36 | 37 | var createOrganizationCmd = &cobra.Command{ 38 | Use: "create-org", 39 | Short: "Create a new organization", 40 | RunE: func(cmd *cobra.Command, args []string) error { 41 | name := cmd.Flag("name").Value.String() 42 | description := cmd.Flag("description").Value.String() 43 | website := cmd.Flag("website").Value.String() 44 | twitter := cmd.Flag("twitter").Value.String() 45 | logo := cmd.Flag("logo").Value.String() 46 | err := CreateOrganization(name, description, website, twitter, logo) 47 | return err 48 | }, 49 | } 50 | 51 | var updateOrganizationCmd = &cobra.Command{ 52 | Use: "update-org", 53 | Short: "update a organization", 54 | RunE: func(cmd *cobra.Command, args []string) error { 55 | orgID := cmd.Flag("org-id").Value.String() 56 | name := cmd.Flag("name").Value.String() 57 | description := cmd.Flag("description").Value.String() 58 | website := cmd.Flag("website").Value.String() 59 | twitter := cmd.Flag("twitter").Value.String() 60 | logo := cmd.Flag("logo").Value.String() 61 | err := UpdateOrganization(orgID, name, description, website, twitter, logo) 62 | return err 63 | }, 64 | } 65 | 66 | var deleteOrganizationCmd = &cobra.Command{ 67 | Use: "delete-org", 68 | Short: "Delete organization by ID", 69 | RunE: func(cmd *cobra.Command, args []string) error { 70 | orgID := cmd.Flag("org-id").Value.String() 71 | err := DeleteOrganization(orgID) 72 | return err 73 | }, 74 | } 75 | 76 | var listPaymentMethodsCmd = &cobra.Command{ 77 | Use: "list-payment-methods", 78 | Short: "List payment methods by organization ID", 79 | RunE: func(cmd *cobra.Command, args []string) error { 80 | orgID := cmd.Flag("org-id").Value.String() 81 | err := ListPaymentMethods(orgID) 82 | return err 83 | }, 84 | } 85 | 86 | // Profile commands 87 | 88 | // addProfileCmd represents the configure command 89 | var addProfileCmd = &cobra.Command{ 90 | Use: "add-profile", 91 | Short: "Set default configs for the packet cli.", 92 | Long: `Set default configs for the packet cli. 93 | 94 | The following configurations are supported: 95 | - default API key 96 | This default key will be used if "--key" flag is missing in command. 97 | - default project ID 98 | This ID will be used if "--project-id" flag is missing in command.`, 99 | RunE: func(cmd *cobra.Command, args []string) error { 100 | profile := cmd.Flag("name").Value.String() 101 | if profile == "" { 102 | profile = "default" 103 | } 104 | err := Configure(profile) 105 | return err 106 | }, 107 | } 108 | 109 | // list-profsCmd represents the list-profs command 110 | var listProfilesCmd = &cobra.Command{ 111 | Use: "list-profiles", 112 | Short: "List configured profiles", 113 | Run: func(cmd *cobra.Command, args []string) { 114 | name := cmd.Flag("name").Value.String() 115 | fmt.Printf("%-10s\t%-32s\t%s\n", "NAME", "APIKEY", "DEFAULT PROJECT") 116 | fmt.Printf("%-10s\t%-32s\t%s\n", "----", "------", "---------------") 117 | confs, _ := ReadConfigs() 118 | if name != "" { 119 | if conf, found := confs.Profiles[name]; found { 120 | fmt.Printf("%-10s\t%s\n", name, conf) 121 | } 122 | } 123 | if confs != nil { 124 | for profile, conf := range confs.Profiles { 125 | fmt.Printf("%-10s\t%s\n", profile, conf) 126 | } 127 | } 128 | }, 129 | } 130 | 131 | var deleteProfileCmd = &cobra.Command{ 132 | Use: "delete-profile", 133 | Short: "Delete a profile", 134 | Run: func(cmd *cobra.Command, args []string) { 135 | name := cmd.Flag("name").Value.String() 136 | confs, _ := ReadConfigs() 137 | if name != "" { 138 | if _, ok := confs.Profiles[name]; ok { 139 | delete(confs.Profiles, name) 140 | writeConfigFile(confs) 141 | } 142 | } 143 | }, 144 | } 145 | 146 | // Project commands 147 | 148 | var listProjectsCmd = &cobra.Command{ 149 | Use: "list-projects", 150 | Short: "Retrieve all projects", 151 | RunE: func(cmd *cobra.Command, args []string) error { 152 | err := ListProjects() 153 | return err 154 | }, 155 | } 156 | 157 | var listProjectCmd = &cobra.Command{ 158 | Use: "list-project", 159 | Short: "Retrieve a project by ID", 160 | RunE: func(cmd *cobra.Command, args []string) error { 161 | projectID := GetProjectID(cmd) 162 | err := ListProject(projectID) 163 | return err 164 | }, 165 | } 166 | 167 | var createProjectCmd = &cobra.Command{ 168 | Use: "create-project", 169 | Short: "Create a new project", 170 | RunE: func(cmd *cobra.Command, args []string) error { 171 | orgID := cmd.Flag("org-id").Value.String() 172 | name := cmd.Flag("name").Value.String() 173 | paymentID := cmd.Flag("payment-id").Value.String() 174 | err := CreateProject(orgID, name, paymentID) 175 | return err 176 | }, 177 | } 178 | 179 | var deleteProjectCmd = &cobra.Command{ 180 | Use: "delete-project", 181 | Short: "Delete a project", 182 | RunE: func(cmd *cobra.Command, args []string) error { 183 | projectID := GetProjectID(cmd) 184 | err := DeleteProject(projectID) 185 | return err 186 | }, 187 | } 188 | 189 | var updateProjectCmd = &cobra.Command{ 190 | Use: "update-project", 191 | Short: "Update a project", 192 | RunE: func(cmd *cobra.Command, args []string) error { 193 | projectID := GetProjectID(cmd) 194 | name := cmd.Flag("name").Value.String() 195 | paymentID := cmd.Flag("payment-id").Value.String() 196 | err := UpdateProject(projectID, name, paymentID) 197 | return err 198 | }, 199 | } 200 | 201 | var listProjectEventsCmd = &cobra.Command{ 202 | Use: "list-project-events", 203 | Short: "View events by project ID", 204 | RunE: func(cmd *cobra.Command, args []string) error { 205 | projectID := GetProjectID(cmd) 206 | err := ListProjectEvents(projectID) 207 | return err 208 | }, 209 | } 210 | 211 | // ssh key management commands 212 | 213 | var listSSHKeysCmd = &cobra.Command{ 214 | Use: "list-sshkeys", 215 | Short: "View all configured SSH keys", 216 | RunE: func(cmd *cobra.Command, args []string) error { 217 | err := ListSSHKeys() 218 | return err 219 | }, 220 | } 221 | 222 | var listSSHKeyCmd = &cobra.Command{ 223 | Use: "list-sshkey", 224 | Short: "View configured SSH key associated with the given ID.", 225 | RunE: func(cmd *cobra.Command, args []string) error { 226 | sshKeyID := cmd.Flag("key-id").Value.String() 227 | err := ListSSHKey(sshKeyID) 228 | return err 229 | }, 230 | } 231 | 232 | var createSSHKeyCmd = &cobra.Command{ 233 | Use: "create-sshkey", 234 | Short: "Configure a new SSH key", 235 | RunE: func(cmd *cobra.Command, args []string) error { 236 | keyFile := cmd.Flag("file").Value.String() 237 | key, err := ioutil.ReadFile(keyFile) 238 | if err != nil { 239 | return err 240 | } 241 | label := cmd.Flag("label").Value.String() 242 | err = CreateSSHKey(label, string(key)) 243 | return err 244 | }, 245 | } 246 | 247 | var deleteSSHKeyCmd = &cobra.Command{ 248 | Use: "delete-sshkey", 249 | Short: "Delete SSH key associated with the given ID.", 250 | RunE: func(cmd *cobra.Command, args []string) error { 251 | sshKeyID := cmd.Flag("key-id").Value.String() 252 | err := DeleteSSHKey(sshKeyID) 253 | return err 254 | }, 255 | } 256 | 257 | var updateSSHKeyCmd = &cobra.Command{ 258 | Use: "update-sshkey", 259 | Short: "Update a SSH key: change the key or its label", 260 | RunE: func(cmd *cobra.Command, args []string) error { 261 | sshKeyID := cmd.Flag("key-id").Value.String() 262 | keyFile := cmd.Flag("file").Value.String() 263 | key, err := ioutil.ReadFile(keyFile) 264 | if err != nil { 265 | return err 266 | } 267 | label := cmd.Flag("label").Value.String() 268 | err = UpdateSSHKey(sshKeyID, label, string(key)) 269 | return err 270 | }, 271 | } 272 | 273 | // listing os command 274 | 275 | // listOSCmd represents the OS command 276 | var listOSCmd = &cobra.Command{ 277 | Use: "list-os", 278 | Short: "View available operating systems", 279 | RunE: func(cmd *cobra.Command, args []string) error { 280 | err := ListOS() 281 | return err 282 | }, 283 | } 284 | 285 | // Facilities 286 | 287 | // listFacilitiesCmd represents the list-facilities command 288 | var listFacilitiesCmd = &cobra.Command{ 289 | Use: "list-facilities", 290 | Short: "View a list of facilities(packet DCs)", 291 | RunE: func(cmd *cobra.Command, args []string) error { 292 | err := ListFacilities() 293 | return err 294 | }, 295 | } 296 | 297 | // Plans 298 | 299 | // planCmd represents the plan command 300 | var listPlansCmd = &cobra.Command{ 301 | Use: "list-plans", 302 | Short: "View available plans.", 303 | RunE: func(cmd *cobra.Command, args []string) error { 304 | err := ListPlans() 305 | return err 306 | }, 307 | } 308 | 309 | // Spot market 310 | 311 | // spotPricesCmd represents the spot-prices command 312 | var spotPricesCmd = &cobra.Command{ 313 | Use: "spot-prices", 314 | Short: "View spot market prices", 315 | RunE: func(cmd *cobra.Command, args []string) error { 316 | err := SpotMarketPrices() 317 | return err 318 | }, 319 | } 320 | 321 | func init() { 322 | adminCmd.AddCommand(addProfileCmd, listProfilesCmd, deleteProfileCmd, listProjectsCmd, listProjectCmd, createProjectCmd, updateProjectCmd, deleteProjectCmd, listProjectEventsCmd, listSSHKeysCmd, listSSHKeyCmd, createSSHKeyCmd, deleteSSHKeyCmd, updateSSHKeyCmd, listOSCmd, listFacilitiesCmd, listPlansCmd, spotPricesCmd, listOrganizationsCmd, listOrganizationCmd, createOrganizationCmd, updateOrganizationCmd, deleteOrganizationCmd, listPaymentMethodsCmd) 323 | RootCmd.AddCommand(adminCmd) 324 | 325 | // Flags for organization related commands 326 | listOrganizationCmd.Flags().String("org-id", "", "Organization ID") 327 | createOrganizationCmd.Flags().String("name", "", "Name") 328 | createOrganizationCmd.Flags().String("description", "", "Description") 329 | createOrganizationCmd.Flags().String("website", "", "Website URL") 330 | createOrganizationCmd.Flags().String("twitter", "", "Twitter URL") 331 | createOrganizationCmd.Flags().String("logo", "", "Logo") 332 | updateOrganizationCmd.Flags().String("org-id", "", "Organization ID") 333 | updateOrganizationCmd.Flags().String("name", "", "Name") 334 | updateOrganizationCmd.Flags().String("description", "", "Description") 335 | updateOrganizationCmd.Flags().String("website", "", "Website URL") 336 | updateOrganizationCmd.Flags().String("twitter", "", "Twitter URL") 337 | updateOrganizationCmd.Flags().String("logo", "", "Logo") 338 | deleteOrganizationCmd.Flags().String("org-id", "", "Organization ID") 339 | listPaymentMethodsCmd.Flags().String("org-id", "", "Organization ID") 340 | 341 | // Flags for profile related commands: add-profile, list-profiles, delete-profile 342 | addProfileCmd.Flags().StringP("name", "n", "", "Profile name") 343 | listProfilesCmd.Flags().StringP("name", "n", "", "Profile name") 344 | deleteProfileCmd.Flags().StringP("name", "n", "", "Profile name") 345 | 346 | // Flags for command: packet admin list-project 347 | listProjectCmd.Flags().String("project-id", "", "Project ID") 348 | 349 | // Flags for command: packet admin create-project 350 | createProjectCmd.Flags().String("org-id", "", "Organization ID") 351 | createProjectCmd.Flags().String("name", "", "Project name") 352 | createProjectCmd.Flags().String("payment-id", "", "ID of the payment method to associate to this project") 353 | 354 | // Flags for command: packet admin delete-project 355 | deleteProjectCmd.Flags().String("project-id", "", "Project ID") 356 | 357 | // Flags for command: packet admin update-project 358 | updateProjectCmd.Flags().String("project-id", "", "Project ID") 359 | updateProjectCmd.Flags().String("name", "", "Project name") 360 | updateProjectCmd.Flags().String("payment-id", "", "ID of the payment method to associate to this project") 361 | 362 | // Flags for command: packet admin list-project-events 363 | listProjectEventsCmd.Flags().String("project-id", "", "Project ID") 364 | 365 | // Flags for command: packet admin list-sshkeys 366 | listSSHKeyCmd.Flags().String("key-id", "", "SSH key ID") 367 | 368 | //Flags for command: packet admin create-sshkey 369 | createSSHKeyCmd.Flags().String("label", "", "Label to assign to the key") 370 | createSSHKeyCmd.Flags().StringP("file", "f", "", "Read public key from file.") 371 | 372 | // Flags for command: packet admin delete-sshkey 373 | deleteSSHKeyCmd.Flags().String("key-id", "", "SSH key ID") 374 | 375 | // Flags for command: packet admin update-sshkey 376 | updateSSHKeyCmd.Flags().String("key-id", "", "SSH key ID") 377 | updateSSHKeyCmd.Flags().String("label", "", "Label to assign to the key") 378 | updateSSHKeyCmd.Flags().StringP("file", "f", "", "Read public key from file.") 379 | } 380 | -------------------------------------------------------------------------------- /cmd/api.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "time" 7 | 8 | "github.com/ebsarr/packngo" 9 | 10 | "github.com/ebsarr/packet/extpackngo" 11 | ) 12 | 13 | // Ifs to Facility API 14 | 15 | // ListFacilities returns a list of packet DCs 16 | func ListFacilities() error { 17 | client, err := NewPacketClient() 18 | if err != nil { 19 | return err 20 | } 21 | 22 | facilities, _, err := client.Facilities.List() 23 | if err != nil { 24 | return err 25 | } 26 | 27 | e := MarshallAndPrint(facilities) 28 | return e 29 | } 30 | 31 | // IFs to Organizations API 32 | 33 | // ListOrganizations prints out the user's organizations 34 | func ListOrganizations() error { 35 | client, err := NewPacketClient() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | orgs, _, err := client.Organizations.List() 41 | if err != nil { 42 | return err 43 | } 44 | 45 | e := MarshallAndPrint(orgs) 46 | return e 47 | } 48 | 49 | // ListOrganization prints out a organization by id 50 | func ListOrganization(orgID string) error { 51 | client, err := NewPacketClient() 52 | if err != nil { 53 | return err 54 | } 55 | 56 | org, _, err := client.Organizations.Get(orgID) 57 | if err != nil { 58 | return err 59 | } 60 | 61 | e := MarshallAndPrint(org) 62 | return e 63 | } 64 | 65 | // CreateOrganization creates a new organization 66 | func CreateOrganization(name, description, website, twitter, logo string) error { 67 | client, err := NewPacketClient() 68 | if err != nil { 69 | return err 70 | } 71 | 72 | req := packngo.OrganizationCreateRequest{ 73 | Name: name, 74 | Description: description, 75 | Website: website, 76 | Twitter: twitter, 77 | Logo: logo, 78 | } 79 | 80 | org, _, err := client.Organizations.Create(&req) 81 | if err != nil { 82 | return err 83 | } 84 | 85 | err = MarshallAndPrint(org) 86 | return err 87 | } 88 | 89 | // UpdateOrganization updates an organization 90 | func UpdateOrganization(orgID, name, description, website, twitter, logo string) error { 91 | client, err := NewPacketClient() 92 | if err != nil { 93 | return err 94 | } 95 | 96 | req := packngo.OrganizationUpdateRequest{ 97 | Name: &name, 98 | Description: &description, 99 | Website: &website, 100 | Twitter: &twitter, 101 | Logo: &logo, 102 | } 103 | 104 | org, _, err := client.Organizations.Update(orgID, &req) 105 | if err != nil { 106 | return err 107 | } 108 | 109 | err = MarshallAndPrint(org) 110 | return err 111 | } 112 | 113 | // DeleteOrganization deletes an organization by ID 114 | func DeleteOrganization(orgID string) error { 115 | client, err := NewPacketClient() 116 | if err != nil { 117 | return err 118 | } 119 | 120 | _, err = client.Organizations.Delete(orgID) 121 | 122 | return err 123 | } 124 | 125 | // ListPaymentMethods returns PaymentMethods for an organization 126 | func ListPaymentMethods(orgID string) error { 127 | client, err := NewPacketClient() 128 | if err != nil { 129 | return err 130 | } 131 | 132 | paymentMethods, _, err := client.Organizations.ListPaymentMethods(orgID) 133 | if err != nil { 134 | return err 135 | } 136 | 137 | err = MarshallAndPrint(paymentMethods) 138 | return err 139 | } 140 | 141 | // IFs to Projects API 142 | 143 | // ListProjects prints out all projects of the user. 144 | func ListProjects() error { 145 | client, err := NewPacketClient() 146 | if err != nil { 147 | return err 148 | } 149 | 150 | projects, _, err := client.Projects.List() 151 | if err != nil { 152 | return err 153 | } 154 | 155 | e := MarshallAndPrint(projects) 156 | return e 157 | } 158 | 159 | // ListProject prints out the project associated with a given project id 160 | func ListProject(projectID string) error { 161 | client, err := NewPacketClient() 162 | if err != nil { 163 | return err 164 | } 165 | 166 | p, _, err := client.Projects.Get(projectID) 167 | if err != nil { 168 | return err 169 | } 170 | 171 | e := MarshallAndPrint(p) 172 | return e 173 | } 174 | 175 | // CreateProject creates a new project with the given project name 176 | func CreateProject(orgID, name, paymentID string) error { 177 | client, err := NewPacketClient() 178 | if err != nil { 179 | return err 180 | } 181 | 182 | req := packngo.ProjectCreateRequest{ 183 | OrganizationID: orgID, 184 | Name: name, 185 | PaymentMethodID: paymentID, 186 | } 187 | 188 | p, _, err := client.Projects.Create(&req) 189 | if err != nil { 190 | return err 191 | } 192 | 193 | e := MarshallAndPrint(p) 194 | return e 195 | } 196 | 197 | // DeleteProject deletes the project associated with the given project id. 198 | func DeleteProject(id string) error { 199 | client, err := NewPacketClient() 200 | if err != nil { 201 | return err 202 | } 203 | 204 | _, e := client.Projects.Delete(id) 205 | return e 206 | } 207 | 208 | // UpdateProject updates the project associated with the given project id either 209 | // by changing the name or the payment method. 210 | func UpdateProject(projectID, name, paymentID string) error { 211 | client, err := NewPacketClient() 212 | if err != nil { 213 | return err 214 | } 215 | 216 | req := packngo.ProjectUpdateRequest{ 217 | Name: &name, 218 | PaymentMethodID: &paymentID, 219 | } 220 | 221 | p, _, err := client.Projects.Update(projectID, &req) 222 | if err != nil { 223 | return err 224 | } 225 | 226 | e := MarshallAndPrint(p) 227 | return e 228 | } 229 | 230 | // IFs to Device, Devices API 231 | 232 | // ListDevices prints out all devices associated with the given project id. 233 | func ListDevices(projectID, includes string, page, perPage int) error { 234 | client, err := NewPacketClient() 235 | if err != nil { 236 | return err 237 | } 238 | 239 | listOptions := &packngo.ListOptions{ 240 | Page: page, 241 | PerPage: perPage, 242 | Includes: includes, 243 | } 244 | 245 | d, _, err := client.Devices.List(projectID, listOptions) 246 | if err != nil { 247 | return err 248 | } 249 | 250 | e := MarshallAndPrint(d) 251 | return e 252 | } 253 | 254 | // ListDevice prints out the device associated with the given device id. 255 | func ListDevice(deviceID string) error { 256 | client, err := NewPacketClient() 257 | if err != nil { 258 | return err 259 | } 260 | 261 | d, _, err := client.Devices.Get(deviceID) 262 | if err != nil { 263 | return err 264 | } 265 | 266 | e := MarshallAndPrint(d) 267 | return e 268 | } 269 | 270 | // CreateDevice creates a new device and optionally logs events till the device is provisionned 271 | func CreateDevice(projectID, hostname, plan, facility, operatingSystem, billingCycle, userData, ipxeScriptURL string, tags []string, spotInstance, alwaysPXE bool, spotPriceMax float64, terminationTime *time.Time, silent bool) error { 272 | client, err := NewPacketClient() 273 | if err != nil { 274 | return err 275 | } 276 | 277 | req := packngo.DeviceCreateRequest{ 278 | Hostname: hostname, 279 | Plan: plan, 280 | Facility: facility, 281 | OS: operatingSystem, 282 | BillingCycle: billingCycle, 283 | ProjectID: projectID, 284 | UserData: userData, 285 | SpotInstance: spotInstance, 286 | SpotPriceMax: spotPriceMax, 287 | Tags: tags, 288 | AlwaysPXE: alwaysPXE, 289 | IPXEScriptURL: ipxeScriptURL, 290 | } 291 | if terminationTime != nil { 292 | req.TerminationTime = &packngo.Timestamp{*terminationTime} 293 | } 294 | 295 | d, _, err := client.Devices.Create(&req) 296 | if err != nil { 297 | return err 298 | } 299 | 300 | if silent { 301 | e := MarshallAndPrint(d) 302 | return e 303 | } 304 | 305 | // print events till device is provisionned 306 | finalEvent := "Provision complete! Your device is ready to go." 307 | lastEvent := "" 308 | 309 | extclient, err := NewExtPacketClient() 310 | if err != nil { 311 | return err 312 | } 313 | 314 | fmt.Fprint(os.Stderr, "\n") 315 | fmt.Fprint(os.Stderr, "Provisioning of device successfully started...") 316 | 317 | for { 318 | events, _, err := extclient.Events.ListDeviceEvents(d.ID) 319 | if err != nil { 320 | return err 321 | } 322 | 323 | currentEventO := events[0] 324 | 325 | if currentEventO.Body != lastEvent { 326 | fmt.Fprintf(os.Stderr, " [ %s ] %s\n", currentEventO.Create, currentEventO.Body) 327 | lastEvent = currentEventO.Body 328 | } 329 | 330 | if currentEventO.Body == finalEvent { 331 | fmt.Println() 332 | break 333 | } 334 | 335 | time.Sleep(10 * time.Second) 336 | } 337 | 338 | return ListDevice(d.ID) 339 | } 340 | 341 | // DeleteDevice deletes the device associated with the given device id. 342 | func DeleteDevice(deviceID string) error { 343 | client, err := NewPacketClient() 344 | if err != nil { 345 | return err 346 | } 347 | 348 | _, e := client.Devices.Delete(deviceID) 349 | return e 350 | } 351 | 352 | // LockDevice locks the device associated with the given device id. 353 | func LockDevice(deviceID string) error { 354 | client, err := NewPacketClient() 355 | if err != nil { 356 | return err 357 | } 358 | 359 | _, e := client.Devices.Lock(deviceID) 360 | return e 361 | } 362 | 363 | // UnlockDevice unlocks the device associated with the given device id. 364 | func UnlockDevice(deviceID string) error { 365 | client, err := NewPacketClient() 366 | if err != nil { 367 | return err 368 | } 369 | 370 | _, e := client.Devices.Unlock(deviceID) 371 | return e 372 | } 373 | 374 | // PowerOnDevice powers on the device associated with the given device id. 375 | func PowerOnDevice(deviceID string) error { 376 | client, err := NewPacketClient() 377 | if err != nil { 378 | return err 379 | } 380 | 381 | _, e := client.Devices.PowerOn(deviceID) 382 | return e 383 | } 384 | 385 | // PowerOffDevice powers off the device associated with the given device id. 386 | func PowerOffDevice(deviceID string) error { 387 | client, err := NewPacketClient() 388 | if err != nil { 389 | return err 390 | } 391 | 392 | _, e := client.Devices.PowerOff(deviceID) 393 | return e 394 | } 395 | 396 | // RebootDevice reboots the device associated with the given device id. 397 | func RebootDevice(deviceID string) error { 398 | client, err := NewPacketClient() 399 | if err != nil { 400 | return err 401 | } 402 | 403 | _, e := client.Devices.Reboot(deviceID) 404 | return e 405 | } 406 | 407 | // UpdateDevice updates a device by ID. 408 | func UpdateDevice(deviceID string, hostname, description, userData, ipxeScriptURL string, tags []string, locked, alwaysPXE bool) error { 409 | client, err := NewPacketClient() 410 | if err != nil { 411 | return err 412 | } 413 | 414 | req := &packngo.DeviceUpdateRequest{ 415 | Hostname: &hostname, 416 | Description: &description, 417 | UserData: &userData, 418 | Locked: &locked, 419 | Tags: &tags, 420 | AlwaysPXE: &alwaysPXE, 421 | IPXEScriptURL: &ipxeScriptURL, 422 | } 423 | 424 | device, _, err := client.Devices.Update(deviceID, req) 425 | if err != nil { 426 | return err 427 | } 428 | 429 | MarshallAndPrint(device) 430 | return err 431 | } 432 | 433 | // IFs to Plan API 434 | 435 | // ListPlans prints out the available plans(server types). 436 | func ListPlans() error { 437 | client, err := NewPacketClient() 438 | if err != nil { 439 | return err 440 | } 441 | 442 | p, _, err := client.Plans.List() 443 | if err != nil { 444 | return err 445 | } 446 | 447 | e := MarshallAndPrint(p) 448 | return e 449 | } 450 | 451 | // IFs to OS API 452 | 453 | // ListOS prints out the available operating systems. 454 | func ListOS() error { 455 | client, err := NewPacketClient() 456 | if err != nil { 457 | return err 458 | } 459 | 460 | o, _, err := client.OperatingSystems.List() 461 | if err != nil { 462 | return err 463 | } 464 | 465 | e := MarshallAndPrint(o) 466 | return e 467 | } 468 | 469 | // IFs to SSH API 470 | 471 | // ListSSHKeys prints out all ssh keys generated by the user. 472 | func ListSSHKeys() error { 473 | client, err := NewPacketClient() 474 | if err != nil { 475 | return err 476 | } 477 | 478 | k, _, err := client.SSHKeys.List() 479 | if err != nil { 480 | return err 481 | } 482 | 483 | e := MarshallAndPrint(k) 484 | return e 485 | } 486 | 487 | // ListSSHKey prints out the ssh key associated with the given key id. 488 | func ListSSHKey(keyID string) error { 489 | client, err := NewPacketClient() 490 | if err != nil { 491 | return err 492 | } 493 | 494 | k, _, err := client.SSHKeys.Get(keyID) 495 | if err != nil { 496 | return err 497 | } 498 | 499 | e := MarshallAndPrint(k) 500 | return e 501 | } 502 | 503 | // CreateSSHKey creates a new ssh key. 504 | func CreateSSHKey(label, key string) error { 505 | client, err := NewPacketClient() 506 | if err != nil { 507 | return err 508 | } 509 | 510 | req := packngo.SSHKeyCreateRequest{ 511 | Key: key, 512 | Label: label, 513 | } 514 | 515 | k, _, err := client.SSHKeys.Create(&req) 516 | if err != nil { 517 | return err 518 | } 519 | 520 | e := MarshallAndPrint(k) 521 | return e 522 | } 523 | 524 | // DeleteSSHKey deletes the ssh key associated with the given key id. 525 | func DeleteSSHKey(keyID string) error { 526 | client, err := NewPacketClient() 527 | if err != nil { 528 | return err 529 | } 530 | 531 | _, e := client.SSHKeys.Delete(keyID) 532 | return e 533 | } 534 | 535 | // UpdateSSHKey updates the ssh key associated with the given key id. 536 | func UpdateSSHKey(keyID, label, key string) error { 537 | client, err := NewPacketClient() 538 | if err != nil { 539 | return err 540 | } 541 | 542 | req := packngo.SSHKeyUpdateRequest{ 543 | Label: &label, 544 | Key: &key, 545 | } 546 | 547 | k, _, err := client.SSHKeys.Update(keyID, &req) 548 | if err != nil { 549 | return err 550 | } 551 | 552 | e := MarshallAndPrint(k) 553 | return e 554 | } 555 | 556 | // IFs to Event API 557 | 558 | // ListDeviceEvents prints out events by device ID 559 | func ListDeviceEvents(id string) error { 560 | client, err := NewExtPacketClient() 561 | if err != nil { 562 | return err 563 | } 564 | 565 | events, _, err := client.Events.ListDeviceEvents(id) 566 | if err != nil { 567 | return err 568 | } 569 | 570 | e := MarshallAndPrint(events) 571 | return e 572 | } 573 | 574 | // ListProjectEvents prints out events by device ID 575 | func ListProjectEvents(id string) error { 576 | client, err := NewExtPacketClient() 577 | if err != nil { 578 | return err 579 | } 580 | 581 | events, _, err := client.Events.ListProjectEvents(id) 582 | if err != nil { 583 | return err 584 | } 585 | 586 | e := MarshallAndPrint(events) 587 | return e 588 | } 589 | 590 | // ListStorageEvents prints out events by device ID 591 | func ListStorageEvents(storageID string) error { 592 | client, err := NewExtPacketClient() 593 | if err != nil { 594 | return err 595 | } 596 | 597 | events, _, err := client.Events.ListStorageEvents(storageID) 598 | if err != nil { 599 | return err 600 | } 601 | 602 | e := MarshallAndPrint(events) 603 | return e 604 | } 605 | 606 | // Extention of the Device API to assign IP address 607 | 608 | // ListIPAddress prints out ip address by ID 609 | func ListIPAddress(ipAddressID string) error { 610 | client, err := NewExtPacketClient() 611 | if err != nil { 612 | return err 613 | } 614 | 615 | ip, _, err := client.IPs.Get(ipAddressID) 616 | if err != nil { 617 | return err 618 | } 619 | 620 | e := MarshallAndPrint(ip) 621 | return e 622 | } 623 | 624 | // AssignIPAddress assigns an IP address to a device by ID 625 | func AssignIPAddress(deviceID, ipAddress string) error { 626 | client, err := NewExtPacketClient() 627 | if err != nil { 628 | return err 629 | } 630 | 631 | req := extpackngo.IPAddressAssignRequest{ 632 | Address: ipAddress, 633 | } 634 | 635 | ip, _, err := client.IPs.Assign(deviceID, &req) 636 | if err != nil { 637 | return err 638 | } 639 | 640 | e := MarshallAndPrint(ip) 641 | return e 642 | } 643 | 644 | // UnAssignIPAddress unassigns and IP address from a device 645 | func UnAssignIPAddress(ipAddressID string) error { 646 | client, err := NewExtPacketClient() 647 | if err != nil { 648 | return err 649 | } 650 | 651 | _, e := client.IPs.Unassign(ipAddressID) 652 | return e 653 | } 654 | 655 | // ListIPReservations provides a list of IP resevations for a single project 656 | func ListIPReservations(projectID string) error { 657 | client, err := NewExtPacketClient() 658 | if err != nil { 659 | return err 660 | } 661 | 662 | reservations, _, err := client.IPReservations.List(projectID) 663 | if err != nil { 664 | return err 665 | } 666 | 667 | e := MarshallAndPrint(reservations) 668 | return e 669 | } 670 | 671 | // RequestMoreIPReservations requests more IP space for a project in order to have additional IP addresses to assign to devices 672 | func RequestMoreIPReservations(projectID, ipType, comments string, quantity int) error { 673 | client, err := NewExtPacketClient() 674 | if err != nil { 675 | return err 676 | } 677 | 678 | req := extpackngo.IPReservationRequest{ 679 | Type: ipType, 680 | Quantity: quantity, 681 | Comments: comments, 682 | } 683 | 684 | _, e := client.IPReservations.RequestMore(projectID, &req) 685 | return e 686 | } 687 | 688 | // ListIPReservation returns a single IP reservation object 689 | func ListIPReservation(id string) error { 690 | client, err := NewExtPacketClient() 691 | if err != nil { 692 | return err 693 | } 694 | 695 | reservation, _, err := client.IPReservations.Get(id) 696 | if err != nil { 697 | return err 698 | } 699 | 700 | e := MarshallAndPrint(reservation) 701 | return e 702 | } 703 | 704 | // RemoveIPReservation removes an IP reservation from the project 705 | func RemoveIPReservation(id string) error { 706 | client, err := NewExtPacketClient() 707 | if err != nil { 708 | return err 709 | } 710 | 711 | _, e := client.IPReservations.Remove(id) 712 | return e 713 | } 714 | 715 | // Ifs to VOLUMES API 716 | 717 | // ListStorages returns a list of the current projects’s volumes 718 | func ListStorages(projectID string) error { 719 | client, err := NewExtPacketClient() 720 | if err != nil { 721 | return err 722 | } 723 | 724 | storages, _, err := client.Storages.List(projectID) 725 | if err != nil { 726 | return err 727 | } 728 | 729 | e := MarshallAndPrint(storages) 730 | return e 731 | } 732 | 733 | // CreateStorage creates a new volume 734 | func CreateStorage(projectID, description, plan, facility, frequency string, size, count int) error { 735 | client, err := NewExtPacketClient() 736 | if err != nil { 737 | return err 738 | } 739 | 740 | // Create a snapshot policy. If `count` is 0, we shall pass an empty object 741 | snapshotPolicies := make([]*extpackngo.SnapshotPolicy, 1) 742 | if count != 0 { 743 | snapshotPolicies = append(snapshotPolicies, &extpackngo.SnapshotPolicy{ 744 | SnapshotFrequency: frequency, 745 | SnapshotCount: count}) 746 | } 747 | request := &extpackngo.StorageCreateRequest{ 748 | Description: description, 749 | Plan: plan, 750 | Size: size, 751 | Facility: facility, 752 | SnapshotPolicies: snapshotPolicies, 753 | } 754 | 755 | storage, _, err := client.Storages.Create(projectID, request) 756 | if err != nil { 757 | return err 758 | } 759 | 760 | e := MarshallAndPrint(storage) 761 | return e 762 | } 763 | 764 | // ListStorage returns a volume by ID 765 | func ListStorage(storageID string) error { 766 | client, err := NewExtPacketClient() 767 | if err != nil { 768 | return err 769 | } 770 | 771 | storage, _, err := client.Storages.Get(storageID) 772 | if err != nil { 773 | return err 774 | } 775 | 776 | e := MarshallAndPrint(storage) 777 | return e 778 | } 779 | 780 | // UpdateStorage updates a volume 781 | func UpdateStorage(storageID, description string, size int, locked bool) error { 782 | client, err := NewExtPacketClient() 783 | if err != nil { 784 | return err 785 | } 786 | 787 | request := &extpackngo.StorageUpdateRequest{ 788 | Description: description, 789 | Size: size, 790 | Locked: locked, 791 | } 792 | 793 | _, e := client.Storages.Update(storageID, request) 794 | return e 795 | } 796 | 797 | // DeleteStorage deletes a volume 798 | func DeleteStorage(storageID string) error { 799 | client, err := NewExtPacketClient() 800 | if err != nil { 801 | return err 802 | } 803 | 804 | _, e := client.Storages.Delete(storageID) 805 | return e 806 | } 807 | 808 | // CreateSnapshotPolicy creates a snapshot policy 809 | func CreateSnapshotPolicy(storageID, frequency string, count int) error { 810 | client, err := NewExtPacketClient() 811 | if err != nil { 812 | return err 813 | } 814 | 815 | request := &extpackngo.CreateSnapshotPolicyRequest{ 816 | SnapshotCount: count, 817 | SnapshotFrequency: frequency, 818 | } 819 | 820 | _, e := client.Storages.CreateSnapshotPolicy(storageID, request) 821 | return e 822 | } 823 | 824 | // UpdateSnapshotPolicy updates a snapshot policy 825 | func UpdateSnapshotPolicy(snapshotPolicyID, frequency string, count int) error { 826 | client, err := NewExtPacketClient() 827 | if err != nil { 828 | return err 829 | } 830 | 831 | request := &extpackngo.UpdateSnapshotPolicyRequest{ 832 | SnapshotCount: count, 833 | SnapshotFrequency: frequency, 834 | } 835 | 836 | _, e := client.Storages.UpdateSnapshotPolicy(snapshotPolicyID, request) 837 | return e 838 | } 839 | 840 | // DeleteSnapshotPolicy deletes a snapshot policy 841 | func DeleteSnapshotPolicy(snapshotPolicyID string) error { 842 | client, err := NewExtPacketClient() 843 | if err != nil { 844 | return err 845 | } 846 | 847 | _, e := client.Storages.DeleteSnapshotPolicy(snapshotPolicyID) 848 | return e 849 | } 850 | 851 | // ListSnapshots returns a list of the current volume’s snapshots 852 | func ListSnapshots(storageID string) error { 853 | client, err := NewExtPacketClient() 854 | if err != nil { 855 | return err 856 | } 857 | 858 | snapshots, _, err := client.Storages.ListSnapshots(storageID) 859 | if err != nil { 860 | return err 861 | } 862 | 863 | e := MarshallAndPrint(snapshots) 864 | return e 865 | } 866 | 867 | // CreateSnapshot creates a new snapshot of your volume 868 | func CreateSnapshot(storageID string) error { 869 | client, err := NewExtPacketClient() 870 | if err != nil { 871 | return err 872 | } 873 | 874 | request := &extpackngo.CreateSnapShotRequest{} 875 | 876 | _, e := client.Storages.CreateSnapshot(storageID, request) 877 | return e 878 | } 879 | 880 | // DeleteSnapshot deletes a snapshot 881 | func DeleteSnapshot(storageID, snapshotID string) error { 882 | client, err := NewExtPacketClient() 883 | if err != nil { 884 | return err 885 | } 886 | 887 | _, e := client.Storages.DeleteSnapshot(storageID, snapshotID) 888 | return e 889 | } 890 | 891 | // AttachStorage attaches your volume to a device 892 | func AttachStorage(storageID, deviceID string) error { 893 | client, err := NewExtPacketClient() 894 | if err != nil { 895 | return err 896 | } 897 | 898 | request := &extpackngo.AttachStorageRequest{ 899 | DeviceID: deviceID, 900 | } 901 | 902 | _, e := client.Storages.Attach(storageID, request) 903 | return e 904 | } 905 | 906 | // DetachStorage detaches your volume from a device 907 | func DetachStorage(attachmentID string) error { 908 | client, err := NewExtPacketClient() 909 | if err != nil { 910 | return err 911 | } 912 | 913 | _, e := client.Storages.Detach(attachmentID) 914 | return e 915 | } 916 | 917 | // RestoreStorage restores a volume to the given snapshot 918 | func RestoreStorage(storageID, restorePoint string) error { 919 | client, err := NewExtPacketClient() 920 | if err != nil { 921 | return err 922 | } 923 | 924 | request := &extpackngo.RestoreVolumeRequest{ 925 | RestorePoint: restorePoint, 926 | } 927 | 928 | _, e := client.Storages.Restore(storageID, request) 929 | return e 930 | } 931 | 932 | // CloneStorage clones your volume or snapshot into a new volume. To clone the volume, send an empty body. To promote a volume snapshot into a new volume, include the snapshot_timestamp attribute in the request body. 933 | func CloneStorage(storageID, snapshotTimestamp string) error { 934 | client, err := NewExtPacketClient() 935 | if err != nil { 936 | return err 937 | } 938 | 939 | request := &extpackngo.CloneVolumeRequest{ 940 | SnapshotTimestamp: snapshotTimestamp, 941 | } 942 | 943 | _, e := client.Storages.Clone(storageID, request) 944 | return e 945 | } 946 | 947 | // Ifs for SpotMarket 948 | 949 | // SpotMarketPrices shows the spot market prices 950 | func SpotMarketPrices() error { 951 | client, err := NewPacketClient() 952 | if err != nil { 953 | return err 954 | } 955 | 956 | spotMarketPrices, _, err := client.SpotMarket.Prices() 957 | if err != nil { 958 | return err 959 | } 960 | 961 | err = MarshallAndPrint(spotMarketPrices) 962 | return err 963 | } 964 | -------------------------------------------------------------------------------- /cmd/baremetal.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "errors" 5 | "io/ioutil" 6 | "time" 7 | 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | var silent, spotInstance, alwaysPXE bool 12 | var spotPriceMax float64 13 | var tags []string 14 | 15 | // baremetalCmd represents t&he baremetal command 16 | var baremetalCmd = &cobra.Command{ 17 | Use: "baremetal", 18 | Short: "Manage server devices.", 19 | // Long: ``, 20 | } 21 | 22 | var listDevicesCmd = &cobra.Command{ 23 | Use: "list-devices", 24 | Short: "Retrieve all devices in a project", 25 | RunE: func(cmd *cobra.Command, args []string) error { 26 | projectID := GetProjectID(cmd) 27 | page, err := cmd.Flags().GetInt("page") 28 | if err != nil { 29 | return err 30 | } 31 | perPage, err := cmd.Flags().GetInt("per-page") 32 | if err != nil { 33 | return err 34 | } 35 | includes := cmd.Flag("includes").Value.String() 36 | err = ListDevices(projectID, includes, page, perPage) 37 | return err 38 | }, 39 | } 40 | 41 | var listDeviceCmd = &cobra.Command{ 42 | Use: "list-device", 43 | Short: "Retrieve a device", 44 | RunE: func(cmd *cobra.Command, args []string) error { 45 | deviceID := cmd.Flag("device-id").Value.String() 46 | err := ListDevice(deviceID) 47 | return err 48 | }, 49 | } 50 | 51 | var createDeviceCmd = &cobra.Command{ 52 | Use: "create-device", 53 | Short: "Create a new device", 54 | RunE: func(cmd *cobra.Command, args []string) error { 55 | var userData string 56 | projectID := GetProjectID(cmd) 57 | hostname := cmd.Flag("hostname").Value.String() 58 | plan := cmd.Flag("plan").Value.String() 59 | facility := cmd.Flag("facility").Value.String() 60 | osType := cmd.Flag("os-type").Value.String() 61 | billing := cmd.Flag("billing").Value.String() 62 | ipxeScriptURL := cmd.Flag("ipxe-script-url").Value.String() 63 | 64 | var terminationTime *time.Time = nil 65 | terminationInt, err := cmd.Flags().GetInt64("termination-time") 66 | if err != nil { 67 | return err 68 | } 69 | if terminationInt != 0 { 70 | t := time.Unix(terminationInt, 0) 71 | terminationTime = &t 72 | } 73 | 74 | // for getting userdata, --userfile has higher priority. 75 | userData = cmd.Flag("userdata").Value.String() 76 | userDataFile := cmd.Flag("userfile").Value.String() 77 | if userDataFile == "" { 78 | userDataFile = cmd.Flag("file").Value.String() 79 | } 80 | if userDataFile != "" { 81 | data, err := ioutil.ReadFile(userDataFile) 82 | if err != nil { 83 | return err 84 | } 85 | userData = string(data) 86 | } 87 | 88 | return CreateDevice(projectID, hostname, plan, facility, osType, billing, userData, ipxeScriptURL, tags, spotInstance, alwaysPXE, spotPriceMax, terminationTime, silent) 89 | }, 90 | } 91 | 92 | var updateDeviceCmd = &cobra.Command{ 93 | Use: "update-device", 94 | Short: "Update a device", 95 | RunE: func(cmd *cobra.Command, args []string) error { 96 | var userData, userDataFile, hostname, description, ipxeScriptURL string 97 | var locked, alwaysPXE bool 98 | // var userDataFile string 99 | deviceID := cmd.Flag("device-id").Value.String() 100 | 101 | // Retrieve current device info 102 | client, err := NewPacketClient() 103 | if err != nil { 104 | return err 105 | } 106 | d, _, err := client.Devices.Get(deviceID) 107 | if err != nil { 108 | return err 109 | } 110 | 111 | if cmd.Flag("hostname").Changed { 112 | hostname = cmd.Flag("hostname").Value.String() 113 | } else { 114 | hostname = d.Hostname 115 | } 116 | 117 | if cmd.Flag("description").Changed { 118 | description = cmd.Flag("description").Value.String() 119 | } 120 | 121 | alwaysPXEFlag := cmd.Flag("always-pxe").Value.String() 122 | if alwaysPXEFlag != "" { 123 | if alwaysPXEFlag == "true" { 124 | alwaysPXE = true 125 | } else if alwaysPXEFlag == "false" { 126 | alwaysPXE = false 127 | } else { 128 | return errors.New("Bad value; --always-pxe only accepts true || false") 129 | } 130 | } else { 131 | alwaysPXE = d.AlwaysPXE 132 | } 133 | 134 | if cmd.Flag("ipxe-script-url").Changed { 135 | ipxeScriptURL = cmd.Flag("ipxe-script-url").Value.String() 136 | } else { 137 | ipxeScriptURL = d.IPXEScriptURL 138 | } 139 | 140 | lockFlag := cmd.Flag("lock").Value.String() 141 | if lockFlag != "" { 142 | if lockFlag == "true" { 143 | locked = true 144 | } else if lockFlag == "false" { 145 | locked = false 146 | } else { 147 | return errors.New("Bad value; --lock only accepts true || false") 148 | } 149 | } else { 150 | locked = d.Locked 151 | } 152 | 153 | // for getting userdata, --userfile has higher priority. 154 | if !cmd.Flag("userfile").Changed { 155 | if cmd.Flag("userdata").Changed { 156 | userData = cmd.Flag("userdata").Value.String() 157 | } else { 158 | userData = d.UserData 159 | } 160 | } else { 161 | userDataFile = cmd.Flag("userfile").Value.String() 162 | data, err := ioutil.ReadFile(userDataFile) 163 | if err != nil { 164 | return err 165 | } 166 | userData = string(data) 167 | } 168 | 169 | if !cmd.Flag("tags").Changed { 170 | tags = d.Tags 171 | } 172 | 173 | err = UpdateDevice(deviceID, hostname, description, userData, ipxeScriptURL, tags, locked, alwaysPXE) 174 | return err 175 | }, 176 | } 177 | 178 | var deleteDeviceCmd = &cobra.Command{ 179 | Use: "delete-device", 180 | Short: "Delete a device", 181 | RunE: func(cmd *cobra.Command, args []string) error { 182 | deviceID := cmd.Flag("device-id").Value.String() 183 | err := DeleteDevice(deviceID) 184 | return err 185 | }, 186 | } 187 | 188 | var lockDeviceCmd = &cobra.Command{ 189 | Use: "lock-device", 190 | Short: "Lock a device", 191 | RunE: func(cmd *cobra.Command, args []string) error { 192 | deviceID := cmd.Flag("device-id").Value.String() 193 | err := LockDevice(deviceID) 194 | return err 195 | }, 196 | } 197 | 198 | var unlockDeviceCmd = &cobra.Command{ 199 | Use: "unlock-device", 200 | Short: "Unlock a device", 201 | RunE: func(cmd *cobra.Command, args []string) error { 202 | deviceID := cmd.Flag("device-id").Value.String() 203 | err := UnlockDevice(deviceID) 204 | return err 205 | }, 206 | } 207 | 208 | var powerOnDeviceCmd = &cobra.Command{ 209 | Use: "poweron-device", 210 | Short: "Power on a device", 211 | RunE: func(cmd *cobra.Command, args []string) error { 212 | deviceID := cmd.Flag("device-id").Value.String() 213 | err := PowerOnDevice(deviceID) 214 | return err 215 | }, 216 | } 217 | 218 | var powerOffDeviceCmd = &cobra.Command{ 219 | Use: "poweroff-device", 220 | Short: "Power off a device", 221 | RunE: func(cmd *cobra.Command, args []string) error { 222 | deviceID := cmd.Flag("device-id").Value.String() 223 | err := PowerOffDevice(deviceID) 224 | return err 225 | }, 226 | } 227 | 228 | var rebootDeviceCmd = &cobra.Command{ 229 | Use: "reboot-device", 230 | Short: "Reboot a device", 231 | RunE: func(cmd *cobra.Command, args []string) error { 232 | deviceID := cmd.Flag("device-id").Value.String() 233 | err := RebootDevice(deviceID) 234 | return err 235 | }, 236 | } 237 | 238 | var listDeviceEventsCmd = &cobra.Command{ 239 | Use: "list-events", 240 | Short: "View events by device ID", 241 | RunE: func(cmd *cobra.Command, args []string) error { 242 | deviceID := cmd.Flag("device-id").Value.String() 243 | err := ListDeviceEvents(deviceID) 244 | return err 245 | }, 246 | } 247 | 248 | func init() { 249 | // subcommands 250 | baremetalCmd.AddCommand(listDevicesCmd, listDeviceCmd, createDeviceCmd, updateDeviceCmd, deleteDeviceCmd, lockDeviceCmd, unlockDeviceCmd, powerOnDeviceCmd, powerOffDeviceCmd, rebootDeviceCmd, listDeviceEventsCmd) 251 | 252 | // add to root command 253 | RootCmd.AddCommand(baremetalCmd) 254 | 255 | // Flags for command: packet baremetal list-devices 256 | listDevicesCmd.Flags().String("project-id", "", "Specify the project ID.") 257 | listDevicesCmd.Flags().Int("page", 0, "For paginated result sets, page of results to retrieve") 258 | listDevicesCmd.Flags().Int("per-page", 0, "For paginated result sets, the number of results to return per page") 259 | listDevicesCmd.Flags().String("includes", "", `Specify which resources you want to return as collections instead of references. For multiple ressources, pass a comma separated string as in "resource1,resource2,resource3". Refer to the API docs(https://www.packet.net/developers/api/common-parameters/) for more info about the "include" parameter.`) 260 | 261 | // Flags for command: packet baremetal list-device 262 | listDeviceCmd.Flags().String("device-id", "", "Specify ID of device to display.") 263 | 264 | // Flags for command: packet baremetal create 265 | createDeviceCmd.Flags().String("project-id", "", "The project ID.") 266 | createDeviceCmd.Flags().String("hostname", "", "Hostname of the device") 267 | createDeviceCmd.Flags().String("plan", "baremetal_0", "Server type to create the device") 268 | createDeviceCmd.Flags().String("facility", "", "DC location. Use \"packet admin list-facilities\" to see available facilities") 269 | createDeviceCmd.Flags().String("os-type", "centos_7", "Operating system to deploy to the server") 270 | createDeviceCmd.Flags().String("billing", "hourly", "Choose \"hourly\" or \"monthly\" billing") 271 | createDeviceCmd.Flags().StringP("file", "f", "", "Read userdata from a file. This option works but is deprecated; use \"--userfile\" instead") 272 | createDeviceCmd.Flags().String("userfile", "", "Read userdata from a `[file]`") 273 | createDeviceCmd.Flags().String("userdata", "", "userdata string. This options will be disgarded if \"--userfile\" is present") 274 | createDeviceCmd.Flags().BoolVarP(&silent, "silent", "s", false, "Omit provisioning logs") 275 | createDeviceCmd.Flags().BoolVarP(&spotInstance, "spot-instance", "", false, "Create as a spot instance") 276 | createDeviceCmd.Flags().BoolVarP(&alwaysPXE, "always-pxe", "", false, "Set PXE boot to `true`") 277 | createDeviceCmd.Flags().String("ipxe-script-url", "", "Script URL") 278 | createDeviceCmd.Flags().Int64("termination-time", 0, "Time to terminate instance (Unix timestamp)") 279 | createDeviceCmd.Flags().Float64VarP(&spotPriceMax, "spot-price-max", "", 0.0, "Spot market price bid") 280 | createDeviceCmd.Flags().StringSliceVar(&tags, "tags", []string{}, "a list of comma separated tags") 281 | 282 | // Flags for command: packet baremetal update-device 283 | updateDeviceCmd.Flags().String("device-id", "", "Device ID") 284 | updateDeviceCmd.Flags().String("hostname", "", "Hostname of the device") 285 | updateDeviceCmd.Flags().String("description", "", "Description") 286 | updateDeviceCmd.Flags().String("ipxe-script-url", "", "Script URL") 287 | updateDeviceCmd.Flags().String("userfile", "", "Read userdata from a `[file]`") 288 | updateDeviceCmd.Flags().String("userdata", "", "userdata string. This options will be disgarded if \"--userfile\" is present") 289 | updateDeviceCmd.Flags().String("always-pxe", "", "PXE boot: [true || false]") 290 | updateDeviceCmd.Flags().String("lock", "", "Lock device: [true || false]") 291 | updateDeviceCmd.Flags().StringSliceVar(&tags, "tags", []string{}, "a list of comma separated tags") 292 | 293 | // Flags for other device commands that require the device ID. 294 | deleteDeviceCmd.Flags().String("device-id", "", "Device ID") 295 | lockDeviceCmd.Flags().String("device-id", "", "Device ID") 296 | unlockDeviceCmd.Flags().String("device-id", "", "Device ID") 297 | powerOnDeviceCmd.Flags().String("device-id", "", "Device ID") 298 | powerOffDeviceCmd.Flags().String("device-id", "", "Device ID") 299 | rebootDeviceCmd.Flags().String("device-id", "", "Device ID") 300 | listDeviceEventsCmd.Flags().String("device-id", "", "Device ID") 301 | 302 | } 303 | -------------------------------------------------------------------------------- /cmd/client.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/ebsarr/packngo" 5 | 6 | "github.com/ebsarr/packet/extpackngo" 7 | ) 8 | 9 | // NewPacketClient returns a *packngo.Client ready for API calls 10 | func NewPacketClient() (*packngo.Client, error) { 11 | k, err := GetAPIKey() 12 | if err != nil { 13 | return nil, err 14 | } 15 | 16 | packetClient := packngo.NewClientWithAuth("", k, nil) 17 | return packetClient, nil 18 | } 19 | 20 | // NewExtPacketClient returns a *extpackngo.Client ready for API calls 21 | func NewExtPacketClient() (*extpackngo.Client, error) { 22 | k, err := GetAPIKey() 23 | if err != nil { 24 | return nil, err 25 | } 26 | 27 | packetClient := extpackngo.NewClient("", k, nil) 28 | return packetClient, nil 29 | } 30 | -------------------------------------------------------------------------------- /cmd/genautocomplete.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | // genautocompleteCmd represents the genautocomplete command 8 | var genautocompleteCmd = &cobra.Command{ 9 | Use: "genautocomplete", 10 | Short: "Generate a auto-completion script for the packet command", 11 | Hidden: true, 12 | Run: func(cmd *cobra.Command, args []string) { 13 | RootCmd.GenBashCompletionFile("packet-autocomplete.sh") 14 | }, 15 | } 16 | 17 | func init() { 18 | RootCmd.AddCommand(genautocompleteCmd) 19 | } 20 | -------------------------------------------------------------------------------- /cmd/gendoc.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | "github.com/spf13/cobra/doc" 6 | ) 7 | 8 | // gendocCmd represents the gendoc command 9 | var gendocCmd = &cobra.Command{ 10 | Use: "gendoc", 11 | Short: "Generate a markdown documentation file for this tool", 12 | Hidden: true, 13 | Run: func(cmd *cobra.Command, args []string) { 14 | doc.GenMarkdownTree(RootCmd, "./doc") 15 | }, 16 | } 17 | 18 | func init() { 19 | RootCmd.AddCommand(gendocCmd) 20 | } 21 | -------------------------------------------------------------------------------- /cmd/network.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import "github.com/spf13/cobra" 4 | 5 | // networkCmd represents the network command 6 | var networkCmd = &cobra.Command{ 7 | Use: "network", 8 | Short: "Manage packet network services", 9 | // Long: ``, 10 | } 11 | 12 | var listIPCmd = &cobra.Command{ 13 | Use: "list-ip", 14 | Short: "Retrieve IP address by ID", 15 | RunE: func(cmd *cobra.Command, args []string) error { 16 | addressID := cmd.Flag("address-id").Value.String() 17 | err := ListIPAddress(addressID) 18 | return err 19 | }, 20 | } 21 | 22 | var assignIPCmd = &cobra.Command{ 23 | Use: "assign-ip", 24 | Short: "Assign IP address to a device by ID", 25 | RunE: func(cmd *cobra.Command, args []string) error { 26 | address := cmd.Flag("address").Value.String() 27 | deviceID := cmd.Flag("device-id").Value.String() 28 | err := AssignIPAddress(deviceID, address) 29 | return err 30 | }, 31 | } 32 | 33 | var unAssignIPCmd = &cobra.Command{ 34 | Use: "unassign-ip", 35 | Short: "Unassign IP address from a device", 36 | RunE: func(cmd *cobra.Command, args []string) error { 37 | addressID := cmd.Flag("address-id").Value.String() 38 | err := UnAssignIPAddress(addressID) 39 | return err 40 | }, 41 | } 42 | 43 | var listReservationsCmd = &cobra.Command{ 44 | Use: "list-ip-reservations", 45 | Short: "Retrieve IP resevations for a single project", 46 | RunE: func(cmd *cobra.Command, args []string) error { 47 | projectID := GetProjectID(cmd) 48 | err := ListIPReservations(projectID) 49 | return err 50 | }, 51 | } 52 | 53 | var requestMoreIPReservationsCmd = &cobra.Command{ 54 | Use: "request-more-ip-reservations", 55 | Short: "Request more IP space", 56 | RunE: func(cmd *cobra.Command, args []string) error { 57 | projectID := GetProjectID(cmd) 58 | ipType := cmd.Flag("type").Value.String() 59 | quantity, err := cmd.Flags().GetInt("quantity") 60 | if err != nil { 61 | return err 62 | } 63 | comments := cmd.Flag("comments").Value.String() 64 | 65 | e := RequestMoreIPReservations(projectID, ipType, comments, quantity) 66 | return e 67 | }, 68 | } 69 | 70 | var listReservationCmd = &cobra.Command{ 71 | Use: "list-ip-reservation", 72 | Short: "Retrieve a single IP reservation object by ID", 73 | RunE: func(cmd *cobra.Command, args []string) error { 74 | reservationID := cmd.Flag("reservation-id").Value.String() 75 | err := ListIPReservations(reservationID) 76 | return err 77 | }, 78 | } 79 | 80 | var removeReservationCmd = &cobra.Command{ 81 | Use: "remove-ip-reservation", 82 | Short: "Remove IP reservation", 83 | RunE: func(cmd *cobra.Command, args []string) error { 84 | reservationID := cmd.Flag("reservation-id").Value.String() 85 | err := RemoveIPReservation(reservationID) 86 | return err 87 | }, 88 | } 89 | 90 | func init() { 91 | networkCmd.AddCommand(listIPCmd, assignIPCmd, unAssignIPCmd, listReservationsCmd, listReservationCmd, requestMoreIPReservationsCmd, removeReservationCmd) 92 | RootCmd.AddCommand(networkCmd) 93 | 94 | // Flags for command: packet network list-ip 95 | listIPCmd.Flags().String("address-id", "", "IP address ID") 96 | 97 | // Flags for command: packet network assign-ip 98 | assignIPCmd.Flags().String("address", "", "IP address.(format: x.x.x.x/y)") 99 | assignIPCmd.Flags().String("device-id", "", "ID of device to assign to") 100 | 101 | // Flags for command: packet network unassign-ip 102 | unAssignIPCmd.Flags().String("address-id", "", "IP address ID") 103 | 104 | // Flags for command: packet netowrk list-ip-reservations 105 | listReservationsCmd.Flags().String("project-id", "", "Project ID") 106 | 107 | // Flags for command: packet network list-ip-reservation 108 | listReservationCmd.Flags().String("reservation-id", "", "Reservation ID") 109 | 110 | // Flags for command: packet network remove-ip-reservation 111 | removeReservationCmd.Flags().String("reservation-id", "", "Reservation ID") 112 | 113 | // Flags for command: packet network request-more 114 | requestMoreIPReservationsCmd.Flags().String("project-id", "", "Project ID") 115 | requestMoreIPReservationsCmd.Flags().String("type", "public_ipv4", "public_ipv4 || global_ipv4") 116 | requestMoreIPReservationsCmd.Flags().String("comments", "", "Comment to Packet team") 117 | requestMoreIPReservationsCmd.Flags().Int("quantity", 1, "How many IPv4 you want to request. Options: 1, 2, 4, 8, 16, 32, 64, 128, 256") 118 | 119 | } 120 | -------------------------------------------------------------------------------- /cmd/releaseNotes.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | // releaseNotesCmd represents the releaseNotes command 11 | var releaseNotesCmd = &cobra.Command{ 12 | Use: "release-notes", 13 | Short: "show release notes", 14 | Hidden: true, 15 | Long: "", 16 | Run: func(cmd *cobra.Command, args []string) { 17 | fmt.Printf("%s v%s %v/%v\n", cmd.Parent().CommandPath(), version, runtime.GOOS, runtime.GOARCH) 18 | fmt.Println() 19 | fmt.Println("RELEASE NOTES") 20 | fmt.Println(releaseNotes) 21 | }, 22 | } 23 | 24 | func init() { 25 | RootCmd.AddCommand(releaseNotesCmd) 26 | } 27 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "runtime" 7 | 8 | "github.com/spf13/cobra" 9 | "github.com/spf13/viper" 10 | ) 11 | 12 | var cfgFile string 13 | 14 | // RootCmd represents the base command when called without any subcommands 15 | var RootCmd = &cobra.Command{ 16 | Use: "packet", 17 | Short: "CLI tool to manage packet.net services", 18 | SilenceUsage: true, 19 | Run: func(cmd *cobra.Command, args []string) { 20 | showVersion, _ := cmd.Flags().GetBool("version") 21 | if showVersion { 22 | // fmt.Printf("packet v%s\n", version) 23 | fmt.Printf("%s v%s %v/%v\n", cmd.CommandPath(), version, runtime.GOOS, runtime.GOARCH) 24 | } 25 | }, 26 | } 27 | 28 | // Execute adds all child commands to the root command sets flags appropriately. 29 | // This is called by main.main(). It only needs to happen once to the rootCmd. 30 | func Execute() { 31 | if err := RootCmd.Execute(); err != nil { 32 | // fmt.Println(err) 33 | os.Exit(-1) 34 | } 35 | } 36 | 37 | func init() { 38 | cobra.OnInitialize(initConfig) 39 | 40 | // Global flag for setting the API key. 41 | RootCmd.PersistentFlags().StringP("key", "k", "", "API key") 42 | RootCmd.PersistentFlags().StringP("profile", "p", "default", "Profile name") 43 | RootCmd.Flags().BoolP("version", "v", false, "Show version and exit") 44 | } 45 | 46 | // initConfig reads in config file and ENV variables if set. 47 | func initConfig() { 48 | if cfgFile != "" { // enable ability to specify config file via flag 49 | viper.SetConfigFile(cfgFile) 50 | } 51 | 52 | viper.SetConfigName(".packet") // name of config file (without extension) 53 | viper.AddConfigPath("$HOME") // adding home directory as first search path 54 | viper.AutomaticEnv() // read in environment variables that match 55 | 56 | // If a config file is found, read it in. 57 | if err := viper.ReadInConfig(); err == nil { 58 | fmt.Println("Using config file:", viper.ConfigFileUsed()) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /cmd/storage.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | // storageCmd represents the storage command 8 | var storageCmd = &cobra.Command{ 9 | Use: "storage", 10 | Short: "Manage your storages", 11 | } 12 | 13 | var listStoragesCmd = &cobra.Command{ 14 | Use: "list-volumes", 15 | Short: "Retrieve all volumes", 16 | RunE: func(cmd *cobra.Command, args []string) error { 17 | projectID := GetProjectID(cmd) 18 | err := ListStorages(projectID) 19 | return err 20 | }, 21 | } 22 | 23 | var createStorageCmd = &cobra.Command{ 24 | Use: "create-volume", 25 | Short: "Create a volume", 26 | RunE: func(cmd *cobra.Command, args []string) error { 27 | projectID := GetProjectID(cmd) 28 | description := cmd.Flag("desc").Value.String() 29 | plan := cmd.Flag("plan").Value.String() 30 | facility := cmd.Flag("facility").Value.String() 31 | size, err := cmd.Flags().GetInt("size") 32 | if err != nil { 33 | return err 34 | } 35 | snapshotFrequency := cmd.Flag("frequency").Value.String() 36 | snapshotCount, err := cmd.Flags().GetInt("count") 37 | if err != nil { 38 | return err 39 | } 40 | e := CreateStorage(projectID, description, plan, facility, snapshotFrequency, size, snapshotCount) 41 | return e 42 | }, 43 | } 44 | 45 | var listStorageCmd = &cobra.Command{ 46 | Use: "list-volume", 47 | Short: "Retrieve a volume by ID", 48 | RunE: func(cmd *cobra.Command, args []string) error { 49 | storageID := cmd.Flag("volume-id").Value.String() 50 | err := ListStorage(storageID) 51 | return err 52 | }, 53 | } 54 | 55 | var updateStorageCmd = &cobra.Command{ 56 | Use: "update-volume", 57 | Short: "Update a volume", 58 | RunE: func(cmd *cobra.Command, args []string) error { 59 | storageID := cmd.Flag("volume-id").Value.String() 60 | description := cmd.Flag("desc").Value.String() 61 | size, err := cmd.Flags().GetInt("size") 62 | if err != nil { 63 | return err 64 | } 65 | locked, err := cmd.Flags().GetBool("lock") 66 | if err != nil { 67 | return err 68 | } 69 | e := UpdateStorage(storageID, description, size, locked) 70 | return e 71 | }, 72 | } 73 | 74 | var deleteStorageCmd = &cobra.Command{ 75 | Use: "delete-volume", 76 | Short: "Delete storage", 77 | RunE: func(cmd *cobra.Command, args []string) error { 78 | storageID := cmd.Flag("volume-id").Value.String() 79 | err := DeleteStorage(storageID) 80 | return err 81 | }, 82 | } 83 | 84 | var createSnapshotPolicyCmd = &cobra.Command{ 85 | Use: "create-snapshot-policy", 86 | Short: "Create a snapshot policy", 87 | RunE: func(cmd *cobra.Command, args []string) error { 88 | storageID := cmd.Flag("volume-id").Value.String() 89 | snapshotFrequency := cmd.Flag("frequency").Value.String() 90 | snapshotCount, err := cmd.Flags().GetInt("count") 91 | if err != nil { 92 | return err 93 | } 94 | e := CreateSnapshotPolicy(storageID, snapshotFrequency, snapshotCount) 95 | return e 96 | }, 97 | } 98 | 99 | var updateSnapshotPolicyCmd = &cobra.Command{ 100 | Use: "update-snapshot-policy", 101 | Short: "Update a snapshot policy", 102 | RunE: func(cmd *cobra.Command, args []string) error { 103 | policyID := cmd.Flag("policy-id").Value.String() 104 | snapshotFrequency := cmd.Flag("frequency").Value.String() 105 | snapshotCount, err := cmd.Flags().GetInt("count") 106 | if err != nil { 107 | return err 108 | } 109 | e := UpdateSnapshotPolicy(policyID, snapshotFrequency, snapshotCount) 110 | return e 111 | }, 112 | } 113 | 114 | var deleteSnapshotPolicyCmd = &cobra.Command{ 115 | Use: "delete-snapshot-policy", 116 | Short: "Delete a snapshot policy", 117 | RunE: func(cmd *cobra.Command, args []string) error { 118 | policyID := cmd.Flag("policy-id").Value.String() 119 | err := DeleteSnapshotPolicy(policyID) 120 | return err 121 | }, 122 | } 123 | 124 | var listSnapshotsCmd = &cobra.Command{ 125 | Use: "list-snapshots", 126 | Short: "View a list of the current volume’s snapshots", 127 | RunE: func(cmd *cobra.Command, args []string) error { 128 | storageID := cmd.Flag("volume-id").Value.String() 129 | err := ListSnapshots(storageID) 130 | return err 131 | }, 132 | } 133 | 134 | var createSnapshotCmd = &cobra.Command{ 135 | Use: "create-snapshot", 136 | Short: "Create a snapshot of your volume", 137 | RunE: func(cmd *cobra.Command, args []string) error { 138 | storageID := cmd.Flag("volume-id").Value.String() 139 | err := CreateSnapshot(storageID) 140 | return err 141 | }, 142 | } 143 | 144 | var deleteSnapshotCmd = &cobra.Command{ 145 | Use: "delete-snapshot", 146 | Short: "Delete a snapshot of your volume", 147 | RunE: func(cmd *cobra.Command, args []string) error { 148 | storageID := cmd.Flag("volume-id").Value.String() 149 | snapshotID := cmd.Flag("snapshot-id").Value.String() 150 | err := DeleteSnapshot(storageID, snapshotID) 151 | return err 152 | }, 153 | } 154 | 155 | var listStorageEventsCmd = &cobra.Command{ 156 | Use: "list-volume-events", 157 | Short: "View a list of the current volume's events", 158 | RunE: func(cmd *cobra.Command, args []string) error { 159 | storageID := cmd.Flag("volume-id").Value.String() 160 | err := ListStorageEvents(storageID) 161 | return err 162 | }, 163 | } 164 | 165 | var attachStorageCmd = &cobra.Command{ 166 | Use: "attach-volume", 167 | Short: "Attach a volume to a device", 168 | RunE: func(cmd *cobra.Command, args []string) error { 169 | storageID := cmd.Flag("volume-id").Value.String() 170 | deviceID := cmd.Flag("device-id").Value.String() 171 | err := AttachStorage(storageID, deviceID) 172 | return err 173 | }, 174 | } 175 | 176 | var detachStorageCmd = &cobra.Command{ 177 | Use: "detach-volume", 178 | Short: "Detach a volume from a device", 179 | RunE: func(cmd *cobra.Command, args []string) error { 180 | attachmentID := cmd.Flag("attachement-id").Value.String() 181 | err := DetachStorage(attachmentID) 182 | return err 183 | }, 184 | } 185 | 186 | var restoreStorageCmd = &cobra.Command{ 187 | Use: "restore-volume", 188 | Short: "Restore a volume to the given snapshot", 189 | RunE: func(cmd *cobra.Command, args []string) error { 190 | storageID := cmd.Flag("volume-id").Value.String() 191 | restorePoint := cmd.Flag("restore-point").Value.String() 192 | err := RestoreStorage(storageID, restorePoint) 193 | return err 194 | }, 195 | } 196 | 197 | var cloneStorageCmd = &cobra.Command{ 198 | Use: "clone-volume", 199 | Short: "Clone a volume or snapshot into a new volume", 200 | RunE: func(cmd *cobra.Command, args []string) error { 201 | storageID := cmd.Flag("volume-id").Value.String() 202 | snapshotTimestamp := cmd.Flag("snapshot-timestamp").Value.String() 203 | err := CloneStorage(storageID, snapshotTimestamp) 204 | return err 205 | }, 206 | } 207 | 208 | func init() { 209 | storageCmd.AddCommand(listStoragesCmd, createStorageCmd, listStorageCmd, updateStorageCmd, deleteStorageCmd, createSnapshotPolicyCmd, updateSnapshotPolicyCmd, deleteSnapshotPolicyCmd, listSnapshotsCmd, createSnapshotCmd, deleteSnapshotCmd, listStorageEventsCmd, attachStorageCmd, detachStorageCmd, restoreStorageCmd, cloneStorageCmd) 210 | RootCmd.AddCommand(storageCmd) 211 | 212 | // Flags for command: packet storage listall 213 | listStoragesCmd.Flags().String("project-id", "", "Project ID") 214 | 215 | // Flags for command: packet storage create 216 | createStorageCmd.Flags().String("project-id", "", "Project ID") 217 | createStorageCmd.Flags().String("desc", "", "Description") 218 | createStorageCmd.Flags().String("plan", "storage_1", "storage_1 || storage_2") 219 | createStorageCmd.Flags().String("facility", "ewr1", "ewr1 || sjc1 || ams1") 220 | createStorageCmd.Flags().Int("size", 120, "Volume size") 221 | createStorageCmd.Flags().String("frequency", "15min", "Snapshot frequency") 222 | createStorageCmd.Flags().Int("count", 4, "Snapshots count. if you pass 0, the volume will be created without a snapashot policy") 223 | 224 | // Flags for command: packet storage list 225 | listStorageCmd.Flags().String("volume-id", "", "Volume ID") 226 | 227 | // Flags for command: packet storage update 228 | updateStorageCmd.Flags().String("volume-id", "", "Volume ID") 229 | updateStorageCmd.Flags().String("desc", "", "Description") 230 | updateStorageCmd.Flags().Int("size", 120, "Volume size") 231 | updateStorageCmd.Flags().Bool("lock", false, "Update and lock") 232 | 233 | // Flags for command: packet storage delete 234 | deleteStorageCmd.Flags().String("volume-id", "", "Volume ID") 235 | 236 | // Flags for command: packet storage create-snapshot-policy 237 | createSnapshotPolicyCmd.Flags().String("volume-id", "", "Volume ID") 238 | createSnapshotPolicyCmd.Flags().String("frequency", "", "Snapshot frequency") 239 | createSnapshotPolicyCmd.Flags().Int("count", 1, "Snapshots count") 240 | 241 | // Flags for command: packet storage update-snapshot-policy 242 | updateSnapshotPolicyCmd.Flags().String("policy-id", "", "Snapshot policy ID") 243 | updateSnapshotPolicyCmd.Flags().String("frequency", "15min", "Snapshot frequency") 244 | updateSnapshotPolicyCmd.Flags().Int("count", 4, "Snapshots count") 245 | 246 | // Flags for command: packet storage delete-snapshot-policy 247 | deleteSnapshotPolicyCmd.Flags().String("policy-id", "", "Snapshot policy ID") 248 | 249 | // Flags for command: packet storage list-snapshots 250 | listSnapshotsCmd.Flags().String("volume-id", "", "Volume ID") 251 | 252 | // Flags for command: packet storage create-snapshot 253 | createSnapshotCmd.Flags().String("volume-id", "", "volume ID") 254 | 255 | // Flags for command: packet storage delete-snapshot 256 | deleteSnapshotCmd.Flags().String("volume-id", "", "Volume ID") 257 | deleteSnapshotCmd.Flags().String("snapshot-id", "", "Snapshot policy ID") 258 | 259 | // Flags for command: packet storage list-events 260 | listStorageEventsCmd.Flags().String("volume-id", "", "Volume ID") 261 | 262 | // Flags for command: packet storage attach 263 | attachStorageCmd.Flags().String("volume-id", "", "Volume ID") 264 | attachStorageCmd.Flags().String("device-id", "", "Device ID") 265 | 266 | // Flags for command: packet storage detach 267 | detachStorageCmd.Flags().String("attachement-id", "", "Attachment ID") 268 | 269 | // Flags for command: packet storage restore 270 | restoreStorageCmd.Flags().String("volume-id", "", "Volume ID") 271 | restoreStorageCmd.Flags().String("restore-point", "", "Restore point in the form of a Unix timestamp") 272 | 273 | // Flags for command: packet storage clone 274 | cloneStorageCmd.Flags().String("volume-id", "", "Volume ID") 275 | cloneStorageCmd.Flags().String("snapshot-timestamp", "", "Snapshot timestamp(optional)") 276 | } 277 | -------------------------------------------------------------------------------- /cmd/util.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "bufio" 5 | "encoding/json" 6 | "errors" 7 | "fmt" 8 | "io/ioutil" 9 | "os" 10 | "os/user" 11 | "path/filepath" 12 | "strings" 13 | 14 | "github.com/spf13/cobra" 15 | ) 16 | 17 | // ConfigDir is the location of the config file under user's $HOME dir 18 | const ConfigDir = ".packet" 19 | 20 | // ConfigFile is the filename of the config file 21 | const ConfigFile = "config" 22 | 23 | // Configs represents a set of profiles 24 | type Configs struct { 25 | Profiles map[string]*Config `json:"profiles"` 26 | } 27 | 28 | // Config represent default configurations 29 | type Config struct { 30 | APIKEY string `json:"APIKEY"` 31 | DefaultProjectID string `json:"DEFAULT_PROJECT_ID"` 32 | } 33 | 34 | func (c *Config) String() string { 35 | return fmt.Sprintf("%-32s\t%s", c.APIKEY, c.DefaultProjectID) 36 | } 37 | 38 | // Configure prompts the user to configure a default API key 39 | func Configure(profile string) error { 40 | 41 | // Modify to true if user changes the config 42 | var hasChanged bool 43 | 44 | // Declare values for user prompt 45 | var newKey, currentKey, keySuffix, currentProjectID, projectID string 46 | 47 | // Get the profile name from CLI 48 | // profile := getProfileName() 49 | 50 | // Get the current key, create a suffix for hint. 51 | // the current key shall not be displayed on the console 52 | confs, _ := ReadConfigs() 53 | var conf *Config 54 | if confs != nil { 55 | if _, ok := confs.Profiles[profile]; ok { 56 | conf = confs.Profiles[profile] 57 | currentKey = conf.APIKEY 58 | currentProjectID = conf.DefaultProjectID 59 | } else { 60 | conf = &Config{} 61 | } 62 | } else { 63 | confs = &Configs{} 64 | confs.Profiles = make(map[string]*Config) 65 | conf = &Config{} 66 | } 67 | 68 | if currentKey != "" && len(currentKey) > 5 { 69 | keySuffix = currentKey[len(currentKey)-4:] 70 | } 71 | 72 | if keySuffix != "" { 73 | keySuffix = "****************************" + keySuffix 74 | } 75 | 76 | // Get API key and default project ID from user 77 | reader := bufio.NewReader(os.Stdin) 78 | fmt.Printf("Enter your API key [ %s ]: ", keySuffix) 79 | newKey, _ = reader.ReadString('\n') 80 | newKey = strings.TrimSpace(newKey) 81 | fmt.Printf("Enter your default project ID [ %s ]: ", currentProjectID) 82 | projectID, _ = reader.ReadString('\n') 83 | projectID = strings.TrimSpace(projectID) 84 | 85 | // For debug: 86 | // fmt.Printf("New key is: %s\n", newKey) 87 | // fmt.Printf("New PID: %s\n", projectID) 88 | 89 | if newKey != "" { 90 | conf.APIKEY = newKey 91 | hasChanged = true 92 | } 93 | 94 | if projectID != "" { 95 | conf.DefaultProjectID = projectID 96 | hasChanged = true 97 | } 98 | 99 | confs.Profiles[profile] = conf 100 | 101 | if hasChanged { 102 | // Write to config file 103 | writeConfigFile(confs) 104 | } 105 | 106 | return nil 107 | } 108 | 109 | // ReadConfigs reads the current config file and returns a Config object 110 | func ReadConfigs() (*Configs, error) { 111 | c, err := readConfigFile() 112 | if err != nil { 113 | return nil, err 114 | } 115 | 116 | // For backward compatibility. This is not essential but will 117 | // avoid errors after upgrades from v1.1 to v1.2 and up 118 | // If it happens that the c.Profiles is empty, we try to read the configs 119 | // assuming the old format, and automatically make a new defualt profile 120 | if len(c.Profiles) == 0 { 121 | defaultConf, err := readOldConfigFile() 122 | if err != nil { 123 | return nil, err 124 | } 125 | if defaultConf.APIKEY != "" { 126 | c.Profiles = make(map[string]*Config) 127 | c.Profiles["default"] = defaultConf 128 | // Now write the profile in new format 129 | err := writeConfigFile(c) 130 | if err != nil { 131 | return nil, err 132 | } 133 | } 134 | } 135 | 136 | return c, nil 137 | } 138 | 139 | // GetAPIKey returns either the default configured key or the one passed through the CLI. 140 | // The key passed through the CLI has the highest priority 141 | func GetAPIKey() (string, error) { 142 | 143 | apiKey := RootCmd.Flag("key").Value.String() 144 | if apiKey == "" { 145 | profile := getProfile() 146 | configs, err := ReadConfigs() 147 | if err != nil { 148 | return apiKey, err 149 | } 150 | if _, found := configs.Profiles[profile]; found { 151 | apiKey = configs.Profiles[profile].APIKEY 152 | } 153 | } 154 | 155 | if apiKey == "" { 156 | // API Key was neither configured, neither passed through the cli 157 | return apiKey, errors.New("API key is missing\nConfigure a profile with `packet admin add-profile`, or use the `--key` flag") 158 | } 159 | 160 | return apiKey, nil 161 | } 162 | 163 | // GetProjectID returns the project ID passed to the CLI, otherwise the configure default ID. 164 | func GetProjectID(cmd *cobra.Command) string { 165 | // The flag to pass a project ID shall always be "--project-id" 166 | projectID := cmd.Flag("project-id").Value.String() 167 | if projectID == "" { 168 | profile := getProfile() 169 | configs, err := ReadConfigs() 170 | if err != nil { 171 | return projectID 172 | } 173 | if _, found := configs.Profiles[profile]; found { 174 | projectID = configs.Profiles[profile].DefaultProjectID 175 | } 176 | } 177 | 178 | return projectID 179 | 180 | } 181 | 182 | // MarshallAndPrint pretty-prints any object as a JSON string 183 | func MarshallAndPrint(v interface{}) error { 184 | b, err := json.MarshalIndent(v, "", " ") 185 | if err != nil { 186 | return err 187 | } 188 | fmt.Printf("%s\n", string(b)) 189 | return nil 190 | } 191 | 192 | // Helper functions 193 | 194 | func getProfile() string { 195 | profile := RootCmd.Flag("profile").Value.String() 196 | if profile == "" { 197 | profile = "default" 198 | } 199 | return profile 200 | } 201 | 202 | func readConfigFile() (*Configs, error) { 203 | u, err := user.Current() 204 | if err != nil { 205 | return nil, err 206 | } 207 | 208 | path := filepath.Join(u.HomeDir, ConfigDir, ConfigFile) 209 | 210 | confs, err := ioutil.ReadFile(path) 211 | if err != nil { 212 | return nil, errors.New("API key is missing\nConfigure a profile with `packet admin add-profile`, or use the `--key` flag") 213 | } 214 | 215 | var c Configs 216 | err = json.Unmarshal(confs, &c) 217 | if err != nil { 218 | return nil, err 219 | } 220 | 221 | return &c, nil 222 | } 223 | 224 | func readOldConfigFile() (*Config, error) { 225 | u, err := user.Current() 226 | if err != nil { 227 | return nil, err 228 | } 229 | 230 | path := filepath.Join(u.HomeDir, ConfigDir, ConfigFile) 231 | 232 | confs, err := ioutil.ReadFile(path) 233 | if err != nil { 234 | return nil, err 235 | } 236 | 237 | var c Config 238 | err = json.Unmarshal(confs, &c) 239 | if err != nil { 240 | return nil, err 241 | } 242 | 243 | return &c, nil 244 | } 245 | 246 | func writeConfigFile(c *Configs) error { 247 | u, err := user.Current() 248 | if err != nil { 249 | return err 250 | } 251 | 252 | // create directory to save configs 253 | dirPath := filepath.Join(u.HomeDir, ConfigDir) 254 | filePath := filepath.Join(dirPath, ConfigFile) 255 | if _, err := os.Stat(dirPath); os.IsNotExist(err) { 256 | os.Mkdir(dirPath, 0755) 257 | } 258 | 259 | cBytes, err := json.MarshalIndent(c, "", "\t") 260 | if err != nil { 261 | return err 262 | } 263 | err = ioutil.WriteFile(filePath, cBytes, 0755) 264 | return err 265 | } 266 | -------------------------------------------------------------------------------- /cmd/version.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | const version = "2.3.1" 4 | 5 | const releaseNotes = `------------------------------------------------------------------------------| 6 | | Version | Description | 7 | |-----------|-----------------------------------------------------------------| 8 | | 2.3.1 | Allow creating volumes without a snapshot policy by passing | 9 | | | --count 0 | 10 | |-----------|-----------------------------------------------------------------| 11 | | 2.3 | Added support for the "organization" API | 12 | | | Support pagination for packet baremetal list-devices | 13 | |-----------|-----------------------------------------------------------------| 14 | | 2.2.2 | Fixed a bug that blows away all tags on device updates | 15 | | | Added --tags flag(not mandatory) to create-device and | 16 | | | update-device commands | 17 | |-----------|-----------------------------------------------------------------| 18 | | 2.2.1 | Fixed compilation issue that emerged with updated Packet API | 19 | |-----------|-----------------------------------------------------------------| 20 | | 2.2 | "update-device" command added; more options for "create-device" | 21 | | | command | 22 | |-----------|-----------------------------------------------------------------| 23 | | 2.1.3 | Fixed an issue that emerged with the updated Packet API | 24 | |-----------|-----------------------------------------------------------------| 25 | | 2.1.2 | Fixed an issue that emerged with the updated Packet API | 26 | |-----------|-----------------------------------------------------------------| 27 | | 2.1.1 | Bug fix around profile configuration. Now you can use --name | 28 | | | or -n to configure and name a profile | 29 | |-----------|-----------------------------------------------------------------| 30 | | 2.1 | Add support for spot market | 31 | |-----------|-----------------------------------------------------------------| 32 | | 2.0 | Changed command structure, many bugs fixed | 33 | |-----------|-----------------------------------------------------------------| 34 | | 1.3 | Can now delete profiles | 35 | |-----------|-----------------------------------------------------------------| 36 | | 1.2 | Added profile support: use --profile option to switch between | 37 | | | profiles. | 38 | | | ssh command now reads keys from files, use --file instead of | 39 | | | ssh-key to read from files. | 40 | |-----------|-----------------------------------------------------------------| 41 | | 1.1 | Added support for userdata | 42 | |-----------|-----------------------------------------------------------------| 43 | | 1.0 | First version | 44 | -------------------------------------------------------------------------------` 45 | -------------------------------------------------------------------------------- /doc/packet.md: -------------------------------------------------------------------------------- 1 | ## packet 2 | 3 | CLI tool to manage packet.net services 4 | 5 | ### Synopsis 6 | 7 | CLI tool to manage packet.net services 8 | 9 | ``` 10 | packet [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for packet 17 | -k, --key string API key 18 | -p, --profile string Profile name (default "default") 19 | -v, --version Show version and exit 20 | ``` 21 | 22 | ### SEE ALSO 23 | 24 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 25 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 26 | * [packet network](packet_network.md) - Manage packet network services 27 | * [packet storage](packet_storage.md) - Manage your storages 28 | 29 | ###### Auto generated by spf13/cobra on 4-Jun-2018 30 | -------------------------------------------------------------------------------- /doc/packet_admin.md: -------------------------------------------------------------------------------- 1 | ## packet admin 2 | 3 | Manage projects, ssh keys, etc... 4 | 5 | ### Synopsis 6 | 7 | Manage projects, ssh keys, etc... 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for admin 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | -k, --key string API key 19 | -p, --profile string Profile name (default "default") 20 | ``` 21 | 22 | ### SEE ALSO 23 | 24 | * [packet](packet.md) - CLI tool to manage packet.net services 25 | * [packet admin add-profile](packet_admin_add-profile.md) - Set default configs for the packet cli. 26 | * [packet admin create-org](packet_admin_create-org.md) - Create a new organization 27 | * [packet admin create-project](packet_admin_create-project.md) - Create a new project 28 | * [packet admin create-sshkey](packet_admin_create-sshkey.md) - Configure a new SSH key 29 | * [packet admin delete-org](packet_admin_delete-org.md) - Delete organization by ID 30 | * [packet admin delete-profile](packet_admin_delete-profile.md) - Delete a profile 31 | * [packet admin delete-project](packet_admin_delete-project.md) - Delete a project 32 | * [packet admin delete-sshkey](packet_admin_delete-sshkey.md) - Delete SSH key associated with the given ID. 33 | * [packet admin list-facilities](packet_admin_list-facilities.md) - View a list of facilities(packet DCs) 34 | * [packet admin list-org](packet_admin_list-org.md) - List organization by ID 35 | * [packet admin list-orgs](packet_admin_list-orgs.md) - List organizations associated to user 36 | * [packet admin list-os](packet_admin_list-os.md) - View available operating systems 37 | * [packet admin list-payment-methods](packet_admin_list-payment-methods.md) - List payment methods by organization ID 38 | * [packet admin list-plans](packet_admin_list-plans.md) - View available plans. 39 | * [packet admin list-profiles](packet_admin_list-profiles.md) - List configured profiles 40 | * [packet admin list-project](packet_admin_list-project.md) - Retrieve a project by ID 41 | * [packet admin list-project-events](packet_admin_list-project-events.md) - View events by project ID 42 | * [packet admin list-projects](packet_admin_list-projects.md) - Retrieve all projects 43 | * [packet admin list-sshkey](packet_admin_list-sshkey.md) - View configured SSH key associated with the given ID. 44 | * [packet admin list-sshkeys](packet_admin_list-sshkeys.md) - View all configured SSH keys 45 | * [packet admin spot-prices](packet_admin_spot-prices.md) - View spot market prices 46 | * [packet admin update-org](packet_admin_update-org.md) - update a organization 47 | * [packet admin update-project](packet_admin_update-project.md) - Update a project 48 | * [packet admin update-sshkey](packet_admin_update-sshkey.md) - Update a SSH key: change the key or its label 49 | 50 | ###### Auto generated by spf13/cobra on 4-Jun-2018 51 | -------------------------------------------------------------------------------- /doc/packet_admin_add-profile.md: -------------------------------------------------------------------------------- 1 | ## packet admin add-profile 2 | 3 | Set default configs for the packet cli. 4 | 5 | ### Synopsis 6 | 7 | Set default configs for the packet cli. 8 | 9 | The following configurations are supported: 10 | - default API key 11 | This default key will be used if "--key" flag is missing in command. 12 | - default project ID 13 | This ID will be used if "--project-id" flag is missing in command. 14 | 15 | ``` 16 | packet admin add-profile [flags] 17 | ``` 18 | 19 | ### Options 20 | 21 | ``` 22 | -h, --help help for add-profile 23 | -n, --name string Profile name 24 | ``` 25 | 26 | ### Options inherited from parent commands 27 | 28 | ``` 29 | -k, --key string API key 30 | -p, --profile string Profile name (default "default") 31 | ``` 32 | 33 | ### SEE ALSO 34 | 35 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 36 | 37 | ###### Auto generated by spf13/cobra on 4-Jun-2018 38 | -------------------------------------------------------------------------------- /doc/packet_admin_create-org.md: -------------------------------------------------------------------------------- 1 | ## packet admin create-org 2 | 3 | Create a new organization 4 | 5 | ### Synopsis 6 | 7 | Create a new organization 8 | 9 | ``` 10 | packet admin create-org [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --description string Description 17 | -h, --help help for create-org 18 | --logo string Logo 19 | --name string Name 20 | --twitter string Twitter URL 21 | --website string Website URL 22 | ``` 23 | 24 | ### Options inherited from parent commands 25 | 26 | ``` 27 | -k, --key string API key 28 | -p, --profile string Profile name (default "default") 29 | ``` 30 | 31 | ### SEE ALSO 32 | 33 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 34 | 35 | ###### Auto generated by spf13/cobra on 4-Jun-2018 36 | -------------------------------------------------------------------------------- /doc/packet_admin_create-project.md: -------------------------------------------------------------------------------- 1 | ## packet admin create-project 2 | 3 | Create a new project 4 | 5 | ### Synopsis 6 | 7 | Create a new project 8 | 9 | ``` 10 | packet admin create-project [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for create-project 17 | --name string Project name 18 | --org-id string Organization ID 19 | --payment-id string ID of the payment method to associate to this project 20 | ``` 21 | 22 | ### Options inherited from parent commands 23 | 24 | ``` 25 | -k, --key string API key 26 | -p, --profile string Profile name (default "default") 27 | ``` 28 | 29 | ### SEE ALSO 30 | 31 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 32 | 33 | ###### Auto generated by spf13/cobra on 4-Jun-2018 34 | -------------------------------------------------------------------------------- /doc/packet_admin_create-sshkey.md: -------------------------------------------------------------------------------- 1 | ## packet admin create-sshkey 2 | 3 | Configure a new SSH key 4 | 5 | ### Synopsis 6 | 7 | Configure a new SSH key 8 | 9 | ``` 10 | packet admin create-sshkey [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -f, --file string Read public key from file. 17 | -h, --help help for create-sshkey 18 | --label string Label to assign to the key 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | -k, --key string API key 25 | -p, --profile string Profile name (default "default") 26 | ``` 27 | 28 | ### SEE ALSO 29 | 30 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 31 | 32 | ###### Auto generated by spf13/cobra on 4-Jun-2018 33 | -------------------------------------------------------------------------------- /doc/packet_admin_delete-org.md: -------------------------------------------------------------------------------- 1 | ## packet admin delete-org 2 | 3 | Delete organization by ID 4 | 5 | ### Synopsis 6 | 7 | Delete organization by ID 8 | 9 | ``` 10 | packet admin delete-org [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-org 17 | --org-id string Organization ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_delete-profile.md: -------------------------------------------------------------------------------- 1 | ## packet admin delete-profile 2 | 3 | Delete a profile 4 | 5 | ### Synopsis 6 | 7 | Delete a profile 8 | 9 | ``` 10 | packet admin delete-profile [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-profile 17 | -n, --name string Profile name 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_delete-project.md: -------------------------------------------------------------------------------- 1 | ## packet admin delete-project 2 | 3 | Delete a project 4 | 5 | ### Synopsis 6 | 7 | Delete a project 8 | 9 | ``` 10 | packet admin delete-project [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-project 17 | --project-id string Project ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_delete-sshkey.md: -------------------------------------------------------------------------------- 1 | ## packet admin delete-sshkey 2 | 3 | Delete SSH key associated with the given ID. 4 | 5 | ### Synopsis 6 | 7 | Delete SSH key associated with the given ID. 8 | 9 | ``` 10 | packet admin delete-sshkey [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-sshkey 17 | --key-id string SSH key ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-facilities.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-facilities 2 | 3 | View a list of facilities(packet DCs) 4 | 5 | ### Synopsis 6 | 7 | View a list of facilities(packet DCs) 8 | 9 | ``` 10 | packet admin list-facilities [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-facilities 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_list-org.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-org 2 | 3 | List organization by ID 4 | 5 | ### Synopsis 6 | 7 | List organization by ID 8 | 9 | ``` 10 | packet admin list-org [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-org 17 | --org-id string Organization ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-orgs.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-orgs 2 | 3 | List organizations associated to user 4 | 5 | ### Synopsis 6 | 7 | List organizations associated to user 8 | 9 | ``` 10 | packet admin list-orgs [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-orgs 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_list-os.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-os 2 | 3 | View available operating systems 4 | 5 | ### Synopsis 6 | 7 | View available operating systems 8 | 9 | ``` 10 | packet admin list-os [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-os 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_list-payment-methods.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-payment-methods 2 | 3 | List payment methods by organization ID 4 | 5 | ### Synopsis 6 | 7 | List payment methods by organization ID 8 | 9 | ``` 10 | packet admin list-payment-methods [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-payment-methods 17 | --org-id string Organization ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-plans.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-plans 2 | 3 | View available plans. 4 | 5 | ### Synopsis 6 | 7 | View available plans. 8 | 9 | ``` 10 | packet admin list-plans [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-plans 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_list-profiles.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-profiles 2 | 3 | List configured profiles 4 | 5 | ### Synopsis 6 | 7 | List configured profiles 8 | 9 | ``` 10 | packet admin list-profiles [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-profiles 17 | -n, --name string Profile name 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-project-events.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-project-events 2 | 3 | View events by project ID 4 | 5 | ### Synopsis 6 | 7 | View events by project ID 8 | 9 | ``` 10 | packet admin list-project-events [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-project-events 17 | --project-id string Project ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-project.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-project 2 | 3 | Retrieve a project by ID 4 | 5 | ### Synopsis 6 | 7 | Retrieve a project by ID 8 | 9 | ``` 10 | packet admin list-project [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-project 17 | --project-id string Project ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-projects.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-projects 2 | 3 | Retrieve all projects 4 | 5 | ### Synopsis 6 | 7 | Retrieve all projects 8 | 9 | ``` 10 | packet admin list-projects [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-projects 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_list-sshkey.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-sshkey 2 | 3 | View configured SSH key associated with the given ID. 4 | 5 | ### Synopsis 6 | 7 | View configured SSH key associated with the given ID. 8 | 9 | ``` 10 | packet admin list-sshkey [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-sshkey 17 | --key-id string SSH key ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_admin_list-sshkeys.md: -------------------------------------------------------------------------------- 1 | ## packet admin list-sshkeys 2 | 3 | View all configured SSH keys 4 | 5 | ### Synopsis 6 | 7 | View all configured SSH keys 8 | 9 | ``` 10 | packet admin list-sshkeys [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-sshkeys 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_spot-prices.md: -------------------------------------------------------------------------------- 1 | ## packet admin spot-prices 2 | 3 | View spot market prices 4 | 5 | ### Synopsis 6 | 7 | View spot market prices 8 | 9 | ``` 10 | packet admin spot-prices [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for spot-prices 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | -k, --key string API key 23 | -p, --profile string Profile name (default "default") 24 | ``` 25 | 26 | ### SEE ALSO 27 | 28 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 29 | 30 | ###### Auto generated by spf13/cobra on 4-Jun-2018 31 | -------------------------------------------------------------------------------- /doc/packet_admin_update-org.md: -------------------------------------------------------------------------------- 1 | ## packet admin update-org 2 | 3 | update a organization 4 | 5 | ### Synopsis 6 | 7 | update a organization 8 | 9 | ``` 10 | packet admin update-org [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --description string Description 17 | -h, --help help for update-org 18 | --logo string Logo 19 | --name string Name 20 | --org-id string Organization ID 21 | --twitter string Twitter URL 22 | --website string Website URL 23 | ``` 24 | 25 | ### Options inherited from parent commands 26 | 27 | ``` 28 | -k, --key string API key 29 | -p, --profile string Profile name (default "default") 30 | ``` 31 | 32 | ### SEE ALSO 33 | 34 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 35 | 36 | ###### Auto generated by spf13/cobra on 4-Jun-2018 37 | -------------------------------------------------------------------------------- /doc/packet_admin_update-project.md: -------------------------------------------------------------------------------- 1 | ## packet admin update-project 2 | 3 | Update a project 4 | 5 | ### Synopsis 6 | 7 | Update a project 8 | 9 | ``` 10 | packet admin update-project [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for update-project 17 | --name string Project name 18 | --payment-id string ID of the payment method to associate to this project 19 | --project-id string Project ID 20 | ``` 21 | 22 | ### Options inherited from parent commands 23 | 24 | ``` 25 | -k, --key string API key 26 | -p, --profile string Profile name (default "default") 27 | ``` 28 | 29 | ### SEE ALSO 30 | 31 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 32 | 33 | ###### Auto generated by spf13/cobra on 4-Jun-2018 34 | -------------------------------------------------------------------------------- /doc/packet_admin_update-sshkey.md: -------------------------------------------------------------------------------- 1 | ## packet admin update-sshkey 2 | 3 | Update a SSH key: change the key or its label 4 | 5 | ### Synopsis 6 | 7 | Update a SSH key: change the key or its label 8 | 9 | ``` 10 | packet admin update-sshkey [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -f, --file string Read public key from file. 17 | -h, --help help for update-sshkey 18 | --key-id string SSH key ID 19 | --label string Label to assign to the key 20 | ``` 21 | 22 | ### Options inherited from parent commands 23 | 24 | ``` 25 | -k, --key string API key 26 | -p, --profile string Profile name (default "default") 27 | ``` 28 | 29 | ### SEE ALSO 30 | 31 | * [packet admin](packet_admin.md) - Manage projects, ssh keys, etc... 32 | 33 | ###### Auto generated by spf13/cobra on 4-Jun-2018 34 | -------------------------------------------------------------------------------- /doc/packet_baremetal.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal 2 | 3 | Manage server devices. 4 | 5 | ### Synopsis 6 | 7 | Manage server devices. 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for baremetal 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | -k, --key string API key 19 | -p, --profile string Profile name (default "default") 20 | ``` 21 | 22 | ### SEE ALSO 23 | 24 | * [packet](packet.md) - CLI tool to manage packet.net services 25 | * [packet baremetal create-device](packet_baremetal_create-device.md) - Create a new device 26 | * [packet baremetal delete-device](packet_baremetal_delete-device.md) - Delete a device 27 | * [packet baremetal list-device](packet_baremetal_list-device.md) - Retrieve a device 28 | * [packet baremetal list-devices](packet_baremetal_list-devices.md) - Retrieve all devices in a project 29 | * [packet baremetal list-events](packet_baremetal_list-events.md) - View events by device ID 30 | * [packet baremetal lock-device](packet_baremetal_lock-device.md) - Lock a device 31 | * [packet baremetal poweroff-device](packet_baremetal_poweroff-device.md) - Power off a device 32 | * [packet baremetal poweron-device](packet_baremetal_poweron-device.md) - Power on a device 33 | * [packet baremetal reboot-device](packet_baremetal_reboot-device.md) - Reboot a device 34 | * [packet baremetal unlock-device](packet_baremetal_unlock-device.md) - Unlock a device 35 | * [packet baremetal update-device](packet_baremetal_update-device.md) - Update a device 36 | 37 | ###### Auto generated by spf13/cobra on 4-Jun-2018 38 | -------------------------------------------------------------------------------- /doc/packet_baremetal_create-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal create-device 2 | 3 | Create a new device 4 | 5 | ### Synopsis 6 | 7 | Create a new device 8 | 9 | ``` 10 | packet baremetal create-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --always-pxe true Set PXE boot to true 17 | --billing string Choose "hourly" or "monthly" billing (default "hourly") 18 | --facility string DC location. Use "packet admin list-facilities" to see available facilities 19 | -f, --file string Read userdata from a file. This option works but is deprecated; use "--userfile" instead 20 | -h, --help help for create-device 21 | --hostname string Hostname of the device 22 | --ipxe-script-url string Script URL 23 | --os-type string Operating system to deploy to the server (default "centos_7") 24 | --plan string Server type to create the device (default "baremetal_0") 25 | --project-id string The project ID. 26 | -s, --silent Omit provisioning logs 27 | --spot-instance Create as a spot instance 28 | --spot-price-max float Spot market price bid 29 | --tags strings a list of comma separated tags 30 | --userdata string userdata string. This options will be disgarded if "--userfile" is present 31 | --userfile [file] Read userdata from a [file] 32 | ``` 33 | 34 | ### Options inherited from parent commands 35 | 36 | ``` 37 | -k, --key string API key 38 | -p, --profile string Profile name (default "default") 39 | ``` 40 | 41 | ### SEE ALSO 42 | 43 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 44 | 45 | ###### Auto generated by spf13/cobra on 4-Jun-2018 46 | -------------------------------------------------------------------------------- /doc/packet_baremetal_delete-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal delete-device 2 | 3 | Delete a device 4 | 5 | ### Synopsis 6 | 7 | Delete a device 8 | 9 | ``` 10 | packet baremetal delete-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for delete-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_list-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal list-device 2 | 3 | Retrieve a device 4 | 5 | ### Synopsis 6 | 7 | Retrieve a device 8 | 9 | ``` 10 | packet baremetal list-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Specify ID of device to display. 17 | -h, --help help for list-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_list-devices.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal list-devices 2 | 3 | Retrieve all devices in a project 4 | 5 | ### Synopsis 6 | 7 | Retrieve all devices in a project 8 | 9 | ``` 10 | packet baremetal list-devices [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-devices 17 | --includes string Specify which resources you want to return as collections instead of references. For multiple ressources, pass a comma separated string as in "resource1,resource2,resource3". Refer to the API docs(https://www.packet.net/developers/api/common-parameters/) for more info about the "include" parameter. 18 | --page int For paginated result sets, page of results to retrieve 19 | --per-page int For paginated result sets, the number of results to return per page 20 | --project-id string Specify the project ID. 21 | ``` 22 | 23 | ### Options inherited from parent commands 24 | 25 | ``` 26 | -k, --key string API key 27 | -p, --profile string Profile name (default "default") 28 | ``` 29 | 30 | ### SEE ALSO 31 | 32 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 33 | 34 | ###### Auto generated by spf13/cobra on 4-Jun-2018 35 | -------------------------------------------------------------------------------- /doc/packet_baremetal_list-events.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal list-events 2 | 3 | View events by device ID 4 | 5 | ### Synopsis 6 | 7 | View events by device ID 8 | 9 | ``` 10 | packet baremetal list-events [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for list-events 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_lock-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal lock-device 2 | 3 | Lock a device 4 | 5 | ### Synopsis 6 | 7 | Lock a device 8 | 9 | ``` 10 | packet baremetal lock-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for lock-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_poweroff-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal poweroff-device 2 | 3 | Power off a device 4 | 5 | ### Synopsis 6 | 7 | Power off a device 8 | 9 | ``` 10 | packet baremetal poweroff-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for poweroff-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_poweron-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal poweron-device 2 | 3 | Power on a device 4 | 5 | ### Synopsis 6 | 7 | Power on a device 8 | 9 | ``` 10 | packet baremetal poweron-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for poweron-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_reboot-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal reboot-device 2 | 3 | Reboot a device 4 | 5 | ### Synopsis 6 | 7 | Reboot a device 8 | 9 | ``` 10 | packet baremetal reboot-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for reboot-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_unlock-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal unlock-device 2 | 3 | Unlock a device 4 | 5 | ### Synopsis 6 | 7 | Unlock a device 8 | 9 | ``` 10 | packet baremetal unlock-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for unlock-device 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_baremetal_update-device.md: -------------------------------------------------------------------------------- 1 | ## packet baremetal update-device 2 | 3 | Update a device 4 | 5 | ### Synopsis 6 | 7 | Update a device 8 | 9 | ``` 10 | packet baremetal update-device [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --always-pxe string PXE boot: [true || false] 17 | --description string Description 18 | --device-id string Device ID 19 | -h, --help help for update-device 20 | --hostname string Hostname of the device 21 | --ipxe-script-url string Script URL 22 | --lock string Lock device: [true || false] 23 | --tags strings a list of comma separated tags 24 | --userdata string userdata string. This options will be disgarded if "--userfile" is present 25 | --userfile [file] Read userdata from a [file] 26 | ``` 27 | 28 | ### Options inherited from parent commands 29 | 30 | ``` 31 | -k, --key string API key 32 | -p, --profile string Profile name (default "default") 33 | ``` 34 | 35 | ### SEE ALSO 36 | 37 | * [packet baremetal](packet_baremetal.md) - Manage server devices. 38 | 39 | ###### Auto generated by spf13/cobra on 4-Jun-2018 40 | -------------------------------------------------------------------------------- /doc/packet_network.md: -------------------------------------------------------------------------------- 1 | ## packet network 2 | 3 | Manage packet network services 4 | 5 | ### Synopsis 6 | 7 | Manage packet network services 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for network 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | -k, --key string API key 19 | -p, --profile string Profile name (default "default") 20 | ``` 21 | 22 | ### SEE ALSO 23 | 24 | * [packet](packet.md) - CLI tool to manage packet.net services 25 | * [packet network assign-ip](packet_network_assign-ip.md) - Assign IP address to a device by ID 26 | * [packet network list-ip](packet_network_list-ip.md) - Retrieve IP address by ID 27 | * [packet network list-ip-reservation](packet_network_list-ip-reservation.md) - Retrieve a single IP reservation object by ID 28 | * [packet network list-ip-reservations](packet_network_list-ip-reservations.md) - Retrieve IP resevations for a single project 29 | * [packet network remove-ip-reservation](packet_network_remove-ip-reservation.md) - Remove IP reservation 30 | * [packet network request-more-ip-reservations](packet_network_request-more-ip-reservations.md) - Request more IP space 31 | * [packet network unassign-ip](packet_network_unassign-ip.md) - Unassign IP address from a device 32 | 33 | ###### Auto generated by spf13/cobra on 4-Jun-2018 34 | -------------------------------------------------------------------------------- /doc/packet_network_assign-ip.md: -------------------------------------------------------------------------------- 1 | ## packet network assign-ip 2 | 3 | Assign IP address to a device by ID 4 | 5 | ### Synopsis 6 | 7 | Assign IP address to a device by ID 8 | 9 | ``` 10 | packet network assign-ip [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --address string IP address.(format: x.x.x.x/y) 17 | --device-id string ID of device to assign to 18 | -h, --help help for assign-ip 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | -k, --key string API key 25 | -p, --profile string Profile name (default "default") 26 | ``` 27 | 28 | ### SEE ALSO 29 | 30 | * [packet network](packet_network.md) - Manage packet network services 31 | 32 | ###### Auto generated by spf13/cobra on 4-Jun-2018 33 | -------------------------------------------------------------------------------- /doc/packet_network_list-ip-reservation.md: -------------------------------------------------------------------------------- 1 | ## packet network list-ip-reservation 2 | 3 | Retrieve a single IP reservation object by ID 4 | 5 | ### Synopsis 6 | 7 | Retrieve a single IP reservation object by ID 8 | 9 | ``` 10 | packet network list-ip-reservation [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-ip-reservation 17 | --reservation-id string Reservation ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet network](packet_network.md) - Manage packet network services 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_network_list-ip-reservations.md: -------------------------------------------------------------------------------- 1 | ## packet network list-ip-reservations 2 | 3 | Retrieve IP resevations for a single project 4 | 5 | ### Synopsis 6 | 7 | Retrieve IP resevations for a single project 8 | 9 | ``` 10 | packet network list-ip-reservations [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-ip-reservations 17 | --project-id string Project ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet network](packet_network.md) - Manage packet network services 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_network_list-ip.md: -------------------------------------------------------------------------------- 1 | ## packet network list-ip 2 | 3 | Retrieve IP address by ID 4 | 5 | ### Synopsis 6 | 7 | Retrieve IP address by ID 8 | 9 | ``` 10 | packet network list-ip [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --address-id string IP address ID 17 | -h, --help help for list-ip 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet network](packet_network.md) - Manage packet network services 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_network_remove-ip-reservation.md: -------------------------------------------------------------------------------- 1 | ## packet network remove-ip-reservation 2 | 3 | Remove IP reservation 4 | 5 | ### Synopsis 6 | 7 | Remove IP reservation 8 | 9 | ``` 10 | packet network remove-ip-reservation [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for remove-ip-reservation 17 | --reservation-id string Reservation ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet network](packet_network.md) - Manage packet network services 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_network_request-more-ip-reservations.md: -------------------------------------------------------------------------------- 1 | ## packet network request-more-ip-reservations 2 | 3 | Request more IP space 4 | 5 | ### Synopsis 6 | 7 | Request more IP space 8 | 9 | ``` 10 | packet network request-more-ip-reservations [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --comments string Comment to Packet team 17 | -h, --help help for request-more-ip-reservations 18 | --project-id string Project ID 19 | --quantity int How many IPv4 you want to request. Options: 1, 2, 4, 8, 16, 32, 64, 128, 256 (default 1) 20 | --type string public_ipv4 || global_ipv4 (default "public_ipv4") 21 | ``` 22 | 23 | ### Options inherited from parent commands 24 | 25 | ``` 26 | -k, --key string API key 27 | -p, --profile string Profile name (default "default") 28 | ``` 29 | 30 | ### SEE ALSO 31 | 32 | * [packet network](packet_network.md) - Manage packet network services 33 | 34 | ###### Auto generated by spf13/cobra on 4-Jun-2018 35 | -------------------------------------------------------------------------------- /doc/packet_network_unassign-ip.md: -------------------------------------------------------------------------------- 1 | ## packet network unassign-ip 2 | 3 | Unassign IP address from a device 4 | 5 | ### Synopsis 6 | 7 | Unassign IP address from a device 8 | 9 | ``` 10 | packet network unassign-ip [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --address-id string IP address ID 17 | -h, --help help for unassign-ip 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet network](packet_network.md) - Manage packet network services 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage.md: -------------------------------------------------------------------------------- 1 | ## packet storage 2 | 3 | Manage your storages 4 | 5 | ### Synopsis 6 | 7 | Manage your storages 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for storage 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | -k, --key string API key 19 | -p, --profile string Profile name (default "default") 20 | ``` 21 | 22 | ### SEE ALSO 23 | 24 | * [packet](packet.md) - CLI tool to manage packet.net services 25 | * [packet storage attach-volume](packet_storage_attach-volume.md) - Attach a volume to a device 26 | * [packet storage clone-volume](packet_storage_clone-volume.md) - Clone a volume or snapshot into a new volume 27 | * [packet storage create-snapshot](packet_storage_create-snapshot.md) - Create a snapshot of your volume 28 | * [packet storage create-snapshot-policy](packet_storage_create-snapshot-policy.md) - Create a snapshot policy 29 | * [packet storage create-volume](packet_storage_create-volume.md) - Create a volume 30 | * [packet storage delete-snapshot](packet_storage_delete-snapshot.md) - Delete a snapshot of your volume 31 | * [packet storage delete-snapshot-policy](packet_storage_delete-snapshot-policy.md) - Delete a snapshot policy 32 | * [packet storage delete-volume](packet_storage_delete-volume.md) - Delete storage 33 | * [packet storage detach-volume](packet_storage_detach-volume.md) - Detach a volume from a device 34 | * [packet storage list-snapshots](packet_storage_list-snapshots.md) - View a list of the current volume’s snapshots 35 | * [packet storage list-volume](packet_storage_list-volume.md) - Retrieve a volume by ID 36 | * [packet storage list-volume-events](packet_storage_list-volume-events.md) - View a list of the current volume's events 37 | * [packet storage list-volumes](packet_storage_list-volumes.md) - Retrieve all volumes 38 | * [packet storage restore-volume](packet_storage_restore-volume.md) - Restore a volume to the given snapshot 39 | * [packet storage update-snapshot-policy](packet_storage_update-snapshot-policy.md) - Update a snapshot policy 40 | * [packet storage update-volume](packet_storage_update-volume.md) - Update a volume 41 | 42 | ###### Auto generated by spf13/cobra on 4-Jun-2018 43 | -------------------------------------------------------------------------------- /doc/packet_storage_attach-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage attach-volume 2 | 3 | Attach a volume to a device 4 | 5 | ### Synopsis 6 | 7 | Attach a volume to a device 8 | 9 | ``` 10 | packet storage attach-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --device-id string Device ID 17 | -h, --help help for attach-volume 18 | --volume-id string Volume ID 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | -k, --key string API key 25 | -p, --profile string Profile name (default "default") 26 | ``` 27 | 28 | ### SEE ALSO 29 | 30 | * [packet storage](packet_storage.md) - Manage your storages 31 | 32 | ###### Auto generated by spf13/cobra on 4-Jun-2018 33 | -------------------------------------------------------------------------------- /doc/packet_storage_clone-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage clone-volume 2 | 3 | Clone a volume or snapshot into a new volume 4 | 5 | ### Synopsis 6 | 7 | Clone a volume or snapshot into a new volume 8 | 9 | ``` 10 | packet storage clone-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for clone-volume 17 | --snapshot-timestamp string Snapshot timestamp(optional) 18 | --volume-id string Volume ID 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | -k, --key string API key 25 | -p, --profile string Profile name (default "default") 26 | ``` 27 | 28 | ### SEE ALSO 29 | 30 | * [packet storage](packet_storage.md) - Manage your storages 31 | 32 | ###### Auto generated by spf13/cobra on 4-Jun-2018 33 | -------------------------------------------------------------------------------- /doc/packet_storage_create-snapshot-policy.md: -------------------------------------------------------------------------------- 1 | ## packet storage create-snapshot-policy 2 | 3 | Create a snapshot policy 4 | 5 | ### Synopsis 6 | 7 | Create a snapshot policy 8 | 9 | ``` 10 | packet storage create-snapshot-policy [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --count int Snapshots count (default 1) 17 | --frequency string Snapshot frequency 18 | -h, --help help for create-snapshot-policy 19 | --volume-id string Volume ID 20 | ``` 21 | 22 | ### Options inherited from parent commands 23 | 24 | ``` 25 | -k, --key string API key 26 | -p, --profile string Profile name (default "default") 27 | ``` 28 | 29 | ### SEE ALSO 30 | 31 | * [packet storage](packet_storage.md) - Manage your storages 32 | 33 | ###### Auto generated by spf13/cobra on 4-Jun-2018 34 | -------------------------------------------------------------------------------- /doc/packet_storage_create-snapshot.md: -------------------------------------------------------------------------------- 1 | ## packet storage create-snapshot 2 | 3 | Create a snapshot of your volume 4 | 5 | ### Synopsis 6 | 7 | Create a snapshot of your volume 8 | 9 | ``` 10 | packet storage create-snapshot [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for create-snapshot 17 | --volume-id string volume ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_create-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage create-volume 2 | 3 | Create a volume 4 | 5 | ### Synopsis 6 | 7 | Create a volume 8 | 9 | ``` 10 | packet storage create-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --count int Snapshots count (default 4) 17 | --desc string Description 18 | --facility string ewr1 || sjc1 || ams1 (default "ewr1") 19 | --frequency string Snapshot frequency (default "15min") 20 | -h, --help help for create-volume 21 | --plan string storage_1 || storage_2 (default "storage_1") 22 | --project-id string Project ID 23 | --size int Volume size (default 120) 24 | ``` 25 | 26 | ### Options inherited from parent commands 27 | 28 | ``` 29 | -k, --key string API key 30 | -p, --profile string Profile name (default "default") 31 | ``` 32 | 33 | ### SEE ALSO 34 | 35 | * [packet storage](packet_storage.md) - Manage your storages 36 | 37 | ###### Auto generated by spf13/cobra on 4-Jun-2018 38 | -------------------------------------------------------------------------------- /doc/packet_storage_delete-snapshot-policy.md: -------------------------------------------------------------------------------- 1 | ## packet storage delete-snapshot-policy 2 | 3 | Delete a snapshot policy 4 | 5 | ### Synopsis 6 | 7 | Delete a snapshot policy 8 | 9 | ``` 10 | packet storage delete-snapshot-policy [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-snapshot-policy 17 | --policy-id string Snapshot policy ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_delete-snapshot.md: -------------------------------------------------------------------------------- 1 | ## packet storage delete-snapshot 2 | 3 | Delete a snapshot of your volume 4 | 5 | ### Synopsis 6 | 7 | Delete a snapshot of your volume 8 | 9 | ``` 10 | packet storage delete-snapshot [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-snapshot 17 | --snapshot-id string Snapshot policy ID 18 | --volume-id string Volume ID 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | -k, --key string API key 25 | -p, --profile string Profile name (default "default") 26 | ``` 27 | 28 | ### SEE ALSO 29 | 30 | * [packet storage](packet_storage.md) - Manage your storages 31 | 32 | ###### Auto generated by spf13/cobra on 4-Jun-2018 33 | -------------------------------------------------------------------------------- /doc/packet_storage_delete-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage delete-volume 2 | 3 | Delete storage 4 | 5 | ### Synopsis 6 | 7 | Delete storage 8 | 9 | ``` 10 | packet storage delete-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for delete-volume 17 | --volume-id string Volume ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_detach-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage detach-volume 2 | 3 | Detach a volume from a device 4 | 5 | ### Synopsis 6 | 7 | Detach a volume from a device 8 | 9 | ``` 10 | packet storage detach-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --attachement-id string Attachment ID 17 | -h, --help help for detach-volume 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_list-snapshots.md: -------------------------------------------------------------------------------- 1 | ## packet storage list-snapshots 2 | 3 | View a list of the current volume’s snapshots 4 | 5 | ### Synopsis 6 | 7 | View a list of the current volume’s snapshots 8 | 9 | ``` 10 | packet storage list-snapshots [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-snapshots 17 | --volume-id string Volume ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_list-volume-events.md: -------------------------------------------------------------------------------- 1 | ## packet storage list-volume-events 2 | 3 | View a list of the current volume's events 4 | 5 | ### Synopsis 6 | 7 | View a list of the current volume's events 8 | 9 | ``` 10 | packet storage list-volume-events [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-volume-events 17 | --volume-id string Volume ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_list-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage list-volume 2 | 3 | Retrieve a volume by ID 4 | 5 | ### Synopsis 6 | 7 | Retrieve a volume by ID 8 | 9 | ``` 10 | packet storage list-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-volume 17 | --volume-id string Volume ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_list-volumes.md: -------------------------------------------------------------------------------- 1 | ## packet storage list-volumes 2 | 3 | Retrieve all volumes 4 | 5 | ### Synopsis 6 | 7 | Retrieve all volumes 8 | 9 | ``` 10 | packet storage list-volumes [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list-volumes 17 | --project-id string Project ID 18 | ``` 19 | 20 | ### Options inherited from parent commands 21 | 22 | ``` 23 | -k, --key string API key 24 | -p, --profile string Profile name (default "default") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [packet storage](packet_storage.md) - Manage your storages 30 | 31 | ###### Auto generated by spf13/cobra on 4-Jun-2018 32 | -------------------------------------------------------------------------------- /doc/packet_storage_restore-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage restore-volume 2 | 3 | Restore a volume to the given snapshot 4 | 5 | ### Synopsis 6 | 7 | Restore a volume to the given snapshot 8 | 9 | ``` 10 | packet storage restore-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for restore-volume 17 | --restore-point string Restore point in the form of a Unix timestamp 18 | --volume-id string Volume ID 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | -k, --key string API key 25 | -p, --profile string Profile name (default "default") 26 | ``` 27 | 28 | ### SEE ALSO 29 | 30 | * [packet storage](packet_storage.md) - Manage your storages 31 | 32 | ###### Auto generated by spf13/cobra on 4-Jun-2018 33 | -------------------------------------------------------------------------------- /doc/packet_storage_update-snapshot-policy.md: -------------------------------------------------------------------------------- 1 | ## packet storage update-snapshot-policy 2 | 3 | Update a snapshot policy 4 | 5 | ### Synopsis 6 | 7 | Update a snapshot policy 8 | 9 | ``` 10 | packet storage update-snapshot-policy [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --count int Snapshots count (default 4) 17 | --frequency string Snapshot frequency (default "15min") 18 | -h, --help help for update-snapshot-policy 19 | --policy-id string Snapshot policy ID 20 | ``` 21 | 22 | ### Options inherited from parent commands 23 | 24 | ``` 25 | -k, --key string API key 26 | -p, --profile string Profile name (default "default") 27 | ``` 28 | 29 | ### SEE ALSO 30 | 31 | * [packet storage](packet_storage.md) - Manage your storages 32 | 33 | ###### Auto generated by spf13/cobra on 4-Jun-2018 34 | -------------------------------------------------------------------------------- /doc/packet_storage_update-volume.md: -------------------------------------------------------------------------------- 1 | ## packet storage update-volume 2 | 3 | Update a volume 4 | 5 | ### Synopsis 6 | 7 | Update a volume 8 | 9 | ``` 10 | packet storage update-volume [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | --desc string Description 17 | -h, --help help for update-volume 18 | --lock Update and lock 19 | --size int Volume size (default 120) 20 | --volume-id string Volume ID 21 | ``` 22 | 23 | ### Options inherited from parent commands 24 | 25 | ``` 26 | -k, --key string API key 27 | -p, --profile string Profile name (default "default") 28 | ``` 29 | 30 | ### SEE ALSO 31 | 32 | * [packet storage](packet_storage.md) - Manage your storages 33 | 34 | ###### Auto generated by spf13/cobra on 4-Jun-2018 35 | -------------------------------------------------------------------------------- /extpackngo/events.go: -------------------------------------------------------------------------------- 1 | package extpackngo 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/packethost/packngo" 7 | ) 8 | 9 | const eventBasePath = "/events" 10 | 11 | // EventService interface defines available event methods 12 | type EventService interface { 13 | ListProjectEvents(projectID string) ([]Event, *Response, error) 14 | ListDeviceEvents(deviceID string) ([]Event, *Response, error) 15 | ListStorageEvents(storageID string) ([]Event, *Response, error) 16 | // Get(string) (*Event, *Response, error) 17 | } 18 | 19 | type eventsRoot struct { 20 | Events []Event `json:"events"` 21 | } 22 | 23 | // Event represents a Packet Event 24 | type Event struct { 25 | ID string `json:"id"` 26 | Type string `json:"type"` 27 | Body string `json:"body"` 28 | Create string `json:"created_at"` 29 | Interpolated string `json:"interpolated"` 30 | Href string `json:"href"` 31 | Relationships []map[string]string `json:"relationships"` 32 | } 33 | 34 | func (e Event) String() string { 35 | return packngo.Stringify(e) 36 | } 37 | 38 | // EventServiceOp implements EventService 39 | type EventServiceOp struct { 40 | client *Client 41 | } 42 | 43 | // ListDeviceEvents returns Events of a device 44 | func (e *EventServiceOp) ListDeviceEvents(deviceID string) ([]Event, *Response, error) { 45 | path := fmt.Sprintf("devices/%s/%s", deviceID, eventBasePath) 46 | 47 | req, err := e.client.NewRequest("GET", path, nil) 48 | if err != nil { 49 | return nil, nil, err 50 | } 51 | 52 | root := new(eventsRoot) 53 | resp, err := e.client.Do(req, root) 54 | if err != nil { 55 | return nil, resp, err 56 | } 57 | 58 | return root.Events, resp, err 59 | } 60 | 61 | // ListProjectEvents returns Events of a project 62 | func (e *EventServiceOp) ListProjectEvents(projectID string) ([]Event, *Response, error) { 63 | path := fmt.Sprintf("projects/%s/%s", projectID, eventBasePath) 64 | 65 | req, err := e.client.NewRequest("GET", path, nil) 66 | if err != nil { 67 | return nil, nil, err 68 | } 69 | 70 | root := new(eventsRoot) 71 | resp, err := e.client.Do(req, root) 72 | if err != nil { 73 | return nil, resp, err 74 | } 75 | 76 | return root.Events, resp, err 77 | } 78 | 79 | // ListStorageEvents returns Events of a project 80 | func (e *EventServiceOp) ListStorageEvents(storageID string) ([]Event, *Response, error) { 81 | path := fmt.Sprintf("volumes/%s/events", storageID) 82 | 83 | req, err := e.client.NewRequest("GET", path, nil) 84 | if err != nil { 85 | return nil, nil, err 86 | } 87 | 88 | root := new(eventsRoot) 89 | resp, err := e.client.Do(req, root) 90 | if err != nil { 91 | return nil, resp, err 92 | } 93 | 94 | return root.Events, resp, err 95 | } 96 | 97 | /* Get returns and event by ID 98 | func (e *EventServiceOp) Get(eventID string) (*Event, *Response, error) { 99 | path := fmt.Sprintf("%s/%s", eventBasePath, eventID) 100 | 101 | req, err := e.client.NewRequest("GET", path, nil) 102 | if err != nil { 103 | return nil, nil, err 104 | } 105 | 106 | event := new(Event) 107 | resp, err := e.client.Do(req, event) 108 | if err != nil { 109 | return nil, resp, err 110 | } 111 | 112 | return event, resp, err 113 | } 114 | */ 115 | -------------------------------------------------------------------------------- /extpackngo/extpackngo.go: -------------------------------------------------------------------------------- 1 | // Package extpackngo is an extension of packngo, the official packet.net library. 2 | // It implements APIs missing in the packngo library. 3 | package extpackngo 4 | 5 | import ( 6 | "bytes" 7 | "encoding/json" 8 | "fmt" 9 | "io" 10 | "io/ioutil" 11 | "net/http" 12 | "net/url" 13 | "strconv" 14 | "strings" 15 | "time" 16 | 17 | "github.com/packethost/packngo" 18 | ) 19 | 20 | const ( 21 | libraryVersion = "0.1.0" 22 | baseURL = "https://api.packet.net/" 23 | userAgent = "packngo/" + libraryVersion 24 | mediaType = "application/json" 25 | 26 | headerRateLimit = "X-RateLimit-Limit" 27 | headerRateRemaining = "X-RateLimit-Remaining" 28 | headerRateReset = "X-RateLimit-Reset" 29 | ) 30 | 31 | // ListOptions specifies optional global API parameters 32 | type ListOptions struct { 33 | // for paginated result sets, page of results to retrieve 34 | Page int `url:"page,omitempty"` 35 | 36 | // for paginated result sets, the number of results to return per page 37 | PerPage int `url:"per_page,omitempty"` 38 | 39 | // specify which resources you want to return as collections instead of references 40 | Includes string 41 | } 42 | 43 | // Response is the http response from api calls 44 | type Response struct { 45 | *http.Response 46 | packngo.Rate 47 | } 48 | 49 | func (r *Response) populateRate() { 50 | // parse the rate limit headers and populate Response.Rate 51 | if limit := r.Header.Get(headerRateLimit); limit != "" { 52 | r.Rate.RequestLimit, _ = strconv.Atoi(limit) 53 | } 54 | if remaining := r.Header.Get(headerRateRemaining); remaining != "" { 55 | r.Rate.RequestsRemaining, _ = strconv.Atoi(remaining) 56 | } 57 | if reset := r.Header.Get(headerRateReset); reset != "" { 58 | if v, _ := strconv.ParseInt(reset, 10, 64); v != 0 { 59 | r.Rate.Reset = packngo.Timestamp{time.Unix(v, 0)} 60 | } 61 | } 62 | } 63 | 64 | // ErrorResponse is the http response used on errrors 65 | type ErrorResponse struct { 66 | Response *http.Response 67 | Errors []string `json:"errors"` 68 | } 69 | 70 | func (r *ErrorResponse) Error() string { 71 | return fmt.Sprintf("%v %v: %d %v", 72 | r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, strings.Join(r.Errors, ", ")) 73 | } 74 | 75 | // Client is the base API Client 76 | type Client struct { 77 | client *http.Client 78 | 79 | BaseURL *url.URL 80 | 81 | UserAgent string 82 | ConsumerToken string 83 | APIKey string 84 | 85 | RateLimit packngo.Rate 86 | 87 | // Packet Api Objects 88 | Events EventService 89 | IPs IPService 90 | IPReservations IPReservationService 91 | Storages StorageService 92 | } 93 | 94 | // NewRequest inits a new http request with the proper headers 95 | func (c *Client) NewRequest(method, path string, body interface{}) (*http.Request, error) { 96 | // relative path to append to the endpoint url, no leading slash please 97 | rel, err := url.Parse(path) 98 | if err != nil { 99 | return nil, err 100 | } 101 | 102 | u := c.BaseURL.ResolveReference(rel) 103 | 104 | // json encode the request body, if any 105 | buf := new(bytes.Buffer) 106 | if body != nil { 107 | err := json.NewEncoder(buf).Encode(body) 108 | if err != nil { 109 | return nil, err 110 | } 111 | } 112 | 113 | req, err := http.NewRequest(method, u.String(), buf) 114 | if err != nil { 115 | return nil, err 116 | } 117 | 118 | req.Close = true 119 | 120 | req.Header.Add("X-Auth-Token", c.APIKey) 121 | req.Header.Add("X-Consumer-Token", c.ConsumerToken) 122 | 123 | req.Header.Add("Content-Type", mediaType) 124 | req.Header.Add("Accept", mediaType) 125 | req.Header.Add("User-Agent", userAgent) 126 | return req, nil 127 | } 128 | 129 | // Do executes the http request 130 | func (c *Client) Do(req *http.Request, v interface{}) (*Response, error) { 131 | resp, err := c.client.Do(req) 132 | if err != nil { 133 | return nil, err 134 | } 135 | 136 | defer resp.Body.Close() 137 | 138 | response := Response{Response: resp} 139 | response.populateRate() 140 | c.RateLimit = response.Rate 141 | 142 | err = checkResponse(resp) 143 | // if the response is an error, return the ErrorResponse 144 | if err != nil { 145 | return &response, err 146 | } 147 | 148 | if v != nil { 149 | // if v implements the io.Writer interface, return the raw response 150 | if w, ok := v.(io.Writer); ok { 151 | io.Copy(w, resp.Body) 152 | } else { 153 | err = json.NewDecoder(resp.Body).Decode(v) 154 | if err != nil { 155 | return &response, err 156 | } 157 | } 158 | } 159 | 160 | return &response, err 161 | } 162 | 163 | // NewClient initializes and returns a Client, use this to get an API Client to operate on 164 | // N.B.: Packet's API certificate requires Go 1.5+ to successfully parse. If you are using 165 | // an older version of Go, pass in a custom http.Client with a custom TLS configuration 166 | // that sets "InsecureSkipVerify" to "true" 167 | func NewClient(consumerToken string, apiKey string, httpClient *http.Client) *Client { 168 | if httpClient == nil { 169 | // Don't fall back on http.DefaultClient as it's not nice to adjust state 170 | // implicitly. If the client wants to use http.DefaultClient, they can 171 | // pass it in explicitly. 172 | httpClient = &http.Client{} 173 | } 174 | 175 | BaseURL, _ := url.Parse(baseURL) 176 | 177 | c := &Client{client: httpClient, BaseURL: BaseURL, UserAgent: userAgent, ConsumerToken: consumerToken, APIKey: apiKey} 178 | c.Events = &EventServiceOp{client: c} 179 | c.IPs = &IPServiceOp{client: c} 180 | c.IPReservations = &IPReservationServiceOp{client: c} 181 | c.Storages = &StorageServiceOP{client: c} 182 | return c 183 | } 184 | 185 | func checkResponse(r *http.Response) error { 186 | // return if http status code is within 200 range 187 | if c := r.StatusCode; c >= 200 && c <= 299 { 188 | // response is good, return 189 | return nil 190 | } 191 | 192 | errorResponse := &ErrorResponse{Response: r} 193 | data, err := ioutil.ReadAll(r.Body) 194 | // if the response has a body, populate the message in errorResponse 195 | if err == nil && len(data) > 0 { 196 | json.Unmarshal(data, errorResponse) 197 | } 198 | 199 | return errorResponse 200 | } 201 | -------------------------------------------------------------------------------- /extpackngo/ip.go: -------------------------------------------------------------------------------- 1 | package extpackngo 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/packethost/packngo" 7 | ) 8 | 9 | // IP API 10 | 11 | // IPBasePath ... 12 | const IPBasePath = "/ips" 13 | 14 | // IPService interface defines available IP methods 15 | type IPService interface { 16 | Assign(deviceID string, assignRequest *IPAddressAssignRequest) (*IPAddress, *Response, error) 17 | Unassign(ipAddressID string) (*Response, error) 18 | Get(ipAddressID string) (*IPAddress, *Response, error) 19 | } 20 | 21 | // IPAddress represents a ip address 22 | type IPAddress struct { 23 | ID string `json:"id"` 24 | Address string `json:"address"` 25 | Network string `json:"network"` 26 | AddressFamily int `json:"address_family"` 27 | Netmask string `json:"netmask"` 28 | Public bool `json:"public"` 29 | Cidr int `json:"cidr"` 30 | AssignedTo map[string]string `json:"assigned_to"` 31 | Href string `json:"href"` 32 | } 33 | 34 | // IPAddressAssignRequest represents the body if a ip assign request 35 | type IPAddressAssignRequest struct { 36 | Address string `json:"address"` 37 | } 38 | 39 | func (i IPAddress) String() string { 40 | return packngo.Stringify(i) 41 | } 42 | 43 | // IPServiceOp implements IPService 44 | type IPServiceOp struct { 45 | client *Client 46 | } 47 | 48 | // Get returns IpAddress by ID 49 | func (i *IPServiceOp) Get(ipAddressID string) (*IPAddress, *Response, error) { 50 | path := fmt.Sprintf("%s/%s", IPBasePath, ipAddressID) 51 | 52 | req, err := i.client.NewRequest("GET", path, nil) 53 | if err != nil { 54 | return nil, nil, err 55 | } 56 | 57 | ip := new(IPAddress) 58 | resp, err := i.client.Do(req, ip) 59 | if err != nil { 60 | return nil, resp, err 61 | } 62 | 63 | return ip, resp, err 64 | } 65 | 66 | // Unassign unassigns an IP address record. This will remove the relationship between an IP 67 | // and the device and will make the IP address available to be assigned to another device. 68 | func (i *IPServiceOp) Unassign(ipAddressID string) (*Response, error) { 69 | path := fmt.Sprintf("%s/%s", IPBasePath, ipAddressID) 70 | 71 | req, err := i.client.NewRequest("DELETE", path, nil) 72 | if err != nil { 73 | return nil, err 74 | } 75 | 76 | resp, err := i.client.Do(req, nil) 77 | return resp, err 78 | } 79 | 80 | // Assign assigns an IP address to a device. The IP address must be in one of the IP ranges assigned to the device’s project. 81 | func (i *IPServiceOp) Assign(deviceID string, assignRequest *IPAddressAssignRequest) (*IPAddress, *Response, error) { 82 | path := fmt.Sprintf("devices/%s%s", deviceID, IPBasePath) 83 | 84 | req, err := i.client.NewRequest("POST", path, assignRequest) 85 | 86 | ip := new(IPAddress) 87 | resp, err := i.client.Do(req, ip) 88 | if err != nil { 89 | return nil, resp, err 90 | } 91 | 92 | return ip, resp, err 93 | } 94 | 95 | // IP RESERVATIONS API 96 | 97 | // IPReservationService interface defines available IPReservation methods 98 | type IPReservationService interface { 99 | List(projectID string) ([]IPReservation, *Response, error) 100 | RequestMore(projectID string, ipReservationReq *IPReservationRequest) (*Response, error) 101 | Get(ipReservationID string) (*IPReservation, *Response, error) 102 | Remove(ipReservationID string) (*Response, error) 103 | } 104 | 105 | // IPReservationServiceOp implements the IPReservationService interface 106 | type IPReservationServiceOp struct { 107 | client *Client 108 | } 109 | 110 | // IPReservationRequest represents the body of a reservation request 111 | type IPReservationRequest struct { 112 | Type string `json:"type"` 113 | Quantity int `json:"quantity"` 114 | Comments string `json:"comments"` 115 | } 116 | 117 | // IPReservation represent an IP reservation for a single project 118 | type IPReservation struct { 119 | ID string `json:"id"` 120 | Network string `json:"network"` 121 | Address string `json:"address"` 122 | AddressFamily int `json:"address_family"` 123 | Netmask string `json:"netmask"` 124 | Public bool `json:"public"` 125 | Cidr int `json:"cidr"` 126 | Management bool `json:"management"` 127 | Manageable bool `json:"manageable"` 128 | Addon bool `json:"addon"` 129 | Bill bool `json:"bill"` 130 | Assignments []map[string]string `json:"assignments"` 131 | Href string `json:"href"` 132 | } 133 | 134 | type ipReservationRoot struct { 135 | IPReservations []IPReservation `json:"ip_addresses"` 136 | } 137 | 138 | // List provides a list of IP resevations for a single project. 139 | func (i *IPReservationServiceOp) List(projectID string) ([]IPReservation, *Response, error) { 140 | path := fmt.Sprintf("projects/%s%s", projectID, IPBasePath) 141 | 142 | req, err := i.client.NewRequest("GET", path, nil) 143 | if err != nil { 144 | return nil, nil, err 145 | } 146 | 147 | reservations := new(ipReservationRoot) 148 | resp, err := i.client.Do(req, reservations) 149 | if err != nil { 150 | return nil, resp, err 151 | } 152 | return reservations.IPReservations, resp, err 153 | } 154 | 155 | // RequestMore requests more IP space for a project in order to have additional IP addresses to assign to devices 156 | func (i *IPReservationServiceOp) RequestMore(projectID string, ipReservationReq *IPReservationRequest) (*Response, error) { 157 | path := fmt.Sprintf("projects/%s%s", projectID, IPBasePath) 158 | 159 | req, err := i.client.NewRequest("POST", path, &ipReservationReq) 160 | if err != nil { 161 | return nil, err 162 | } 163 | 164 | resp, err := i.client.Do(req, nil) 165 | if err != nil { 166 | return nil, err 167 | } 168 | return resp, err 169 | } 170 | 171 | // Get returns a single IP reservation object 172 | func (i *IPReservationServiceOp) Get(ipReservationID string) (*IPReservation, *Response, error) { 173 | path := fmt.Sprintf("%s/%s", IPBasePath, ipReservationID) 174 | 175 | req, err := i.client.NewRequest("GET", path, nil) 176 | if err != nil { 177 | return nil, nil, err 178 | } 179 | 180 | reservation := new(IPReservation) 181 | resp, err := i.client.Do(req, reservation) 182 | if err != nil { 183 | return nil, nil, err 184 | } 185 | 186 | return reservation, resp, err 187 | } 188 | 189 | // Remove removes an IP reservation from the project. 190 | func (i *IPReservationServiceOp) Remove(ipReservationID string) (*Response, error) { 191 | path := fmt.Sprintf("%s/%s", IPBasePath, ipReservationID) 192 | 193 | req, err := i.client.NewRequest("DELETE", path, nil) 194 | if err != nil { 195 | return nil, err 196 | } 197 | 198 | resp, err := i.client.Do(req, nil) 199 | if err != nil { 200 | return nil, err 201 | } 202 | 203 | return resp, err 204 | } 205 | -------------------------------------------------------------------------------- /extpackngo/volumes.go: -------------------------------------------------------------------------------- 1 | package extpackngo 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/packethost/packngo" 7 | ) 8 | 9 | const storageBasePath = "/storage" 10 | 11 | // StorageService interface defines available storage methods 12 | type StorageService interface { 13 | List(projectID string) ([]Storage, *Response, error) 14 | Create(projectID string, request *StorageCreateRequest) (*Storage, *Response, error) 15 | Get(storageID string) (*Storage, *Response, error) 16 | Update(storageID string, request *StorageUpdateRequest) (*Response, error) 17 | Delete(storageID string) (*Response, error) 18 | CreateSnapshotPolicy(storageID string, request *CreateSnapshotPolicyRequest) (*Response, error) 19 | UpdateSnapshotPolicy(snapshotPolicyID string, request *UpdateSnapshotPolicyRequest) (*Response, error) 20 | DeleteSnapshotPolicy(snapshotPolicyID string) (*Response, error) 21 | ListSnapshots(storageID string) ([]Snapshot, *Response, error) 22 | CreateSnapshot(storageID string, request *CreateSnapShotRequest) (*Response, error) 23 | DeleteSnapshot(storageID, snapshotID string) (*Response, error) 24 | Restore(storageID string, request *RestoreVolumeRequest) (*Response, error) 25 | Clone(storageID string, request *CloneVolumeRequest) (*Response, error) 26 | Attach(storageID string, request *AttachStorageRequest) (*Response, error) 27 | Detach(attachmentID string) (*Response, error) 28 | } 29 | 30 | // StorageServiceOP implements the StorageService interface 31 | type StorageServiceOP struct { 32 | client *Client 33 | } 34 | 35 | // Storage represents a packet block storage 36 | type Storage struct { 37 | ID string `json:"id"` 38 | Name string `json:"name"` 39 | Description string `json:"description"` 40 | Size int `json:"size"` 41 | Locked bool `json:"locked"` 42 | BillingCycle string `json:"billing_cycle"` 43 | State string `json:"state"` 44 | Create string `json:"created_at"` 45 | Update string `json:"updated_at"` 46 | Project map[string]string `json:"project"` 47 | Facility map[string]string `json:"facility"` 48 | SnapshotPolicies []map[string]string `json:"snapshot_policies"` 49 | Attachements []map[string]string `json:"attachments"` 50 | Plan packngo.Plan `json:"plan"` 51 | Href string `json:"href"` 52 | } 53 | 54 | // StorageCreateRequest represents the body of a storage create request 55 | type StorageCreateRequest struct { 56 | Description string `json:"description"` 57 | Plan string `json:"plan"` 58 | Size int `json:"size"` 59 | Facility string `json:"facility"` 60 | SnapshotPolicies []*SnapshotPolicy `json:"snapshot_policies"` 61 | } 62 | 63 | // StorageUpdateRequest represents the body of a storage update request 64 | type StorageUpdateRequest struct { 65 | Description string `json:"description"` 66 | Size int `json:"size"` 67 | Locked bool `json:"size"` 68 | } 69 | 70 | // SnapshotPolicy represents a snapshot policy 71 | type SnapshotPolicy struct { 72 | SnapshotCount int `json:"snapshot_count"` 73 | SnapshotFrequency string `json:"snapshot_frequency"` 74 | } 75 | 76 | // CreateSnapshotPolicyRequest represents the body of a create snapshot policy request 77 | type CreateSnapshotPolicyRequest struct { 78 | SnapshotCount int `json:"snapshot_count"` 79 | SnapshotFrequency string `json:"snapshot_frequency"` 80 | } 81 | 82 | // UpdateSnapshotPolicyRequest represents the body of a update snapshot policy request 83 | type UpdateSnapshotPolicyRequest struct { 84 | SnapshotCount int `json:"snapshot_count"` 85 | SnapshotFrequency string `json:"snapshot_frequency"` 86 | } 87 | 88 | // Snapshot reprensents a snapshot 89 | type Snapshot struct { 90 | ID string `json:"id"` 91 | Status string `json:"status"` 92 | Create string `json:"created_at"` 93 | Volume map[string]string `json:"volume"` 94 | } 95 | 96 | type snapshotsRoot struct { 97 | Snapshots []Snapshot `json:"snapshots"` 98 | } 99 | 100 | // CreateSnapShotRequest represents the body of a snapshot create request 101 | type CreateSnapShotRequest struct { 102 | } 103 | 104 | // AttachStorageRequest represents the body of a attach storage request 105 | type AttachStorageRequest struct { 106 | DeviceID string `json:"device_id"` 107 | } 108 | 109 | // RestoreVolumeRequest represents the body of a restore request 110 | type RestoreVolumeRequest struct { 111 | RestorePoint string `json:"restore_point"` 112 | } 113 | 114 | // CloneVolumeRequest represents the body of a restore request 115 | type CloneVolumeRequest struct { 116 | SnapshotTimestamp string `json:"snapshot_timestamp,omitempty"` 117 | } 118 | 119 | type volumesRoot struct { 120 | Volumes []Storage `json:"volumes"` 121 | } 122 | 123 | // List returns a list of the current projects’s volumes 124 | func (s *StorageServiceOP) List(projectID string) ([]Storage, *Response, error) { 125 | path := fmt.Sprintf("projects/%s%s", projectID, storageBasePath) 126 | 127 | req, err := s.client.NewRequest("GET", path, nil) 128 | if err != nil { 129 | return nil, nil, err 130 | } 131 | 132 | root := new(volumesRoot) 133 | resp, err := s.client.Do(req, root) 134 | if err != nil { 135 | return nil, resp, err 136 | } 137 | 138 | return root.Volumes, resp, err 139 | } 140 | 141 | // Create creates a new volume 142 | func (s *StorageServiceOP) Create(projectID string, request *StorageCreateRequest) (*Storage, *Response, error) { 143 | path := fmt.Sprintf("projects/%s%s", projectID, storageBasePath) 144 | 145 | req, err := s.client.NewRequest("POST", path, request) 146 | if err != nil { 147 | return nil, nil, err 148 | } 149 | 150 | storage := new(Storage) 151 | resp, err := s.client.Do(req, storage) 152 | if err != nil { 153 | return nil, nil, err 154 | } 155 | 156 | return storage, resp, err 157 | } 158 | 159 | // Get returns a volume by ID 160 | func (s *StorageServiceOP) Get(storageID string) (*Storage, *Response, error) { 161 | path := fmt.Sprintf("%s/%s", storageBasePath, storageID) 162 | 163 | req, err := s.client.NewRequest("GET", path, nil) 164 | if err != nil { 165 | return nil, nil, err 166 | } 167 | 168 | storage := new(Storage) 169 | resp, err := s.client.Do(req, storage) 170 | if err != nil { 171 | return nil, nil, err 172 | } 173 | 174 | return storage, resp, err 175 | } 176 | 177 | // Update updates a volume 178 | func (s *StorageServiceOP) Update(storateID string, request *StorageUpdateRequest) (*Response, error) { 179 | path := fmt.Sprintf("%s/%s", storageBasePath, storateID) 180 | 181 | req, err := s.client.NewRequest("POST", path, request) 182 | if err != nil { 183 | return nil, err 184 | } 185 | 186 | resp, err := s.client.Do(req, nil) 187 | if err != nil { 188 | return nil, err 189 | } 190 | 191 | return resp, err 192 | } 193 | 194 | // Delete deletes a volume 195 | func (s *StorageServiceOP) Delete(storageID string) (*Response, error) { 196 | path := fmt.Sprintf("%s/%s", storageBasePath, storageID) 197 | 198 | req, err := s.client.NewRequest("DELETE", path, nil) 199 | if err != nil { 200 | return nil, err 201 | } 202 | 203 | resp, err := s.client.Do(req, nil) 204 | if err != nil { 205 | return nil, err 206 | } 207 | 208 | return resp, err 209 | } 210 | 211 | // CreateSnapshotPolicy creates a snapshot policy 212 | func (s *StorageServiceOP) CreateSnapshotPolicy(storageID string, request *CreateSnapshotPolicyRequest) (*Response, error) { 213 | path := fmt.Sprintf("%s/%s", storageBasePath, storageID) 214 | 215 | req, err := s.client.NewRequest("POST", path, request) 216 | if err != nil { 217 | return nil, err 218 | } 219 | 220 | resp, err := s.client.Do(req, nil) 221 | if err != nil { 222 | return nil, err 223 | } 224 | 225 | return resp, err 226 | } 227 | 228 | // UpdateSnapshotPolicy updates a snapshot policy 229 | func (s *StorageServiceOP) UpdateSnapshotPolicy(snapshotPolicyID string, request *UpdateSnapshotPolicyRequest) (*Response, error) { 230 | path := fmt.Sprintf("%s/snapshot-policies/%s", storageBasePath, snapshotPolicyID) 231 | 232 | req, err := s.client.NewRequest("POST", path, request) 233 | if err != nil { 234 | return nil, err 235 | } 236 | 237 | resp, err := s.client.Do(req, nil) 238 | if err != nil { 239 | return nil, err 240 | } 241 | 242 | return resp, err 243 | } 244 | 245 | // DeleteSnapshotPolicy deletes a snapshot policy 246 | func (s *StorageServiceOP) DeleteSnapshotPolicy(snapshotPolicyID string) (*Response, error) { 247 | path := fmt.Sprintf("%s/snapshot-policies/%s", storageBasePath, snapshotPolicyID) 248 | 249 | req, err := s.client.NewRequest("POST", path, nil) 250 | if err != nil { 251 | return nil, err 252 | } 253 | 254 | resp, err := s.client.Do(req, nil) 255 | if err != nil { 256 | return nil, err 257 | } 258 | 259 | return resp, err 260 | } 261 | 262 | // ListSnapshots returns a list of the current volume’s snapshots 263 | func (s *StorageServiceOP) ListSnapshots(storageID string) ([]Snapshot, *Response, error) { 264 | path := fmt.Sprintf("%s/%s/snapshots", storageBasePath, storageID) 265 | 266 | req, err := s.client.NewRequest("GET", path, nil) 267 | if err != nil { 268 | return nil, nil, err 269 | } 270 | 271 | root := new(snapshotsRoot) 272 | resp, err := s.client.Do(req, root) 273 | if err != nil { 274 | return nil, nil, err 275 | } 276 | 277 | return root.Snapshots, resp, err 278 | } 279 | 280 | // CreateSnapshot creates a new snapshot of your volume 281 | func (s *StorageServiceOP) CreateSnapshot(storageID string, request *CreateSnapShotRequest) (*Response, error) { 282 | path := fmt.Sprintf("%s/%s/snapshots", storageBasePath, storageID) 283 | 284 | req, err := s.client.NewRequest("POST", path, request) 285 | if err != nil { 286 | return nil, err 287 | } 288 | 289 | resp, err := s.client.Do(req, nil) 290 | if err != nil { 291 | return nil, err 292 | } 293 | 294 | return resp, err 295 | } 296 | 297 | // DeleteSnapshot deletes a snapshot 298 | func (s *StorageServiceOP) DeleteSnapshot(storageID, snapshotID string) (*Response, error) { 299 | path := fmt.Sprintf("%s/%s/snapshots/%s", storageBasePath, storageID, snapshotID) 300 | 301 | req, err := s.client.NewRequest("POST", path, nil) 302 | if err != nil { 303 | return nil, err 304 | } 305 | 306 | resp, err := s.client.Do(req, nil) 307 | if err != nil { 308 | return nil, err 309 | } 310 | 311 | return resp, err 312 | } 313 | 314 | // Attach attaches your volume to a device 315 | func (s *StorageServiceOP) Attach(storageID string, request *AttachStorageRequest) (*Response, error) { 316 | path := fmt.Sprintf("%s/%s/attachments", storageBasePath, storageID) 317 | 318 | req, err := s.client.NewRequest("POST", path, request) 319 | if err != nil { 320 | return nil, err 321 | } 322 | 323 | resp, err := s.client.Do(req, nil) 324 | if err != nil { 325 | return nil, err 326 | } 327 | 328 | return resp, err 329 | } 330 | 331 | // Detach detaches your volume from a device 332 | func (s *StorageServiceOP) Detach(attachmentID string) (*Response, error) { 333 | path := fmt.Sprintf("%s/attachments/%s", storageBasePath, attachmentID) 334 | 335 | req, err := s.client.NewRequest("DELETE", path, nil) 336 | if err != nil { 337 | return nil, err 338 | } 339 | 340 | resp, err := s.client.Do(req, nil) 341 | if err != nil { 342 | return nil, err 343 | } 344 | 345 | return resp, err 346 | } 347 | 348 | // Restore restores a volume to the given snapshot 349 | func (s *StorageServiceOP) Restore(storageID string, request *RestoreVolumeRequest) (*Response, error) { 350 | path := fmt.Sprintf("%s/%s/restore", storageBasePath, storageID) 351 | 352 | req, err := s.client.NewRequest("POST", path, request) 353 | if err != nil { 354 | return nil, err 355 | } 356 | 357 | resp, err := s.client.Do(req, nil) 358 | if err != nil { 359 | return nil, err 360 | } 361 | 362 | return resp, err 363 | } 364 | 365 | // Clone clones your volume or snapshot into a new volume. To clone the volume, send an empty body. To promote a volume snapshot into a new volume, include the snapshot_timestamp attribute in the request body. 366 | func (s *StorageServiceOP) Clone(storageID string, request *CloneVolumeRequest) (*Response, error) { 367 | path := fmt.Sprintf("%s/%s/clone", storageBasePath, storageID) 368 | 369 | req, err := s.client.NewRequest("POST", path, request) 370 | if err != nil { 371 | return nil, err 372 | } 373 | 374 | resp, err := s.client.Do(req, nil) 375 | if err != nil { 376 | return nil, err 377 | } 378 | 379 | return resp, err 380 | } 381 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/ebsarr/packet/cmd" 4 | 5 | func main() { 6 | cmd.Execute() 7 | } 8 | --------------------------------------------------------------------------------