Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getting Droplets by name #898

Merged
merged 6 commits into from Oct 28, 2020

Conversation

mamercad
Copy link
Contributor

@mamercad mamercad commented Oct 24, 2020

Might fix #895 -- I'm not very experienced in Golang.

❯ ./builds/doctl compute droplet list
ID           Name             Public IPv4       Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features              Volumes
213635352    hacktoberfest    142.93.240.125    10.116.0.2                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking    
213653028    hacktoberfest    142.93.5.117      10.116.0.3                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking
❯ ./builds/doctl compute droplet get hacktoberfest
Error: Multiple Droplets with the name "hacktoberfest" found.
❯ ./builds/doctl compute droplet delete 213653028
Warning: Are you sure you want to delete this Droplet? (y/N) ? y

New functionality:

❯ ./builds/doctl compute droplet get hacktoberfest
ID           Name             Public IPv4       Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features              Volumes
213635352    hacktoberfest    142.93.240.125    10.116.0.2                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking
❯ ./builds/doctl compute droplet delete 213635352
Warning: Are you sure you want to delete this Droplet? (y/N) ? y
❯ ./builds/doctl compute droplet get hacktoberfest
Error: Droplet with the name "hacktoberfest" could not be found.

Copy link
Member

@andrewsomething andrewsomething left a comment

Thanks for taking this on @mamercad!

In order to reduce some duplication, I think it would be best to reuse the existing matchDroplets function that is called when deleting by name.

https://github.com/digitalocean/doctl/blob/master/commands/droplets.go#L516

You can see how it gets used by the delete command here:

https://github.com/digitalocean/doctl/blob/master/commands/droplets.go#L501-L509

@mamercad
Copy link
Contributor Author

@mamercad mamercad commented Oct 27, 2020

This isn't right, still working on it.

@mamercad
Copy link
Contributor Author

@mamercad mamercad commented Oct 27, 2020

❯ ./builds/doctl compute droplet list
ID           Name             Public IPv4        Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features              Volumes
213989132    hacktoberfest    67.205.153.187     10.116.0.2                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking    
214047592    hacktoberfest    167.172.148.146    10.116.0.3                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking    
214049768    test             157.230.215.122    10.116.0.4                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking    

❯ ./builds/doctl compute droplet get hacktoberfest
Error: There are 2 Droplets with the name "hacktoberfest"; please provide a specific Droplet ID. [213989132, 214047592]

❯ ./builds/doctl compute droplet get test
ID           Name    Public IPv4        Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features              Volumes
214049768    test    157.230.215.122    10.116.0.4                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking

Seems to work now.

commands/droplets.go Outdated Show resolved Hide resolved
commands/droplets.go Outdated Show resolved Hide resolved
commands/droplets.go Outdated Show resolved Hide resolved
@mamercad
Copy link
Contributor Author

@mamercad mamercad commented Oct 27, 2020

❯ ./builds/doctl compute droplet list | grep test
214119531    test1                               64.227.3.17        10.116.0.6                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64        0c20a2e6-b9ca-43fd-8b22-def8741321ac    active                                                               private_networking    
214119620    test1                               134.122.117.15     10.116.0.7                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64        0c20a2e6-b9ca-43fd-8b22-def8741321ac    active                                                               private_networking    
214119947    test2                               157.230.232.122    10.116.0.8                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64        0c20a2e6-b9ca-43fd-8b22-def8741321ac    new                                                                  private_networking    

❯ ./builds/doctl compute droplet get test2
ID           Name     Public IPv4        Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features              Volumes
214119947    test2    157.230.232.122    10.116.0.8                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking    

❯ ./builds/doctl compute droplet get test1
Error: There are 2 Droplets with the name "test1"; please provide a specific Droplet ID. [214119531, 214119620]

❯ ./builds/doctl compute droplet get 214119531
ID           Name     Public IPv4    Private IPv4    Public IPv6    Memory    VCPUs    Disk    Region    Image                     VPC UUID                                Status    Tags    Features              Volumes
214119531    test1    64.227.3.17    10.116.0.6                     1024      1        25      nyc1      Ubuntu 20.04 (LTS) x64    0c20a2e6-b9ca-43fd-8b22-def8741321ac    active            private_networking

Copy link
Contributor Author

@mamercad mamercad left a comment

Ah, thanks for helping me, again!

Copy link
Member

@andrewsomething andrewsomething left a comment

👍 Thanks again for this! Just waiting for Travis to go green (queue times have been very long recently).

@andrewsomething andrewsomething merged commit 5cc3aeb into digitalocean:master Oct 28, 2020
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants