Module: Fog::OpenStack::Volume::Mock

Included in:
V1::Mock, V2::Mock, V3::Mock
Defined in:
lib/fog/openstack/volume/requests/get_quota.rb,
lib/fog/openstack/volume/requests/list_zones.rb,
lib/fog/openstack/volume/requests/set_tenant.rb,
lib/fog/openstack/volume/requests/update_quota.rb,
lib/fog/openstack/volume/requests/create_backup.rb,
lib/fog/openstack/volume/requests/delete_backup.rb,
lib/fog/openstack/volume/requests/delete_volume.rb,
lib/fog/openstack/volume/requests/extend_volume.rb,
lib/fog/openstack/volume/requests/update_volume.rb,
lib/fog/openstack/volume/requests/list_snapshots.rb,
lib/fog/openstack/volume/requests/delete_snapshot.rb,
lib/fog/openstack/volume/requests/get_quota_usage.rb,
lib/fog/openstack/volume/requests/update_snapshot.rb,
lib/fog/openstack/volume/requests/list_volume_types.rb,
lib/fog/openstack/volume/requests/create_volume_type.rb,
lib/fog/openstack/volume/requests/delete_volume_type.rb,
lib/fog/openstack/volume/requests/get_backup_details.rb,
lib/fog/openstack/volume/requests/get_quota_defaults.rb,
lib/fog/openstack/volume/requests/update_volume_type.rb,
lib/fog/openstack/volume/requests/list_backups_detailed.rb,
lib/fog/openstack/volume/requests/get_volume_type_details.rb,
lib/fog/openstack/volume/requests/list_snapshots_detailed.rb

Instance Method Summary collapse

Instance Method Details

#create_backup(_options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fog/openstack/volume/requests/create_backup.rb', line 30

def create_backup(_options = {})
  response = Excon::Response.new
  response.status = 202
  response.body = {
    "backup" => {
      "id" => "1",
      "volume_id" => "2",
      "name" => "backup 1",
      "status" => "available",
      "size" => 1,
      "object_count" => 16,
      "container" => "testcontainer",
    }
  }
  response
end

#create_volume_type(_options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/openstack/volume/requests/create_volume_type.rb', line 24

def create_volume_type(_options = {})
  response = Excon::Response.new
  response.status = 202
  response.body = {
    "volume_type" => {
      "id"          => "6685584b-1eac-4da6-b5c3-555430cf68ff",
      "name"        => "vol-type-001",
      "extra_specs" => {
        "capabilities" => "gpu"
      }
    }
  }
  response
end

#delete_backup(_backup_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/volume/requests/delete_backup.rb', line 15

def delete_backup(_backup_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#delete_snapshot(_snapshot_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/volume/requests/delete_snapshot.rb', line 15

def delete_snapshot(_snapshot_id)
  response = Excon::Response.new
  response.status = 202
  response
end

#delete_volume(_volume_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/volume/requests/delete_volume.rb', line 15

def delete_volume(_volume_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#delete_volume_type(_volume_type_id) ⇒ Object



15
16
17
18
19
# File 'lib/fog/openstack/volume/requests/delete_volume_type.rb', line 15

def delete_volume_type(_volume_type_id)
  response = Excon::Response.new
  response.status = 204
  response
end

#extend_volume(_volume_id, _size) ⇒ Object



17
18
19
20
21
# File 'lib/fog/openstack/volume/requests/extend_volume.rb', line 17

def extend_volume(_volume_id, _size)
  response = Excon::Response.new
  response.status = 202
  response
end

#get_backup_details(_backup_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/openstack/volume/requests/get_backup_details.rb', line 15

def get_backup_details(_backup_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "backup" => {
      "id" => "1",
      "volume_id" => "2",
      "name" => "backup 1",
      "status" => "available",
      "size" => 1,
      "object_count" => 16,
      "container" => "testcontainer",
    }
  }
  response
end

#get_quota(tenant_id) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/openstack/volume/requests/get_quota.rb', line 15

def get_quota(tenant_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'quota_set' => (data[:quota_updated] || data[:quota]).merge('id' => tenant_id)
  }
  response
end

#get_quota_defaults(tenant_id) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/fog/openstack/volume/requests/get_quota_defaults.rb', line 15

def get_quota_defaults(tenant_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'quota_set' => data[:quota].merge('id' => tenant_id)
  }
  response
end

#get_quota_usage(tenant_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
# File 'lib/fog/openstack/volume/requests/get_quota_usage.rb', line 15

def get_quota_usage(tenant_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'quota_set' => {
      'gigabytes' => {
        'reserved' => 0,
        'limit'    => -1,
        'in_use'   => 160
      },
      'snapshots' => {
        'reserved' => 0,
        'limit'    => 50,
        'in_use'   => 3
      },
      'volumes'   => {
        'reserved' => 0,
        'limit'    => 50,
        'in_use'   => 5
      },
      'id'        => tenant_id
    }
  }
  response
end

#get_volume_type_details(_volume_type_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/openstack/volume/requests/get_volume_type_details.rb', line 15

def get_volume_type_details(_volume_type_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    "volume_type" => {
      "id"          => "1",
      "name"        => "type 1",
      "extra_specs" => {
        "volume_backend_name" => "type 1 backend name"
      }
    }
  }
  response
end

#list_backups_detailed(_options = {}) ⇒ 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
# File 'lib/fog/openstack/volume/requests/list_backups_detailed.rb', line 16

def list_backups_detailed(_options = {})
  response = Excon::Response.new
  response.status = 200
  data[:backups] ||= [
    {
      "id" => "1",
      "volume_id" => "2",
      "name" => "backup 1",
      "status" => "available",
      "size" => 1,
      "object_count" => 16,
      "container" => "testcontainer",
    },
    {
      "id" => "2",
      "volume_id" => "2",
      "name" => "backup 2",
      "status" => "available",
      "size" => 1,
      "object_count" => 16,
      "container" => "testcontainer",
    }
  ]
  response.body = { 'backups' => data[:backups] }
  response
end

#list_snapshots(_detailed = true, _options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/fog/openstack/volume/requests/list_snapshots.rb', line 30

def list_snapshots(_detailed = true, _options = {})
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'snapshots' => [get_snapshot_details.body["snapshot"]]
  }
  response
end

#list_snapshots_detailed(_options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/fog/openstack/volume/requests/list_snapshots_detailed.rb', line 16

def list_snapshots_detailed(_options = {})
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'snapshots' => [get_snapshot_details.body["snapshot"]]
  }
  response
end

#list_volume_types(_options = {}) ⇒ Object



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

def list_volume_types(_options = {})
  response = Excon::Response.new
  response.status = 200
  data[:volume_types] ||= [
    {
      "id"          => "1",
      "name"        => "type 1",
      "extra_specs" => {
        "volume_backend_name" => "type 1 backend name"
      }
    },
    {
      "id"          => "2",
      "name"        => "type 2",
      "extra_specs" => {
        "volume_backend_name" => "type 2 backend name"
      }
    }
  ]
  response.body = {'volume_types' => data[:volume_types]}
  response
end

#list_zones(_options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/openstack/volume/requests/list_zones.rb', line 16

def list_zones(_options = {})
  Excon::Response.new(
    :body   => {
      "availabilityZoneInfo" => [
        {
          "zoneState" => {"available" => true},
          "zoneName"  => "nova"
        }
      ]
    },
    :status => 200
  )
end

#set_tenant(_tenant) ⇒ Object



13
14
15
# File 'lib/fog/openstack/volume/requests/set_tenant.rb', line 13

def set_tenant(_tenant)
  true
end

#update_quota(_tenant_id, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/fog/openstack/volume/requests/update_quota.rb', line 16

def update_quota(_tenant_id, options = {})
  data[:quota_updated] = data[:quota].merge options

  response = Excon::Response.new
  response.status = 200
  response.body = {'quota_set' => data[:quota_updated]}
  response
end

#update_snapshot(snapshot_id, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/openstack/volume/requests/update_snapshot.rb', line 16

def update_snapshot(snapshot_id, options = {})
  unless snapshot_id
    raise ArgumentError, 'snapshot_id is required'
  end
  response = Excon::Response.new
  if snapshot = data[:snapshots][snapshot_id]
    response.status                 = 200
    snapshot['display_name']        = options['display_name'] if options['display_name']
    snapshot['display_description'] = options['display_description'] if options['display_description']
    snapshot['name']                = options['name'] if options['name']
    snapshot['description']         = options['description'] if options['description']
    snapshot['metadata']            = options['metadata'] if options['metadata']
    response.body                   = {'snapshot' => snapshot}
    response
  else
    raise Fog::HP::BlockStorageV2::NotFound
  end
end

#update_volume(volume_id, data = {}) ⇒ Object



5
6
7
8
9
10
# File 'lib/fog/openstack/volume/requests/update_volume.rb', line 5

def update_volume(volume_id, data = {})
  response        = Excon::Response.new
  response.status = 200
  response.body   = {'volume' => data.merge('id' => volume_id)}
  response
end

#update_volume_type(_volume_type_id, _options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/openstack/volume/requests/update_volume_type.rb', line 24

def update_volume_type(_volume_type_id, _options = {})
  response = Excon::Response.new
  response.status = 202
  response.body = {
    "volume_type" => {
      "id"          => "6685584b-1eac-4da6-b5c3-555430cf68ff",
      "name"        => "vol-type-001",
      "extra_specs" => {
        "capabilities" => "gpu"
      }
    }
  }
  response
end