Code Monkey home page Code Monkey logo

droplet_kit's Introduction

DropletKit

Build Status Gem Version

DropletKit is the official DigitalOcean V2 API client. It supports everything the API can do with a simple interface written in Ruby.

Installation

Add this line to your application's Gemfile:

gem 'droplet_kit'

And then execute:

$ bundle

Or install it yourself as:

$ gem install droplet_kit

Usage

You'll need to generate an access token in DigitalOcean's control panel at https://cloud.digitalocean.com/settings/applications

Using your access token, retrieve a client instance.

require 'droplet_kit'
client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')

Timeout

You may also set timeout and time to first byte options on the client.

require 'droplet_kit'
client = DropletKit::Client.new(
  access_token: 'YOUR_TOKEN',
  open_timeout: 60, # time to first byte in seconds
  timeout:      120, # response timeout in seconds
)

Custom User-Agent

If you would like to include a custom User-Agent header beyond what DropletKit uses, you can pass one in at the client initialization like so:

require 'droplet_kit'
client = DropletKit::Client.new(access_token: 'YOUR_TOKEN', user_agent: 'custom')

Automatically Retry Rate Limited Requests

By default, DropletKit will handle requests that are rate limited by the DigitalOcean API's burst limit. When the burst rate limit is reached, DropletKit will wait according to the value of the API response's Retry-After header. Typically the wait time is less than one minute. When the hourly rate limit is hit, an error is raised.

By default, DropletKit will retry a rate limited request three times before returning an error. If you would like to disable the retry behavior altogether, and instead raise an error when any rate limit is reached, you can set the retry_max config value to zero.

DropletKit will also wait zero seconds until retrying a request after the Retry-After time has elapsed by default. To change this, set the retry_wait_min to a different value.

require 'droplet_kit'
client = DropletKit::Client.new(access_token: 'YOUR_TOKEN', retry_max: 3, retry_wait_min: 1)

Design

DropletKit follows a strict design of resources as methods on your client. For examples, for droplets, you will call your client like this:

client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
client.droplets #=> DropletsResource

DropletKit will return Plain Old Ruby objects(tm) that contain the information provided by the API. For actions that return multiple objects, the request won't be executed until the result is accessed. For example:

client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')

# Returns an instance of a Paginated Resource.
client.droplets.all
# => #<DropletKit::PaginatedResource:0x000000010d556c3a>

# Returns the first Droplet.
client.droplets.all.first
# => <DropletKit::Droplet {:@id=>1, :@name=>"mydroplet", ...}>

# Returns an array of Droplet IDs.
client.droplets.all.map(&:id)
# => [1]

When you'd like to save objects, it's your responsibility to instantiate the objects and persist them using the resource objects. Let's use creating a Droplet as an example:

client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
droplet = DropletKit::Droplet.new(name: 'mysite.com', region: 'nyc2', image: 'ubuntu-14-04-x64', size: 's-1vcpu-1gb')
created = client.droplets.create(droplet)
# => DropletKit::Droplet(id: 1231, name: 'something.com', ...)

To retrieve objects, you can perform this type of action on the resource (if the API supports it):

client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
droplet = client.droplets.find(id: 123)
# => DropletKit::Droplet(id: 1231, name: 'something.com', ...)

All Resources and actions.

CDN resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.cdns #=> DropletKit::CertificateResource
cdn = DropletKit::CDN.new(
  origin: 'myspace.nyc3.digitaloceanspaces.com',
  ttl: 1800,
  custom_domain: 'www.myacme.xyz',
  certificate_id: 'a6689b98-2bb9-40be-8638-fb8426aabd26'
)

Actions supported:

  • client.cdns.find(id: 'id')
  • client.cdns.all()
  • client.cdns.create(cdn)
  • client.cdns.update_ttl(id: 'id', ttl: 3600)
  • client.cdns.update_custom_domain(id: 'id', custom_domain: 'www.myacme.xyz', certificate_id: 'a6689b98-2bb9-40be-8638-fb8426aabd26')
  • client.cdns.flush_cache(id: 'id', files: ['*', 'path/to/css/*'])
  • client.cdns.delete(id: 'id')

Certificate resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.certificates #=> DropletKit::CertificateResource

Actions supported:

  • client.certificates.find(id: 'id')
  • client.certificates.all()
  • client.certificates.create(certificate)
  • client.certificates.delete(id: 'id')

Database resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.databases #=> DropletKit::DatabaseResource
database_cluster = DropletKit::DatabaseCluster.new(
  name: 'backend',
  engine: 'pg',
  version: '10',
  region: 'nyc3',
  size: 'db-s-2vcpu-4gb',
  num_nodes: 2,
  tags: ['production']
)

Actions supported:

  • client.databases.find_cluster(id: 'id')
  • client.databases.all_clusters()
  • client.databases.create_cluster(database_cluster)
  • client.databases.resize_cluster(database_cluster, id: 'id')
  • client.databases.migrate_cluster(database_cluster, id: 'id')
  • client.databases.set_maintenance_window(database_maintenance_window, id: 'id')
  • client.databases.update_maintenance_window(database_maintenance_window, id: 'id')
  • client.databases.list_backups(id: 'id')
  • client.databases.restore_from_backup(database_backup)
  • client.databases.delete_cluster(id: 'id')
  • client.databases.create_db(database, id: 'id')
  • client.databases.find_db(id: 'id', name: 'name')
  • client.databases.all_dbs(id: 'id')
  • client.databases.delete_db(id: 'id', name: 'name')
  • client.databases.list_firewall_rules(id: 'id')
  • client.databases.set_firewall_rules(database_firewall_rules, id: 'id')
  • client.databases.create_read_only_replica(database_read_only_replica, id: 'id')
  • client.databases.find_read_only_replica(id: 'id', name: 'name')
  • client.databases.list_read_only_replicas(id: 'id')
  • client.databases.delete_read_only_replica(id: 'id', name: 'name')
  • client.databases.create_database_user(database_user, id: 'id')
  • client.databases.find_database_user(id: 'id', name: 'name')
  • client.databases.list_database_users(id: 'id')
  • client.databases.reset_database_user_auth(reset_auth, id: 'id', name: 'name')
  • client.databases.delete_database_user(id: 'id', name: 'name')
  • client.databases.create_connection_pool(database_connection_pool, id: 'id')
  • client.databases.find_connection_pool(id: 'id', name: 'name')
  • client.databases.list_connection_pools(id: 'id')
  • client.databases.delete_connection_pool(id: 'id', name: 'name')
  • client.databases.set_eviction_policy(database_eviction_policy, id: 'id')
  • client.databases.get_eviction_policy(id: 'id')
  • client.databases.set_sql_mode(database_sql_mode, id: 'id')
  • client.databases.get_sql_mode(id: 'id')

Droplet resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.droplets #=> DropletKit::DropletResource

Actions supported:

  • client.droplets.all()
  • client.droplets.all(tag_name: 'tag_name')
  • client.droplets.find(id: 'id')
  • client.droplets.create(droplet)
  • client.droplets.create_multiple(droplet)
  • client.droplets.delete(id: 'id')
  • client.droplets.delete_for_tag(tag_name: 'tag_name')
  • client.droplets.kernels(id: 'id')
  • client.droplets.snapshots(id: 'id')
  • client.droplets.backups(id: 'id')
  • client.droplets.actions(id: 'id')

Droplet Action resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.droplet_actions #=> DropletKit::DropletAction

Actions supported:

  • client.droplet_actions.reboot(droplet_id: droplet.id)
  • client.droplet_actions.power_cycle(droplet_id: droplet.id)
  • client.droplet_actions.power_cycle_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.shutdown(droplet_id: droplet.id)
  • client.droplet_actions.shutdown_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.power_off(droplet_id: droplet.id)
  • client.droplet_actions.power_off_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.power_on(droplet_id: droplet.id)
  • client.droplet_actions.power_on_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.password_reset(droplet_id: droplet.id)
  • client.droplet_actions.enable_ipv6(droplet_id: droplet.id)
  • client.droplet_actions.enable_ipv6_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.enable_backups(droplet_id: droplet.id)
  • client.droplet_actions.enable_backups_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.disable_backups(droplet_id: droplet.id)
  • client.droplet_actions.disable_backups_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.upgrade(droplet_id: droplet.id)
  • client.droplet_actions.enable_private_networking(droplet_id: droplet.id)
  • client.droplet_actions.enable_private_networking_for_tag(tag_name: 'tag_name')
  • client.droplet_actions.snapshot(droplet_id: droplet.id, name: 'Snapshot Name')
  • client.droplet_actions.snapshot_for_tag(tag_name: 'tag_name', name: 'Snapshot Name')
  • client.droplet_actions.change_kernel(droplet_id: droplet.id, kernel: 'kernel_id')
  • client.droplet_actions.rename(droplet_id: droplet.id, name: 'New-Droplet-Name')
  • client.droplet_actions.rebuild(droplet_id: droplet.id, image: 'image_id')
  • client.droplet_actions.restore(droplet_id: droplet.id, image: 'image_id')
  • client.droplet_actions.resize(droplet_id: droplet.id, size: 's-1vcpu-1gb')
  • client.droplet_actions.find(droplet_id: droplet.id, id: action.id)
  • client.droplet_actions.action_for_id(droplet_id: droplet.id, type: 'event_name', param: 'value')
  • client.droplet_actions.action_for_tag(tag_name: 'tag_name', type: 'event_name', param: 'value')

Domain resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.domains #=> DropletKit::DomainResource

Actions supported:

  • client.domains.all()
  • client.domains.create(domain)
  • client.domains.find(name: 'name')
  • client.domains.delete(name: 'name')

Domain record resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.domain_records #=> DropletKit::DomainRecordResource
domain_record = DropletKit::DomainRecord.new(
  type: 'CNAME',
  name: 'www',
  data: '@',
  ttl: 1800
)

Actions supported:

  • client.domain_records.all(for_domain: 'for_domain')
  • client.domain_records.create(domain_record, for_domain: 'for_domain')
  • client.domain_records.find(for_domain: 'for_domain', id: 'id')
  • client.domain_records.delete(for_domain: 'for_domain', id: 'id')
  • client.domain_records.update(domain_record, for_domain: 'for_domain', id: 'id')

Firewall resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.firewalls #=> DropletKit::FirewallResource

inbound_rule = DropletKit::FirewallInboundRule.new(
  protocol: 'icmp',
  ports: '0',
  sources: {
    tags: ['frontend', 'backend'],
    load_balancer_uids: ['d2d3920a-9d45-41b0-b018-d15e18ec60a4'],
    kubernetes_ids: ['a47b6fb1-4791-4b29-aae1-2b1b9f68a2da']
  }
)

outbound_rule = DropletKit::FirewallOutboundRule.new(
  protocol: 'icmp',
  ports: '0',
  destinations: {
    addresses: ["127.0.0.0"],
    droplet_ids: [456, 789]
  }
)

firewall = DropletKit::Firewall.new(
  name: 'firewall',
  inbound_rules: [
    inbound_rule
  ],
  outbound_rules: [
    outbound_rule
  ],
  droplet_ids: [123],
  tags: ['backend']
)

Actions supported:

  • client.firewalls.find(id: 'id')
  • client.firewalls.create(firewall)
  • client.firewalls.update(firewall, id: 'id')
  • client.firewalls.all()
  • client.firewalls.all_by_droplet(droplet_id: 'id')
  • client.firewalls.delete(id: 'id')
  • client.firewalls.add_droplets([droplet.id], id: 'id')
  • client.firewalls.remove_droplets([droplet.id], id: 'id')
  • client.firewalls.add_tags([tag.name], id: 'id')
  • client.firewalls.remove_tags([tag.name], id: 'id')
  • client.firewalls.add_rules(inbound_rules: [inbound_rule], outbound_rules: [outbound_rule], id: 'id')
  • client.firewalls.remove_rules(inbound_rules: [inbound_rule], outbound_rules: [outbound_rule], id: 'id')

Image resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.images #=> DropletKit::ImageResource

Actions supported:

  • client.images.all()
  • client.images.find(id: 'id')
  • client.images.delete(id: 'id')
  • client.images.update(image, id: 'id')

Image Action Resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.image_actions #=> DropletKit::ImageActionResource

Image Actions Supported:

  • client.image_actions.all(image_id: 123)
  • client.image_actions.find(image_id: 123, id: 123455)
  • client.image_actions.transfer(image_id: 123, region: 'nyc3')

Invoice resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.invoices #=> DropletKit::InvoiceResource

Actions supported:

  • client.invoices.list()
  • client.invoices.find(id:123)

Kubernetes Resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.kubernetes_clusters #=> DropletKit::KubernetesClusterResource

Actions supported

When the arguments below refer to cluster, they refer to:

cluster = DropletKit::KubernetesCluster.new(name: "foo", region: "nyc1", ...) # cluster attributes

When the arguments below refer to node_pool, they refer to:

node_pool = DropletKit::KubernetesNodePool.new(name: 'frontend', size: 's-1vcpu-1gb', count: 3, ...) # Node Pool attributes
  • client.kubernetes_clusters.all()
  • client.kubernetes_clusters.find(id: 'cluster_id')
  • client.kubernetes_clusters.create(cluster)
  • client.kubernetes_clusters.kubeconfig(id: 'cluster_id')
  • client.kubernetes_clusters.update(cluster, id: 'cluster_id')
  • client.kubernetes_clusters.delete(id: 'cluster_id')
  • client.kubernetes_clusters.node_pools(id: 'cluster_id')
  • client.kubernetes_clusters.find_node_pool(id: 'cluster_id', pool_id: 'node_pool_id')
  • client.kubernetes_clusters.create_node_pool(node_pool, id: 'cluster_id')
  • client.kubernetes_clusters.update_node_pool(node_pool, id: 'cluster_id', pool_id: 'node_pool_id')
  • client.kubernetes_clusters.delete_node_pool(id: 'cluster_id', pool_id: 'node_pool_id')
  • client.kubernetes_clusters.recycle_node_pool([node_id, node_id, ...], id: 'cluster_id', pool_id: 'node_pool_id')
  • client.kubernetes_options.all()

Load balancer resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.load_balancers #=> DropletKit::LoadBalancerResource

Actions supported:

  • client.load_balancers.find(id: 'id')
  • client.load_balancers.all()
  • client.load_balancers.create(load_balancer)
  • client.load_balancers.update(load_balancer, id: 'id')
  • client.load_balancers.delete(id: 'id')
  • client.load_balancers.add_droplets([droplet.id], id: 'id')
  • client.load_balancers.remove_droplets([droplet.id], id: 'id')
  • client.load_balancers.add_forwarding_rules([forwarding_rule], id: 'id')
  • client.load_balancers.remove_forwarding_rules([forwarding_rule], id: 'id')

Region resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.regions #=> DropletKit::RegionResource

Actions supported:

  • client.regions.all()

Size resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.sizes #=> DropletKit::SizeResource

Actions supported:

  • client.sizes.all()

SSH key resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.ssh_keys #=> DropletKit::SSHKeyResource

When you want to create a droplet using your stored SSH key.

client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
my_ssh_keys = client.ssh_keys.all.collect {|key| key.fingerprint}
droplet = DropletKit::Droplet.new(name: 'mysite.com', region: 'nyc2', image: 'ubuntu-14-04-x64', size: 's-1vcpu-1gb', ssh_keys: my_ssh_keys)
created = client.droplets.create(droplet)
# => DropletKit::Droplet(id: 1231, name: 'something.com', ...)

Actions supported:

  • client.ssh_keys.all()
  • client.ssh_keys.create(ssh_key)
  • client.ssh_keys.find(id: 'id')
  • client.ssh_keys.delete(id: 'id')
  • client.ssh_keys.update(ssh_key, id: 'id')

Project resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.projects #=> DropletKit::ProjectResource

Actions supported:

  • client.projects.all()
  • client.projects.find(id: 'id')
  • client.projects.find_default is equivalent to client.projects.find(id: DropletKit::Project::DEFAULT)
  • client.projects.create(DropletKit::Project.new(name: 'name', purpose: 'Service or API'))
  • client.projects.update(project, id: 'id')
  • client.projects.delete(id: 'id')
  • client.projects.list_resources(id: 'id')
  • client.projects.assign_resources([DropletKit::Droplet.new(id: 123), "do:space:myspace.com"], id: 'id')

Tag resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.tags #=> DropletKit::TagResource

Actions supported:

  • client.tags.all()
  • client.tags.find(name: 'name')
  • client.tags.create(DropletKit::Tag.new(name: 'name'))
  • client.tags.delete(name: 'name')
  • client.tags.tag_resources(name: 'name', resources: [{ resource_id => 'droplet_id', resource_type: 'droplet' },{ resource_id => 'image_id', resource_type: 'image' }])
  • client.tags.untag_resources(name 'name', resources: [{ resource_id => 'droplet_id', resource_type: 'droplet' },{ resource_id => 'image_id', resource_type: 'image' }])

Account resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.account #=> DropletKit::AccountResource

Actions supported:

  • client.account.info()

Balance resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.balance #=> DropletKit::BalanceResource

Actions supported:

  • client.balance.info()

Reserved IP resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.reserved_ips #=> DropletKit::ReservedIpResource

Actions supported:

  • client.reserved_ips.all()
  • client.reserved_ips.find(ip: 'ip address')
  • client.reserved_ips.create(reserved_ip)
  • client.reserved_ips.delete(ip: 'ip address')

Reserved IP Action resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.reserved_ip_actions #=> DropletKit::ReservedIpActionResource

Actions supported:

  • client.reserved_ip_actions.assign(ip: reserved_ip.ip, droplet_id: droplet.id)
  • client.reserved_ip_actions.unassign(ip: reserved_ip.ip)

Volume resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.volumes #=> DropletKit::VolumeResource

Actions supported:

  • client.volumes.all()
  • client.volumes.find(id: 'id')
  • client.volumes.create(volume)
  • client.volumes.snapshots(id: 'id')
  • client.volumes.create_snapshot(id: 'id', name: 'snapshot-name')
  • client.volumes.delete(id: 'id')

Volume Action resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.volume_actions #=> DropletKit::VolumeActionResource

Actions supported:

  • client.volume_actions.attach(volume_id: volume.id, droplet_id: droplet.id, region: droplet.region.slug)
  • client.volume_actions.detach(volume_id: volume.id, droplet_id: droplet.id, region: droplet.region.slug)
  • client.volume_actions.resize(volume_id: volume.id, size_gigabytes: 123, region: droplet.region.slug)

Snapshot resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.snapshots #=> DropletKit::SnapshotResource

Actions supported:

  • client.snapshots.all(resource_type: 'droplet')
  • client.snapshots.find(id: 'id')
  • client.snapshots.delete(id: 'id')

VPC resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.vpcs #=> DropletKit::VPCResource

Actions supported:

  • client.vpcs.find(id: 'id')
  • client.vpcs.all()
  • client.vpcs.create(vpc)
  • client.vpcs.update(vpc, id: 'id')
  • client.vpcs.patch(vpc, id: 'id')
  • client.vpcs.delete(id: 'id')
  • client.vpcs.all_members(id: 'id')

Container Registry resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.container_registry #=> DropletKit::ContainerRegistryResource

Actions supported:

  • client.container_registry.get()
  • client.container_registry.create(registry)
  • client.container_registry.delete()
  • client.container_registry.docker_credentials()

Container Registry Repository resource

client = DropletKit::Client.new(access_token: 'TOKEN')
client.container_registry_repository #=> DropletKit::ContainerRegistryRepositoryResource

Actions supported:

  • client.container_registry_repository.all(registry_name: 'registry')
  • client.container_registry_repository.tags(registry_name: 'registry', repository: 'repo')
  • client.container_registry_repository.delete_tag(registry_name: 'registry', repository: 'repo', tag: 'tag')
  • client.container_registry_repository.delete_manifest(registry_name: 'registry', repository: 'repo', manifest_digest: 'sha256:cb8a924afdf0229ef7515d9e5b3024e23b3eb03ddbba287f4a19c6ac90b8d221')

Contributing

  1. Fork it ( https://github.com/digitalocean/droplet_kit/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Releasing

See RELEASE for details

droplet_kit's People

Contributors

alambike avatar andrewsomething avatar awmichel avatar bentranter avatar bobbytables avatar caiofilipini avatar danaelhe avatar dikshant avatar gregmankes avatar hilary avatar hugocorbucci avatar humzashah avatar icreatejb avatar ivanvanderbyl avatar mauricio avatar mberbero avatar mchitten avatar mregmi avatar nanzhong avatar nicktate avatar petems avatar phillbaker avatar shockwavenn avatar sunny-b avatar suprnova32 avatar tas50 avatar viola avatar webdestroya avatar zachgersh avatar zbarahal-do avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

droplet_kit's Issues

New release?

Hi!

Is it possible to tag and push a new release? πŸ˜„

API error

As mention in #61, the API documentation lists this:

client.images.all.each(public: false)

as the way to get all user images. Since that's not right, I tried this, which seems consistent with code I've seen elsewhere:

client.images.all(public: false).each

but that gives public images as well. It's possible that my correction to the documentation mistake was itself mistaken, but since it appears to me to be an error I'll post this in case I'm correct.

In the meantime, this works just fine

client.images.all.select{|i| i.public == false}.each

Is there anyway to perform a permanent resize?

Right now,one can do a flexible resize using
.droplet_actions.resize
but is there any method to do a permanent resize.
Also I know this is not like an issue,but I don't know where else to ask.

ssh_keys not working on droplet create

I am trying to create a droplet, however, the ssh_keys array does not appear to get passed along during creation

[20] pry(main)> client.ssh_keys.find(id: 1234567)
=> <DropletKit::SSHKey {:@id=>1234567, :@fingerprint=>"XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX", :@public_key=>"ssh-rsa XXXXXXXXXXXX", :@name=>"ssh key name"}>
[21] pry(main)> droplet
=> <DropletKit::Droplet {:@name=>"new-droplet", :@size=>"2gb", :@image=>"centos-7-0-x64", :@region=>"nyc1", :@ssh_keys=>["1234567"], :@private_networking=>true, :@backups=>nil, :@ipv6=>nil, :@id=>nil, :@memory=>nil, :@vcpus=>nil, :@disk=>nil, :@locked=>nil, :@created_at=>nil, :@status=>nil, :@backup_ids=>nil, :@snapshot_ids=>nil, :@action_ids=>nil, :@features=>nil, :@networks=>nil, :@kernel=>nil, :@size_slug=>nil, :@user_data=>nil}>
[22] pry(main)> server = client.droplets.create(droplet)
=> <DropletKit::Droplet {:@name=>"new-droplet", :@size=>nil, :@image=><DropletKit::Image {:@id=>14782842, :@name=>"7.1 x64", :@distribution=>"CentOS", :@slug=>"centos-7-0-x64", :@public=>true, :@regions=>["nyc1", "sfo1", "nyc2", "ams2", "sgp1", "lon1", "nyc3", "ams3", "fra1", "tor1"], :@type=>"snapshot"}>, :@region=><DropletKit::Region {:@slug=>"nyc1", :@name=>"New York 1", :@sizes=>["512mb", "8gb", "16gb", "32gb", "48gb", "64gb", "1gb", "2gb", "4gb"], :@available=>true, :@features=>["private_networking", "backups", "ipv6", "metadata"]}>, :@ssh_keys=>nil, :@private_networking=>nil, :@backups=>nil, :@ipv6=>nil, :@id=>11162726, :@memory=>2048, :@vcpus=>2, :@disk=>40, :@locked=>true, :@created_at=>"2016-02-16T20:01:36Z", :@status=>"new", :@backup_ids=>[], :@snapshot_ids=>[], :@action_ids=>nil, :@features=>["virtio"], :@networks=>#<struct DropletKit::NetworkHash v4=[], v6=[]>, :@kernel=><DropletKit::Kernel {:@id=>6028, :@name=>"CentOS 7 x64 vmlinuz-3.10.0-229.20.1.el7.x86_64", :@version=>"3.10.0-229.20.1.el7.x86_64"}>, :@size_slug=>"2gb", :@user_data=>nil}>
[23] pry(main)> server.ssh_keys
=> nil
[24] pry(main)> 

Creating tags

The 2.0 documentation suggests a tag would be created like this:

client.tags.create(name: 'my_tag')

But that gives the error:

ArgumentError: {:name=>"my_tag"} does not respond to name, so we can't map it

Passing an OpenStruct works, but seems like a hack:

client.tags.create(OpenStruct.new(name: 'my_tag'))

ActiveSupport 5.0 Support

I am preparing to start a Rails App and want to use Rails 5 beta, I have forked the project and updated the dependency settings for ActiveSupport and ran the tests and everything is passing on my machine (ubuntu 14.04). Can we update to all for Rails 5 support or beta gem? I can send a pull request.

$digital_ocean.ssh_keys.all.first

NoMethodError: undefined method `+' for :read:Symbol
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/kartograph-0.2.4/lib/kartograph/map.rb:14:in `property'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/mappings/ssh_key_mapping.rb:9:in `block in <class:SSHKeyMapping>'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/kartograph-0.2.4/lib/kartograph/dsl.rb:12:in `instance_eval'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/kartograph-0.2.4/lib/kartograph/dsl.rb:12:in `kartograph'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/mappings/ssh_key_mapping.rb:5:in `<class:SSHKeyMapping>'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/mappings/ssh_key_mapping.rb:2:in `<module:DropletKit>'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/mappings/ssh_key_mapping.rb:1:in `<top (required)>'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/resources/ssh_key_resource.rb:7:in `block (3 levels) in <class:SSHKeyResource>'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/resource_kit-0.1.4/lib/resource_kit/action_invoker.rb:19:in `instance_exec'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/resource_kit-0.1.4/lib/resource_kit/action_invoker.rb:19:in `handle_response'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/paginated_resource.rb:62:in `retrieve'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/paginated_resource.rb:54:in `fetch_next_page'
    from /Users/aulugbekov/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/droplet_kit-1.1.2/lib/droplet_kit/paginated_resource.rb:26:in `each'
    from (irb):8:in `first'
    from (irb):8
    from /Users/aulugbekov/.rbenv/versions/2.1.2/bin/irb:11:in `<main>'

Long waits on list commands if theres no data to be returned

I'm seeing long pauses when I loop over any list command when theirs nothing to be returned.

If I list domain names, sshkeys, images, etc, it sometimes takes a full minute to get the results back. If I add data to be listed it returns almost instantly.

if you gem install knife-digital_ocean and run knife digital_ocean image list you should see what I'm talking about, assuming you have no snapshots under your account.

How droplet kit fetches pages for all droplets

Hello! I'm currently in the middle of switching Tugboat to use Droplet Kit over Barge.

Most of the code has been a simple switchover, but the pagination of returned nodes is giving me some bother.

Right now I have some code like this to deal with pagination with https://github.com/blom/barge/:

      # Get all pages of droplets
      def get_droplet_list(ocean)
        verify_credentials(ocean)

        page = ocean.droplet.all(per_page: 200, page: 1)
        return page.droplets unless page.paginated?

        Enumerator.new do |enum|
          page.droplets.each { |drop| enum.yield drop }
          for page_num in 2..page.last_page
            page = ocean.droplet.all(per_page: 200, page: page_num)
            page.droplets.each { |drop| enum.yield drop }
          end
        end
      end

This is so I can fetch 200 at a time, but if there's more than 200 then it can look for the next page, using the paginated? method.

This doesn't seem to be the case for droplet_kit and I can't find an example of fetching a large amount of droplets...

So some questions:

  • With droplet_kit, how can I make sure I'm fetching all droplets?
  • Is client.droplets.all enough, or does that default to the API max of 200?

paginated_resource raises error with no api key set

client = DropletKit::Client.new(access_token: nil)
client.droplets.all.each do |droplet|
  puts droplet.name
end
=> TypeError: no implicit conversion of String into Array
from /Users/jadems/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.2.3/lib/droplet_kit/paginated_resource.rb:68:in `retrieve'
from /Users/jadems/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.2.3/lib/droplet_kit/paginated_resource.rb:60:in `fetch_next_page'
from /Users/jadems/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.2.3/lib/droplet_kit/paginated_resource.rb:26:in `each'

I had a misconfigured environment and spent a few minutes trying to figure out why I was getting this. It might be helpful to handle authentication errors more gracefully.

feature request: public_ip convenience method

It would be nice to have public_ip and private_ip convenience methods, rather than having to loop through the network block and figure them out from the hash. So something like this.

client = DropletKit::Client.new(access_token: 'YOUR_TOKEN')
droplet = client.droplets.find(id: 123)
droplet.public_ip
droplet.private_ip

If a paginated resource is empty, an infinite loops occurs

When hitting /v2/droplets when you have no droplets, this occurs:

    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'
    from /Users/robert/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/droplet_kit-1.0.2/lib/droplet_kit/paginated_resource.rb:36:in `each'

ssh_keys are not assigned to new droplet

Hello,

I tried to create droplets by many ways: droplet_kit, curl, ... trying to assign ssh_keys to new droplet.
I assigned the values manually copying ssh keys from web and getting them by api but none of them works.
My last test:

params = {:name=>"domain1", :region=>"nyc1", :image=>"25092162", :size=>"512mb", :ssh_keys=>["99:19:5d:dd:f8:4d:99:0e:c3:41:4a:c4:cf:f3:52:8c", 7493092, 9485273]}
droplet = DropletKit::Droplet.new(params)
created = remote_connection.droplets.create(droplet)

and ssh_keys always is null and I can not connect to server to make additional actions (....:@ssh_keys=>nil, :@id=>50204194, ....).

Note: the same results using other libraries and CURL.

Regards,

Cannot create droplet with one-click app

I cannot find a way to create a droplet with a 1-click app (in my case, WordPress) as I can do on the web site. Is there a way to do this with droplet_kit? If not, could that feature be added?

(I tried searching the code base for click and app but did not find any occurrences, and I tried listing the images but the 1-click apps did not appear to be included in the result.)

Untag resources error

I've been using DropletKit for the past year without issues.
Over the past few weeks when I go to run:
tags.untag_resources(name: @tag[0], resources: [{resource_id: droplet_id, resource_type: 'droplet' }])

I see:

error_handling_resourcable.rb:14:in block (2 levels) in included': 400: {"id":"parameter_missing","message":"param is missing or the value is empty: resources"} (DropletKit::Error) from /root/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/resource_kit-0.1.6/lib/resource_kit/action_invoker.rb:19:in instance_exec'
from /root/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/resource_kit-0.1.6/lib/resource_kit/action_invoker.rb:19:in handle_response' from /root/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/resource_kit-0.1.6/lib/resource_kit/action_invoker.rb:14:in call'
from /root/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/resource_kit-0.1.6/lib/resource_kit/method_factory.rb:16:in `block in method_for_action'

support space

hi search about space api on droplet kit gem but i cant find anything , please add this api to droplet_kit gem
thanks

client.domains.all not working

I'm not able to list domains

client = DropletKit::Client.new(access_token: token)
client.domains.all.each do |domain|
  puts domain.name
end

I always get the following error.

/home/gregf/.gem/ruby/2.1.4/gems/droplet_kit-1.1.1/lib/droplet_kit/paginated_resource.rb:62:in `retrieve': no implicit conversion of String into Array (TypeError)
    from /home/gregf/.gem/ruby/2.1.4/gems/droplet_kit-1.1.1/lib/droplet_kit/paginated_resource.rb:54:in `fetch_next_page'
    from /home/gregf/.gem/ruby/2.1.4/gems/droplet_kit-1.1.1/lib/droplet_kit/paginated_resource.rb:26:in `each'
    from -:21:in `<main>'

Sudden Issue with API

The api was working perfect till suddenly, around 20 hours hours ago, it started giving me an error.
Even a simple droplet call like:

client = DropletKit::Client.new(access_token: 'token')
droplets = client.droplets.all
puts droplets

suddenly started giving the following error:

/root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/resource_kit-0.1.4/lib/resource_kit/method_factory.rb:6:in block in construct': Action 'assign' is already defined onDropletKit::FloatingIpActionResource(ArgumentError) from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/resource_kit-0.1.4/lib/resource_kit/method_factory.rb:4:inconstruct'
from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/resource_kit-0.1.4/lib/resource_kit/resource.rb:20:in resources' from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.3.0/lib/droplet_kit/resources/floating_ip_action_resource.rb:3:inclass:FloatingIpActionResource'
from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.3.0/lib/droplet_kit/resources/floating_ip_action_resource.rb:2:in <module:DropletKit>' from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.3.0/lib/droplet_kit/resources/floating_ip_action_resource.rb:1:in<top (required)>'
from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.3.0/lib/droplet_kit/client.rb:33:in resources' from /root/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/droplet_kit-1.3.0/lib/droplet_kit/client.rb:38:inmethod_missing'
from test.rb

API documentation error

The API documentation lists this:

client.images.all.each(public: false)

as the way to get all user images, but that fails with an ArgumentError (bad value for range), so I'm pretty sure it would be something closer to this:

client.images.all(public: false).each

although that doesn't work either: it gives public images as well. But that's not a documentation error, so I'll list it separately.

possibly hitting api more than needed?

I can't claim I understand all the internals to droplet_kit, but I'm wondering if it's possible it's hitting the api more than one might expect. Since switching knife-digital_ocean over to dropletkit I seem to be hitting my api limit every time I sit down to do some work. My tests are using vcr to cache api responses, and I only run the occasional command manually to test my work.

I was attempting to update our readme tonight and ran just two or three commands (after not touching the api in a day or two), and have hit my limit again.

After running a few commands my RateLimit-Reset is now 1416011974, meaning I can't make another request until tomorrow at noon, if I'm understanding the documentation for the api correctly. Theres no way I have run 1200 commands tonight, and assuming I haven't touched the api in a day or two it should have been reset from previous times.

Thanks guys!

coreos image / can't ssh to instance when created with dropletkit

Not a hell of a deal but I'd like to stick using dropletkit

I've created this gist to expose the problem i have :

https://gist.github.com/bbnnt/28f7a1627afe76c26e2c3f3d1b8a2cee

2.curl.sh and 3.cloud-config-for-curl-command.yaml goes together, when I use curl I can ssh to the instance without any problem via ssh -A core@droplet_ip

However, when running quite the same via dropletkit (1.dropletkit_cmd.rb, so same userdata, same region, etc..), the droplet gets created, but when trying to ssh into it (I do use the same ssh -A core@droplet_ip), nothing else than a timeout

I tried many slight adjustements on the dropletkit script, but nothing to do, I won't reach the coreos droplet via ssh if I create it via dropletkib

That might just be a typo in the dropletkit script… Hope to get some hints

Pagination doesn't work

I was trying to register in DNS over 60 domains with his domain records, but when I ask for the domains registered, every page returns the same 20 domains, so can't check if is registered already

    client.domains.all.each do |d|
        puts d.name
    end

With curl it seems to works ok.

Message: Failed to complete #create action: [Names can't be blank]

I just pulled this down to try for the first time, so the problem I've hit could absolutely be on my end, but I kept getting the message Message: Failed to complete #create action: [Names can't be blank] when I'd try to create a droplet using the kitchen-digitalocean driver. I found I'm able to create without error if I comment out line 30 of lib/droplet_kit/mappings/droplet_mapping.rb which was added just a few days ago in commit 284d0e1. name appears to be automagically generated with the driver, but I don't see where it's doing anything for names. Is this something I'm just overlooking in my .kitchen.yml, or just that kitchen-digitalocean hasn't caught up with the latest updates here? (or something else?)

My .kitchen.yml:

---
driver:
  name: digitalocean
  driver_config:
    ssh_key_ids: <%= ENV['DIGITALOCEAN_SSH_KEY_IDS'] %>
    ssh_key: <%= ENV['DIGITALOCEAN_SSH_KEY_PATH'] %>

platforms:
  - name: ubuntu-14.04

suites:
  - name: default
    run_list:
      - recipe[dome::default]
    attributes:

Add support for the bock storage API

The API is still in private beta, but having it available via DropletKit will really simplify its implementation within the GitHost codebase. We would like to have our implementation ready for when the block storage feature goes out of beta.

I'll see if I can contribute this in some way, but it will take me some time to get acquainted with the codebase.

Documentation on New Domain Record

There is basically nothing explaining what the first param "domain_record" should look like:

client.domain_records.create(domain_record, for_domain: 'for_domain')

So any documentation that might explain what this should be would be great. I'd expect you could pass in a hash like follows that would fill the needs, but this did not work:

options = { :type => "A", :name => "test2", :data => "10.1.1.1" }

Inconsistent status sometimes after shutdown/boot action (action completed, droplet status not updated immediately)?

I've been having this for many months now, but infrequently and hard to reproduce. So say I do a power off. I check the status code is 2xx. I check that the action status is not "errored". I check that the action status is "completed". But when I check the droplet status, it's "active", not "off"

I'm doing this in a background worker (keep polling action status), and haven't had it for a long time actually so I thought it was fixed, but I just got it again today a few times. By the time I realize it's failed and looked at it, the droplet properly reports "off"

I know it's not a lot of debugging information, but I just wanted to report this issue first and see if anyone has had it/knows anything about it. It's hard to reproduce

Sure, it's not hard to retry a few times checking the droplet status before giving up, but it's messy. When the API reports the event completed successfully, the droplet should be in the proper state.

tl,dr; power off action completed, droplet status not "off" until a few seconds later

keys named other than id_rsa or id_dsa fail.

I have two keys on digitalocean. One is named ~/.ssh/id_rsa and the other is named ~/.ssh/id_rsa.digitalocean.

If I choose to use the key id for id_rsa test-kitchen will create my server and login using my ssh key.

If I disable id_rsa and choose to use the key named id_rsa.digitalocean it prompts me for a password each time.

Update to Rails 4.2

Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    droplet_kit (>= 0) ruby depends on
      activesupport (~> 4.1.6) ruby

    rails (= 4.2.0) ruby depends on
      actionpack (= 4.2.0) ruby depends on
        activesupport (4.2.0)

Can you upgrade dependency to allow upgrading to rails 4.2?

Add docs for attributes for each resource

Right now it's a bit hard to see what attributes are available on each resource.

For example, I'm moving https://github.com/pearkes/tugboat to use droplet_kit, but it's missing a few of the attributes on the image side, and I had to dig into the code to find out. Adding docs for each attribute, using the docs from the API DigitalOcean docs.

I did some of this in #115, but it would be nice to have full coverage! πŸ˜„

Unable to list SSH keys

When I try to list the SSH keys:

client.ssh_keys.all.each do |key|
  puts key.name
end

I'm presented with this error:

NoMethodError: undefined method `+' for :read:Symbol
    from /home/user/.rvm/gems/ruby-2.1.5/gems/kartograph-0.2.1/lib/kartograph/map.rb:14:in `property'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/mappings/ssh_key_mapping.rb:9:in `block in <class:SSHKeyMapping>'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/kartograph-0.2.1/lib/kartograph/dsl.rb:12:in `instance_eval'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/kartograph-0.2.1/lib/kartograph/dsl.rb:12:in `kartograph'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/mappings/ssh_key_mapping.rb:5:in `<class:SSHKeyMapping>'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/mappings/ssh_key_mapping.rb:2:in `<module:DropletKit>'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/mappings/ssh_key_mapping.rb:1:in `<top (required)>'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/resources/ssh_key_resource.rb:7:in `block (3 levels) in <class:SSHKeyResource>'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/resource_kit-0.1.2/lib/resource_kit/action_invoker.rb:19:in `instance_exec'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/resource_kit-0.1.2/lib/resource_kit/action_invoker.rb:19:in `handle_response'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/paginated_resource.rb:68:in `retrieve'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/paginated_resource.rb:60:in `fetch_next_page'
    from /home/user/.rvm/gems/ruby-2.1.5/gems/droplet_kit-1.1.3/lib/droplet_kit/paginated_resource.rb:26:in `each'

I can create droplets without issue, so I'm assuming nothing is wrong with my setup.

creating a droplet with ssh key?

The following code gives no errors, it just doesn't create a new droplet...

require 'rubygems'
require 'droplet_kit'
token='really_long_secret_token'
client = DropletKit::Client.new(access_token: token)
droplet = DropletKit::Droplet.new(name: 'example', region: 'nyc3', size: '1gb', image: 'ubuntu-14-04-x64', ssh_keys: ["654321", "123456"])

I've also specified the keys without quotes.

What's the actual way to do this?

`droplets.all` by `tag` documentation error

Hey all!

First, thanks for providing a great API with good tools to use it and for the easy to read documentation.

Second, in the listing droplets by tag section ruby code examples, it says to pass a parameter tag to list all droplets for a tag, but in the code you use tag_name, which took me a second to find. e.g.

# provided example:
client.droplets.all(tag: awesome)

# A correct example:
client.droplets.all(tag_name: "awesome")

I couldn't find a repo for the docs or I would have submitted a pull request. I saw one other issue related docs filed here, so I thought I'd try this. Let me know if there's a better spot to file this.

πŸ’•

Expose Faraday adaptor to allow injecting middleware

Over at Tugboat, we've been using Barge for a while, which has a very similar API to droplet_kit

One of the things we did in Barge was to expose the faraday endpoint:

    def faraday
      @faraday ||= Faraday.new faraday_options do |f|
        f.adapter :net_http

        f.request :json

        f.response :follow_redirects
        f.response :mashify
        f.response :json

        f.options.merge! request_options
      end
    end

    private

    def faraday_options
      {
        headers: {
          authorization: "Bearer #{access_token}",
          content_type: 'application/json'
        },
        url: DIGITAL_OCEAN_URL
      }
    end

Which allows you to overwrite, including adding your own custom middleware:

env['barge'].faraday.use Tugboat::CustomLogger if ENV['DEBUG']

This allows us to do things like show debugging logs with the API key redacted for users to debug issues:

I, [2016-10-08T20:53:14.408984 #54987]  INFO -- : Started GET request to: https://api.digitalocean.com/v2/droplets?page=1&per_page=200
D, [2016-10-08T20:53:14.409434 #54987] DEBUG -- : Request Headers:
----------------
Authorization : Bearer [TOKEN REDACTED]
Content-Type  : application/json
User-Agent    : Faraday v0.9.2

Request Body:
-------------
{
  "droplets": [
    {
[etc.]

Very cool, and I'm pretty proud of it πŸ‘

We're looking to possible start using droplet_kit over Barge for Tugboat, would this be something you'd be ok with adding to droplet_kit? πŸ˜„

Release 1.4.3

The version in Rubygems is still the one that is incompatible with the Block Storage API. Please push a new version. I don't want to use my fork in production.

Unexpected return of Droplet.create

According to Documentation

created = client.droplets.create(droplet)
# => DropletKit::Droplet(id: 1231, name: 'something.com', ...)

actuall i get only a temp object

<DropletKit::Droplet {:@name=>"PROXY", :@region=><DropletKit::Region {:@slug=>"nyc2", :@name=>"New York 2", :@sizes=>["1gb", "2gb", "4gb", "8gb", "32gb", "64gb", "512mb", "48gb", "16gb"], :@available=>true, :@features=>["private_networking", "backups", "ipv6", "metadata"]}>, :@image=><DropletKit::Image {:@id=>17150032, :@name=>"proxy", :@distribution=>"Ubuntu", :@slug=>nil, :@public=>false, :@regions=>["nyc2"], :@type=>"snapshot"}>, :@size=>"512mb", :@ssh_keys=>[1264198], :@id=>14676199, :@memory=>512, :@vcpus=>1, :@disk=>20, :@locked=>true, :@created_at=>"2016-05-04T16:46:35Z", :@status=>"new", :@backup_ids=>[], :@snapshot_ids=>[], :@action_ids=>nil, :@features=>["virtio"], :@networks=>#<struct DropletKit::NetworkHash v4=[], v6=[]>, :@kernel=>nil, :@size_slug=>"512mb", :@tags=>[], :@names=>nil, :@backups=>nil, :@ipv6=>nil, :@user_data=>nil, :@private_networking=>nil}

that means i have no id nor IP

droplet_kit documentation/help

Hello,

I am new to ruby and droplet_kit but I'm trying to learn. I have been using irb commands and not getting expected results. For example, after

require 'droplet_kit'
token = ENV['DO_TOKEN']
client = DropletKit::Client.new(access_token: token)
client.droplets.all

I get the following result ()
=> #<DropletKit::PaginatedResource:0xb95191f4 @current_page=0, @total=nil, @action=#<ResourceKit::Action:0xb97308fc @name=:all, @verb=:get, @path="/v2/droplets", @query_keys=[:per_page, :page], @handlers={:any=>#<Proc:0xb9730a64@/opt/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/droplet_kit-1.3.3/lib/droplet_kit/error_handling_resourcable.rb:4>, 200=>#<Proc:0xb9730794@/opt/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/droplet_kit-1.3.3/lib/droplet_kit/resources/droplet_resource.rb:8>}>, @resource=#<DropletKit::DropletResource:0xb989dc6c @connection=#<Faraday::Connection:0xb95b859c @parallel_manager=nil, @headers={"Content-Type"=>"application/json", "Authorization"=>"Bearer SECRET", "User-Agent"=>"Faraday v0.9.2"}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0xb95abfa4 @handlers=[Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS https://api.digitalocean.com/>, @proxy=nil>, @scope=nil>, @collection=[], @args=[], @options={}>

Just by guessing and trial and error, I was able to get a better result with client.droplets.all.each and I saw another example using client.droplets.all.first but other than that, I have no idea what I am doing. :-)

My question is, where can I find a list of all available and valid options to client.droplets.all() and client.images.all() etc.?

My goal is to try to automate some things like taking snapshots (saw the snapshots.rb example but I need something more robust) and transferring the resulting images to different data centers and creating droplets based off those snapshot images. I'd like to be able to create some of the results I have seen with knife digital_ocean such as:

knife digital_ocean image list
ID        Distribution  Name                              Slug
1xxxxxx1  Debian        production-live
1xxxxxx2  Debian        production-live

Anything you can do to help would be greatly appreciated!

Cheers,
Ed

Faraday dependency is overly specific

The gem dependency on faraday is ~> 0.9.1. This only allows 0.9.1 and 0.9.2. Faraday 0.10 was released last November and it is currently up to 0.12. Was this an intentional lock? Usually ~> should only have two version components if you're using it in a SemVer style. If what you want is >=0.9.1 && <1.0 you can do that with '~> 0.9', '>= 0.9.1' or something similar. This is causing dependency conflicts in some Chef ecosystem tools as we try to upgrade Faraday to more recent versions.

Change record TTL ?

Hi folks,

Is there a way to change the default TTL for a record through the API ?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.