Class: Fog::Compute::DigitalOcean::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/compute/digitalocean/requests/get_ssh_key.rb,
lib/fog/compute/digitalocean.rb,
lib/fog/compute/digitalocean/requests/rename.rb,
lib/fog/compute/digitalocean/requests/resize.rb,
lib/fog/compute/digitalocean/requests/rebuild.rb,
lib/fog/compute/digitalocean/requests/restore.rb,
lib/fog/compute/digitalocean/requests/upgrade.rb,
lib/fog/compute/digitalocean/requests/power_on.rb,
lib/fog/compute/digitalocean/requests/shutdown.rb,
lib/fog/compute/digitalocean/requests/snapshot.rb,
lib/fog/compute/digitalocean/requests/power_off.rb,
lib/fog/compute/digitalocean/requests/enable_ipv6.rb,
lib/fog/compute/digitalocean/requests/list_images.rb,
lib/fog/compute/digitalocean/requests/power_cycle.rb,
lib/fog/compute/digitalocean/requests/list_flavors.rb,
lib/fog/compute/digitalocean/requests/list_regions.rb,
lib/fog/compute/digitalocean/requests/list_servers.rb,
lib/fog/compute/digitalocean/requests/list_volumes.rb,
lib/fog/compute/digitalocean/requests/attach_volume.rb,
lib/fog/compute/digitalocean/requests/change_kernel.rb,
lib/fog/compute/digitalocean/requests/create_server.rb,
lib/fog/compute/digitalocean/requests/create_volume.rb,
lib/fog/compute/digitalocean/requests/detach_volume.rb,
lib/fog/compute/digitalocean/requests/list_ssh_keys.rb,
lib/fog/compute/digitalocean/requests/reboot_server.rb,
lib/fog/compute/digitalocean/requests/resize_volume.rb,
lib/fog/compute/digitalocean/requests/create_ssh_key.rb,
lib/fog/compute/digitalocean/requests/delete_ssh_key.rb,
lib/fog/compute/digitalocean/requests/destroy_server.rb,
lib/fog/compute/digitalocean/requests/destroy_volume.rb,
lib/fog/compute/digitalocean/requests/password_reset.rb,
lib/fog/compute/digitalocean/requests/transfer_image.rb,
lib/fog/compute/digitalocean/requests/update_ssh_key.rb,
lib/fog/compute/digitalocean/requests/disable_backups.rb,
lib/fog/compute/digitalocean/requests/get_image_details.rb,
lib/fog/compute/digitalocean/requests/get_droplet_action.rb,
lib/fog/compute/digitalocean/requests/get_server_details.rb,
lib/fog/compute/digitalocean/requests/get_volume_details.rb,
lib/fog/compute/digitalocean/requests/convert_to_snapshot.rb,
lib/fog/compute/digitalocean/requests/list_volume_actions.rb,
lib/fog/compute/digitalocean/requests/list_droplet_actions.rb,
lib/fog/compute/digitalocean/requests/enable_private_networking.rb

Overview

noinspection RubyStringKeysInHashInspection

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



76
77
78
# File 'lib/fog/compute/digitalocean.rb', line 76

def initialize(options={})
  @digitalocean_token = options[:digitalocean_token]
end

Class Method Details

.dataObject



67
68
69
70
71
72
73
74
# File 'lib/fog/compute/digitalocean.rb', line 67

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :servers  => [],
      :ssh_keys => []
    }
  end
end

Instance Method Details

#attach_volume(volume_id, droplet_id, region) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fog/compute/digitalocean/requests/attach_volume.rb', line 39

def attach_volume(volume_id, droplet_id, region)
					response         = Excon::Response.new
					response.status  = 201
					response.body    = {
						"action" => {
							"id" => 72531856,
							"status" => "completed",
							"type" => "attach_volume",
							"started_at" => "2015-11-12T17:51:03Z",
							"completed_at" => "2015-11-12T17:51:14Z",
							"resource_id" => "null",
							"resource_type" => "volume",
							"region" => {
"name" => "New York 1",
"slug" => "nyc1",
"sizes" => [
	"1gb",
	"2gb",
	"4gb",
	"8gb",
	"32gb",
	"64gb",
	"512mb",
	"48gb",
	"16gb"
],
"features" => [
	"private_networking",
	"backups",
	"ipv6",
	"metadata"
],
"available" => true
							},
							"region_slug" => "nyc1"
						}
					}

  response
end

#attach_volume_by_name(volume_name, droplet_id, region) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fog/compute/digitalocean/requests/attach_volume.rb', line 79

def attach_volume_by_name(volume_name, droplet_id, region)
					response         = Excon::Response.new
					response.status  = 201
					response.body    = {
						"action" => {
							"id" => 72531856,
							"status" => "completed",
							"type" => "attach_volume",
							"started_at" => "2015-11-12T17:51:03Z",
							"completed_at" => "2015-11-12T17:51:14Z",
							"resource_id" => "null",
							"resource_type" => "volume",
							"region" => {
"name" => "New York 1",
"slug" => "nyc1",
"sizes" => [
	"1gb",
	"2gb",
	"4gb",
	"8gb",
	"32gb",
	"64gb",
	"512mb",
	"48gb",
	"16gb"
],
"features" => [
	"private_networking",
	"backups",
	"ipv6",
	"metadata"
],
"available" => true
							},
							"region_slug" => "nyc1"
						}
					}

  response
end

#change_kernel(id, kernel) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/change_kernel.rb', line 23

def change_kernel(id, kernel)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "change_kernel",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#convert_to_snapshot(id, name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/convert_to_snapshot.rb', line 23

def convert_to_snapshot(id, name)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id' => 46592838,
      'status' => 'completed',
      'type' => 'convert_to_snapshot',
      'started_at' => '2015-03-24T19:02:47Z',
      'completed_at' => '2015-03-24T19:02:47Z',
      'resource_id' => 11060029,
      'resource_type' => 'image',
      'region' => nil,
      'region_slug' => nil
    }
  }
  response
end

#create_server(name, size, image, region, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fog/compute/digitalocean/requests/create_server.rb', line 46

def create_server(name,
                  size,
                  image,
                  region,
                  options = {})

  response        = Excon::Response.new
  response.status = 202

  response.body = {
    'droplet' => {
      'id'           => 3164494,
      'name'         => name,
      'memory'       => 512,
      'vcpus'        => 1,
      'disk'         => 20,
      'locked'       => true,
      'status'       => 'new',
      'kernel'       => {
        'id'      => 2233,
        'name'    => 'Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic',
        'version' => '3.13.0-37-generic'
      },
      'created_at'   => '2014-11-14T16:36:31Z',
      'features'     => %w(virtio),
      'backup_ids'   => [],
      'snapshot_ids' => [],
      'image'        => {},
      'size'         => {},
      'size_slug'    => '512mb',
      'networks'     => {},
      'region'       => {}
    },
    'links'   => {
      'actions' => [
        {
          'id'   => 36805096,
          'rel'  => "create",
          'href' => "https://api.digitalocean.com/v2/actions/36805096"
        }
      ]
    }
  }

  response
end

#create_ssh_key(name, public_key) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/compute/digitalocean/requests/create_ssh_key.rb', line 29

def create_ssh_key(name, public_key)
  response        = Excon::Response.new
  response.status = 201

  data[:ssh_keys] << {
    "id" => Fog::Mock.random_numbers(6).to_i,
    "fingerprint" => (["00"] * 16).join(':'),
    "public_key" => public_key,
    "name" => name
  }

  response.body ={
    'ssh_key' => data[:ssh_keys].last
  }

  response
end

#create_volume(options) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fog/compute/digitalocean/requests/create_volume.rb', line 30

def create_volume(options)
  response        = Excon::Response.new
  response.status = 201

  response.body ={
    'volume' => {
      "id" => Fog::Mock.random_numbers(6).to_i,
      "fingerprint" => (["00"] * 16).join(':'),
      "region" => options[:region], 
      "size_gigabytes" => 10,
      "description" => options[:description],
      "name" => options[:name]
    }
  }

  response
end

#dataObject



80
81
82
# File 'lib/fog/compute/digitalocean.rb', line 80

def data
  self.class.data[@digitalocean_token]
end

#delete_server(server_id) ⇒ Object



24
25
26
# File 'lib/fog/compute/digitalocean/requests/destroy_server.rb', line 24

def delete_server(server_id)
  destroy_server(server_id)
end

#delete_ssh_key(id) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/fog/compute/digitalocean/requests/delete_ssh_key.rb', line 20

def delete_ssh_key(id)
  self.data[:ssh_keys].select! do |key|
    key["id"] != id
  end

  response        = Excon::Response.new
  response.status = 204
  response
end

#destroy_server(_) ⇒ Object



27
28
29
30
31
# File 'lib/fog/compute/digitalocean/requests/destroy_server.rb', line 27

def destroy_server(_)
  response        = Excon::Response.new
  response.status = 204
  response
end

#destroy_volume(id) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/fog/compute/digitalocean/requests/destroy_volume.rb', line 20

def destroy_volume(id)
  self.data[:volumes].select! do |key|
    key["id"] != id
  end

  response        = Excon::Response.new
  response.status = 204
  response
end

#detach_volume(volume_id, droplet_id, region) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/compute/digitalocean/requests/detach_volume.rb', line 38

def detach_volume(volume_id, droplet_id, region)
      response         = Excon::Response.new
      response.status  = 201
	response.body    = {
		"action" => {
			"id" => 68212773,
			"status" => "in-progress",
			"type" => "detach_volume",
			"started_at" => "2015-10-15T17:46:15Z",
			"completed_at" => nil,
			"resource_id" => nil,
			"resource_type" => "backend",
			"region" => {
				"name" => "New York 1",
				"slug" => "nyc1",
				"sizes" => [
					"512mb",
					"1gb",
					"2gb",
					"4gb",
					"8gb",
					"16gb",
					"32gb",
					"48gb",
					"64gb"
				],
				"features" => [
					"private_networking",
					"backups",
					"ipv6",
					"metadata"
				],
				"available" => true
			},
			"region_slug" => "nyc1"
		}
	}

	response
end

#detach_volume_by_name(volume_name, droplet_id, region) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/fog/compute/digitalocean/requests/detach_volume.rb', line 78

def detach_volume_by_name(volume_name, droplet_id, region)
  response         = Excon::Response.new
  response.status  = 201
					response.body    = {
						"action" => {
							"id" => 68212773,
							"status" => "in-progress",
							"type" => "detach_volume",
							"started_at" => "2015-10-15T17:46:15Z",
							"completed_at" => nil,
							"resource_id" => nil,
							"resource_type" => "backend",
							"region" => {
"name" => "New York 1",
"slug" => "nyc1",
"sizes" => [
	"512mb",
	"1gb",
	"2gb",
	"4gb",
	"8gb",
	"16gb",
	"32gb",
	"48gb",
	"64gb"
],
"features" => [
	"private_networking",
	"backups",
	"ipv6",
	"metadata"
],
"available" => true
							},
							"region_slug" => "nyc1"
						}
					}

					response
end

#disable_backups(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/disable_backups.rb', line 23

def disable_backups(id)
  response        = Excon::Response.new
  response.status = 201
  response.body   = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "disable_backups",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#enable_ipv6(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/enable_ipv6.rb', line 23

def enable_ipv6(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "enable_ipv6",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#enable_private_networking(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/enable_private_networking.rb', line 23

def enable_private_networking(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "enable_private_networking",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#get_droplet_action(droplet_id, action) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/compute/digitalocean/requests/get_droplet_action.rb', line 15

def get_droplet_action(droplet_id, action)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "change_kernel",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#get_image_details(id_or_slug) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/compute/digitalocean/requests/get_image_details.rb', line 16

def get_image_details(id_or_slug)
  response        = Excon::Response.new

  if [7555620, 'nifty-new-snapshot-ubuntu'].include?(id_or_slug)
    response.status = 200

    response.body = {
      'image' =>
      {
        'id' => 7555620,
        'name' => 'Nifty New Snapshot',
        'distribution' => 'Ubuntu',
        'slug' => 'nifty-new-snapshot-ubuntu',
        'public' => false,
        'regions' => [
          'nyc2',
          'nyc2'
          ],
          'created_at' => '2014-11-04T22:23:02Z',
          'min_disk_size' => 20
        }
      }
  else
    response.status = 404
    raise(Fog::Compute::DigitalOcean::NotFound.new("Expected([200]) <=> Actual(404 Not Found)"))
  end

  response
end

#get_server_details(_) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fog/compute/digitalocean/requests/get_server_details.rb', line 16

def get_server_details(_)
  response        = Excon::Response.new
  response.status = 200

  response.body = {
    'droplet' => {
      'id'           => 3164494,
      'name'         => 'example.com',
      'memory'       => 512,
      'vcpus'        => 1,
      'disk'         => 20,
      'locked'       => false,
      'status'       => 'active',
      'kernel'       => {
        'id'      => 2233,
        'name'    => 'Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic',
        'version' => '3.13.0-37-generic'
      },
      'created_at'   => '2014-11-14T16:36:31Z',
      'features'     => %w(ipv6 virtio),
      'backup_ids'   => [],
      'snapshot_ids' => [7938206],
      'image'        => {
        'id'            => 6918990,
        'name'          => '14.04 x64',
        'distribution'  => 'Ubuntu',
        'slug'          => 'ubuntu-14-04-x64',
        'public'        => true,
        'regions'       => %w(nyc1 ams1 sfo1 nyc2 ams2 sgp1 lon1 nyc3 ams3 nyc3),
        'created_at'    => '2014-10-17T20:24:33Z',
        'type'          => 'snapshot',
        'min_disk_size' => 20
      },
      'size'         => {},
      'size_slug'    => '512mb',
      'networks'     => {
        'v4' => [
          {
            'ip_address' => '104.131.186.241',
            'netmask'    => '255.255.240.0',
            'gateway'    => '104.131.176.1',
            'type'       => 'public'
          }
        ],
        'v6' => [
          {
            'ip_address' => '2604:A880:0800:0010:0000:0000:031D:2001',
            'netmask'    => 64,
            'gateway'    => '2604:A880:0800:0010:0000:0000:0000:0001',
            'type'       => 'public'
          }
        ]
      },
      'region'       => {
        'name'      => 'New York 3',
        'slug'      => 'nyc3',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups ipv6 metadata),
        'available' => true
      }
    }
  }

  response
end

#get_ssh_key(_) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/compute/digitalocean/requests/get_ssh_key.rb', line 16

def get_ssh_key(_)
  response        = Excon::Response.new
  response.status = 200

  response.body = {
    'ssh_key' => {
      'id'          => 512190,
      'fingerprint' => '3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa',
      'public_key'  => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example',
      'name'        => 'My SSH Public Key'
    }
  }

  response
end

#get_volume_details(_) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/compute/digitalocean/requests/get_volume_details.rb', line 16

def get_volume_details(_)
  response        = Excon::Response.new
  response.status = 200

  response.body = {
    'volume' => {
      "id" =>  "v4-e098-11e5-ad9f-000f53306ae1",
      "region" => {
        "name" => "New York 1",
        "slug" => "nyc1",
        "sizes" => [
          "512mb",
          "1gb",
          "2gb",
          "4gb",
          "8gb",
          "16gb",
          "32gb",
          "48gb",
          "64gb"
        ],
        "features" => [
          "private_networking",
          "backups",
          "ipv6",
          "metadata"
        ],
        "available" => true
      },
      "droplet_ids" => [

      ],
      "name" => "example",
      "description" => "Block store for examples",
      "size_gigabytes" => 10,
      "created_at" => "2016-03-02T17:00:49Z"
    }
  }

  response
end

#list_droplet_actions(id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/compute/digitalocean/requests/list_droplet_actions.rb', line 15

def list_droplet_actions(id)
  response        = Excon::Response.new
  response.status = 201
  response.body   = {
    'actions' => [
      'action' => {
        'id'            => Fog::Mock.random_numbers(1).to_i,
        'status'        => "in-progress",
        'type'          => "change_kernel",
        'started_at'    => "2014-11-14T16:31:00Z",
        'completed_at'  => nil,
        'resource_id'   => id,
        'resource_type' => "droplet",
        'region'        => "nyc3",
        'region_slug'   => "nyc3"
      }
    ]
  }
  response
end

#list_flavors(filters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/fog/compute/digitalocean/requests/list_flavors.rb', line 17

def list_flavors(filters = {})
  response        = Excon::Response.new
  response.status = 200
  response.body   = {

    'sizes' => [
      {
        'slug'          => '512mb',
        'memory'        => 512,
        'vcpus'         => 1,
        'disk'          => 20,
        'transfer'      => 1.0,
        'price_monthly' => 5.0,
        'price_hourly'  => 0.00744,
        'regions'       => %w(nyc1 sgp1 ams1 ams2 sfo1 nyc2 lon1 nyc3 ams3),
        'available'     => true
      },
      {
        'slug'          => '1gb',
        'memory'        => 1024,
        'vcpus'         => 1,
        'disk'          => 30,
        'transfer'      => 2.0,
        'price_monthly' => 10.0,
        'price_hourly'  => 0.01488,
        'regions'       => %w(nyc2 sgp1 ams1 sfo1 lon1 nyc3 ams3 ams2 nyc1),
        'available'     => true
      },
      {
        'slug'          => '2gb',
        'memory'        => 2048,
        'vcpus'         => 2,
        'disk'          => 40,
        'transfer'      => 3.0,
        'price_monthly' => 20.0,
        'price_hourly'  => 0.02976,
        'regions'       => %w(nyc2 sfo1 ams1 sgp1 ams2 lon1 nyc3 ams3 nyc1),
        'available'     => true
      },
      {
        'slug'          => '4gb',
        'memory'        => 4096,
        'vcpus'         => 2,
        'disk'          => 60,
        'transfer'      => 4.0,
        'price_monthly' => 40.0,
        'price_hourly'  => 0.05952,
        'regions'       => %w(nyc2 sfo1 ams1 sgp1 ams2 lon1 nyc3 ams3 nyc1),
        'available'     => true
      },
      {
        'slug'          => '8gb',
        'memory'        => 8192,
        'vcpus'         => 4,
        'disk'          => 80,
        'transfer'      => 5.0,
        'price_monthly' => 80.0,
        'price_hourly'  => 0.11905,
        'regions'       => %w(nyc2 sfo1 sgp1 ams1 ams2 nyc1 lon1 nyc3 ams3),
        'available'     => true
      },
      {
        'slug'          => '16gb',
        'memory'        => 16384,
        'vcpus'         => 8,
        'disk'          => 160,
        'transfer'      => 6.0,
        'price_monthly' => 160.0,
        'price_hourly'  => 0.2381,
        'regions'       => %w(sgp1 nyc1 sfo1 ams2 nyc3 lon1 nyc2 ams1 ams3),
        'available'     => true
      },
      {
        'slug'          => '32gb',
        'memory'        => 32768,
        'vcpus'         => 12,
        'disk'          => 320,
        'transfer'      => 7.0,
        'price_monthly' => 320.0,
        'price_hourly'  => 0.47619,
        'regions'       => %w(nyc2 sgp1 ams2 nyc1 sfo1 lon1 ams3 nyc3),
        'available'     => true
      },
      {
        'slug'          => '48gb',
        'memory'        => 49152,
        'vcpus'         => 16,
        'disk'          => 480,
        'transfer'      => 8.0,
        'price_monthly' => 480.0,
        'price_hourly'  => 0.71429,
        'regions'       => %w(sgp1 ams2 sfo1 nyc1 lon1 nyc2 ams3 nyc3),
        'available'     => true
      },
      {
        'slug'          => '64gb',
        'memory'        => 65536,
        'vcpus'         => 20,
        'disk'          => 640,
        'transfer'      => 9.0,
        'price_monthly' => 640.0,
        'price_hourly'  => 0.95238,
        'regions'       => %w(sgp1 nyc1 nyc2 sfo1 lon1 ams3 ams2 nyc3),
        'available'     => true
      }
    ],
    'links' => {},
    'meta'  => {'total' => 9}
  }

  response
end

#list_images(filters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/compute/digitalocean/requests/list_images.rb', line 17

def list_images(filters = {})
  next_page = (filters[:page] || 1).to_i + 1

  response        = Excon::Response.new
  response.status = 200
  response.body   = {

    'images' => [
      {
        'id'            => 7555620,
        'name'          => 'Nifty New Snapshot',
        'distribution'  => 'Ubuntu',
        'slug'          => 'nifty-new-snapshot-ubuntu',
        'public'        => false,
        'regions'       => %w(nyc2 nyc3),
        'created_at'    => '2014-11-04T22:23:02Z',
        'type'          => 'snapshot',
        'min_disk_size' => 20,
      }
    ],
    'links'  => {
      'pages' => {
        'last' => 'https://api.digitalocean.com/v2/images?page=56&per_page=1',
        'next' => "https://api.digitalocean.com/v2/images?page=#{next_page}&per_page=1"
      }
    },
    'meta'   => {
      'total' => 56
    }
  }

  response
end

#list_regions(filters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fog/compute/digitalocean/requests/list_regions.rb', line 17

def list_regions(filters = {})
  response        = Excon::Response.new
  response.status = 200
  response.body   = {
    'regions' => [
      {
        'name'      => 'New York 1',
        'slug'      => 'nyc1',
        'sizes'     => [],
        'features'  => %w(virtio backups),
        'available' => false
      },
      {
        'name'      => 'Amsterdam 1',
        'slug'      => 'ams1',
        'sizes'     => [],
        'features'  => %w(virtio backups),
        'available' => false
      },
      {
        'name'      => 'San Francisco 1',
        'slug'      => 'sfo1',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio backups metadata),
        'available' => true
      },
      {
        'name'      => 'New York 2',
        'slug'      => 'nyc2',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups),
        'available' => true
      },
      {
        'name'      => 'Amsterdam 2',
        'slug'      => 'ams2',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups metadata),
        'available' => true
      },
      {
        'name'      => 'Singapore 1',
        'slug'      => 'sgp1',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups ipv6 metadata),
        'available' => true
      },
      {
        'name'      => 'London 1',
        'slug'      => 'lon1',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups ipv6 metadata),
        'available' => true
      },
      {
        'name'      => 'New York 3',
        'slug'      => 'nyc3',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups ipv6 metadata),
        'available' => true
      },
      {
        'name'      => 'Amsterdam 3',
        'slug'      => 'ams3',
        'sizes'     => %w(32gb 16gb 2gb 1gb 4gb 8gb 512mb 64gb 48gb),
        'features'  => %w(virtio private_networking backups ipv6 metadata),
        'available' => true
      }
    ],
    'links'   => {},
    'meta'    => {'total' => 9}
  }

  response
end

#list_servers(filters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/compute/digitalocean/requests/list_servers.rb', line 17

def list_servers(filters = {})
  response = Excon::Response.new
  response.status = 200
  response.body = {
      "status" => "OK",
      "droplets"  => self.data[:servers],
      "links" => {},
      "meta" => {
        "total" => data[:servers].count
      }
  }
  response
end

#list_ssh_keys(filters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/compute/digitalocean/requests/list_ssh_keys.rb', line 17

def list_ssh_keys(filters = {})
  response        = Excon::Response.new
  response.status = 200
  response.body   = {
    "ssh_keys" => data[:ssh_keys] ||
      [
        {
          "id" => 512189,
          "fingerprint" => "3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa",
          "public_key" => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example",
          "name" => "My SSH Public Key"
        }
      ],
    "links" => {
    },
    "meta" => {
      "total" => data[:ssh_keys].count || 1
    }
  }
  response
end

#list_volume_actions(id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/compute/digitalocean/requests/list_volume_actions.rb', line 15

def list_volume_actions(id)
  response        = Excon::Response.new
  response.status = 201
  response.body   = {
    "actions" => [
      {
        "id" => 72531856,
        "status" => "completed",
        "type" => "attach_volume",
        "started_at" => "2015-11-21T21:51:09Z",
        "completed_at" => "2015-11-21T21:51:09Z",
        "resource_id" => nil,
        "resource_type" => "volume",
        "region" => {
          "name" => "New York 1",
          "slug" => "nyc1",
          "sizes" => [
            "512mb",
            "1gb",
            "2gb",
            "4gb",
            "8gb",
            "16gb",
            "32gb",
            "48gb",
            "64gb"
          ],
          "features" => [
            "private_networking",
            "backups",
            "ipv6",
            "metadata"
          ],
          "available" => true
        },
        "region_slug" => "nyc1"
      }
    ],
    "links" => {
    },
    "meta" => {
      "total" => 1
    }
  }
  response
end

#list_volumes(filters = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/compute/digitalocean/requests/list_volumes.rb', line 17

def list_volumes(filters = {})
  response        = Excon::Response.new
					response.status = 200
					response.body   = {
						"volumes" => [
							{
"id" => "506f78a4-e098-11e5-ad9f-000f53306ae1",
"region" => {
	"name" => "New York 1",
	"slug" =>"nyc1",
	"sizes" => [
		"512mb",
		"1gb",
		"2gb",
		"4gb",
		"8gb",
		"16gb",
		"32gb",
		"48gb",
		"64gb"
	],
	"features" => [
		"private_networking",
		"backups",
		"ipv6",
		"metadata"
	],
	"available" => true
},
"droplet_ids" => [],
"name" =>"example",
"description" =>"Block store for examples",
"size_gigabytes" =>10,
"created_at" =>"2016-03-02T17:00:49Z"
							}
						],
						"links" => {},
						"meta" => {
							"total" => 1
						}
					}

  response
end

#password_reset(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/password_reset.rb', line 23

def password_reset(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "password_reset",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#power_cycle(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/power_cycle.rb', line 23

def power_cycle(id)
  response        = Excon::Response.new
  response.status = 201
  response.body   = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "power_cycle",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#power_off(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/power_off.rb', line 23

def power_off(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "power_off",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#power_on(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/power_on.rb', line 23

def power_on(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "power_on",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#reboot_server(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/reboot_server.rb', line 23

def reboot_server(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "reboot",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#rebuild(id, image) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/rebuild.rb', line 23

def rebuild(id, image)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "rebuild",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#rename(id, name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/rename.rb', line 23

def rename(id, name)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "rename",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#reset_dataObject



84
85
86
# File 'lib/fog/compute/digitalocean.rb', line 84

def reset_data
  self.class.data.delete(@digitalocean_token)
end

#resize(id, resize_disk, size) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/compute/digitalocean/requests/resize.rb', line 27

def resize(id, resize_disk, size)
  response        = Excon::Response.new
  response.status = 201
  response.body   = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "resize",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#resize_volume(volume_id, size, region) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/compute/digitalocean/requests/resize_volume.rb', line 23

def resize_volume(volume_id, size, region)
					response         = Excon::Response.new
					response.status  = 201
  response.body    = {
    "action" => {
      "id" => 72531856,
      "status" => "in-progress",
      "type" => "resize",
      "started_at" => "2015-11-12T17:51:03Z",
      "completed_at" => "2015-11-12T17:51:14Z",
      "resource_id" => nil,
      "resource_type" => "volume",
      "region" => {
        "name" => "New York 1",
        "slug" => "nyc1",
        "sizes" => [
          "1gb",
          "2gb",
          "4gb",
          "8gb",
          "32gb",
          "64gb",
          "512mb",
          "48gb",
          "16gb"
        ],
        "features" => [
          "private_networking",
          "backups",
          "ipv6",
          "metadata"
        ],
        "available" => true
      },
      "region_slug" => "nyc1"
    }
  }
  response
end

#restore(id, image) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/restore.rb', line 23

def restore(id, image)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "restore",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#shutdown(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/shutdown.rb', line 23

def shutdown(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "shutdown",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#snapshot(id, name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/snapshot.rb', line 23

def snapshot(id, name)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "snapshot",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end

#transfer_image(id, name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/transfer_image.rb', line 23

def transfer_image(id, name)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id' => 36805527,
      'status' => 'in-progress',
      'type' => 'transfer',
      'started_at' => '2014-11-14T16:42:45Z',
      'completed_at' => nil,
      'resource_id' => 7938269,
      'resource_type' => 'image',
      'region' => 'nyc3',
      'region_slug' => 'nyc3'
    }
  }
  response
end

#update_ssh_key(key_id, name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/compute/digitalocean/requests/update_ssh_key.rb', line 28

def update_ssh_key(key_id, name)
  response        = Excon::Response.new
  response.status = 200

  response.body ={
    'ssh_key' => {
      'id'          => 512190,
      'fingerprint' => "3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa",
      'public_key'  => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQDDHr/jh2Jy4yALcK4JyWbVkPRaWmhck3IgCoeOO3z1e2dBowLh64QAM+Qb72pxekALga2oi4GvT+TlWNhzPH4V example",
      'name'        => "My SSH Public Key"
    }
  }

  response
end

#upgrade(id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/compute/digitalocean/requests/upgrade.rb', line 23

def upgrade(id)
  response         = Excon::Response.new
  response.status  = 201
  response.body    = {
    'action' => {
      'id'            => Fog::Mock.random_numbers(1).to_i,
      'status'        => "in-progress",
      'type'          => "upgrade",
      'started_at'    => "2014-11-14T16:31:00Z",
      'completed_at'  => nil,
      'resource_id'   => id,
      'resource_type' => "droplet",
      'region'        => "nyc3",
      'region_slug'   => "nyc3"
    }
  }
  response
end