class Fog::Compute::ProfitBricks::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/profitbricks/compute.rb, line 222
def self.data
  dc1_id   = Fog::UUID.uuid
  dc2_id   = Fog::UUID.uuid
  serv1_id = Fog::UUID.uuid
  vol1_id  = Fog::UUID.uuid
  vol2_id  = Fog::UUID.uuid
  req1_id  = Fog::UUID.uuid
  req2_id  = Fog::UUID.uuid
  nic1_id  = Fog::UUID.uuid
  nic2_id  = Fog::UUID.uuid
  ipb1_id  = Fog::UUID.uuid
  ipb2_id  = Fog::UUID.uuid
  fwr1_id  = Fog::UUID.uuid
  fwr2_id  = Fog::UUID.uuid
  lb1_id   = Fog::UUID.uuid
  lb2_id   = Fog::UUID.uuid

  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :datacenters => {
        "id"    => "datacenters",
        "type"  => "collection",
        "href"  => "https://api.profitbricks.com/rest/v2/datacenters",
        "items" =>
        [
          {
            'id'        => dc1_id,
            'type'      => 'datacenter',
            'href'      => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}",
            'metadata'  => {
              'createdDate' => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8702',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name' => 'dc_1',
              'description' => 'testing fog rest implementation',
              'location'    => 'us/las',
              'version'     => 1,
              'features'    => %w(SSD MULTIPLE_CPU)
            }
          },
          {
            'id'        => dc2_id,
            'type'      => 'datacenter',
            'href'      => "https://api.profitbricks.com/rest/v2/datacenters/#{dc2_id}",
            'metadata'  => {
              'createdDate' => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8702',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name' => 'dc_2',
              'description' => 'testing fog rest implementation',
              'location'    => 'de/fkb',
              'version'     => 1,
              'features'    => %w(SSD MULTIPLE_CPU)
            }
          }
        ]
      },
      :servers => {
        'id'    => 'servers',
        'type'  => 'collection',
        "href"  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers",
        'items' =>
        [
          {
            'id'    => serv1_id,
            'type'  => 'server',
            'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}",
            'metadata' => {
              'createdDate'       => '2014-10-20T21:20:46Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '0018832d7a7ba455db74ac41ae9f11fe',
              'lastModifiedDate'  => '2015-03-18T21:31:10Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'              => 'FogTestServer_1',
              'cores'             => 1,
              'ram'               => 1024,
              'availabilityZone'  => 'AUTO',
              'vmState'           => 'RUNNING',
              'bootVolume'    => {
                'id'          => 'c04a2198-7e60-4bc0-b869-6e9c9dbcb8e1',
                'type'        => 'volume',
                'href'        => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/c04a2198-7e60-4bc0-b869-6e9c9dbcb8e1",
                'metadata'    => {
                  'createdDate'       => '2014-10-20T21:20:46Z',
                  'createdBy'         => 'test@stackpointcloud.com',
                  'etag'              => '7a539b539d8ca9e08c5ac5e63c9c4c8f',
                  'lastModifiedDate'  => '2014-10-20T21:20:46Z',
                  'lastModifiedBy'    => 'test@stackpointcloud.com',
                  'state'             => 'AVAILABLE'
                },
                'properties' => {
                  'name'                => 'Storage',
                  'type'                => 'HDD',
                  'size'                => 50,
                  'image'               => '4f363db0-4955-11e4-b362-52540066fee9',
                  'bus'                 => 'VIRTIO',
                  'licenceType'         => 'LINUX',
                  'cpuHotPlug'          => 'true',
                  'cpuHotUnplug'        => 'false',
                  'ramHotPlug'          => 'true',
                  'ramHotUnplug'        => 'false',
                  'nicHotPlug'          => 'true',
                  'nicHotUnplug'        => 'true',
                  'discVirtioHotPlug'   => 'true',
                  'discVirtioHotUnplug' => 'true',
                  'discScsiHotPlug'     => 'false',
                  'discScsiHotUnplug'   => 'false',
                  'deviceNumber'        => 1
                }
              },
              'cpuFamily' => 'AMD_OPTERON'
            },
            'entities' => {
              'cdroms'  => {
                'id'    => "#{serv1_id}/cdroms",
                'type'  => 'collection',
                'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/cdroms",
                'items' => []
              },
              'volumes' => {
                'id'    => "#{serv1_id}/volumes",
                'type'  => 'collection',
                'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/volumes",
                'items' =>
                [
                  {
                    'id'          => 'c04a2198-7e60-4bc0-b869-6e9c9dbcb8e1',
                    'type'        => 'volume',
                    'href'        => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/c04a2198-7e60-4bc0-b869-6e9c9dbcb8e1",
                    'metadata'    => {
                      'createdDate'       => '2014-10-20T21:20:46Z',
                      'createdBy'         => 'test@stackpointcloud.com',
                      'etag'              => '7a539b539d8ca9e08c5ac5e63c9c4c8f',
                      'lastModifiedDate'  => '2014-10-20T21:20:46Z',
                      'lastModifiedBy'    => 'test@stackpointcloud.com',
                      'state'             => 'AVAILABLE'
                    },
                    'properties' => {
                      'name'                => 'Storage',
                      'type'                => 'HDD',
                      'size'                => 50,
                      'image'               => '4f363db0-4955-11e4-b362-52540066fee9',
                      'bus'                 => 'VIRTIO',
                      'licenceType'         => 'LINUX',
                      'cpuHotPlug'          => 'true',
                      'cpuHotUnplug'        => 'false',
                      'ramHotPlug'          => 'true',
                      'ramHotUnplug'        => 'false',
                      'nicHotPlug'          => 'true',
                      'nicHotUnplug'        => 'true',
                      'discVirtioHotPlug'   => 'true',
                      'discVirtioHotUnplug' => 'true',
                      'discScsiHotPlug'     => 'false',
                      'discScsiHotUnplug'   => 'false',
                      'deviceNumber'        => 1
                    }
                  },
                  {
                    'id'          => '5c4d37ca-d620-4546-8b24-f92e3c608c2c',
                    'type'        => 'volume',
                    'href'        => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/5c4d37ca-d620-4546-8b24-f92e3c608c2c",
                    'metadata'    => {
                      'createdDate'       => '2015-03-18T21:31:10Z',
                      'createdBy'         => 'test@stackpointcloud.com',
                      'etag'              => '0018832d7a7ba455db74ac41ae9f11fe',
                      'lastModifiedDate'  => '2015-03-18T21:31:10Z',
                      'lastModifiedBy'    => 'test@stackpointcloud.com',
                      'state'             => 'AVAILABLE'
                    },
                    'properties' => {
                      'name'                => 'Docker Registry Volume',
                      'type'                => 'HDD',
                      'size'                => 50,
                      'bus'                 => 'VIRTIO',
                      'licenceType'         => 'OTHER',
                      'cpuHotPlug'          => 'false',
                      'cpuHotUnplug'        => 'false',
                      'ramHotPlug'          => 'false',
                      'ramHotUnplug'        => 'false',
                      'nicHotPlug'          => 'false',
                      'nicHotUnplug'        => 'false',
                      'discVirtioHotPlug'   => 'false',
                      'discVirtioHotUnplug' => 'false',
                      'discScsiHotPlug'     => 'false',
                      'discScsiHotUnplug'   => 'false',
                      'deviceNumber'        => 2
                    }
                  }
                ]
              },
              'nics'    => {
                'id'    => "#{serv1_id}/nics",
                'type'  => 'collection',
                'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics",
                'items' =>
                [
                  {
                    'id'          => '01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d',
                    'type'        => 'nic',
                    'href'        => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d",
                    'metadata'    => {
                      'createdDate'       => '2015-02-09T22:46:38Z',
                      'createdBy'         => 'test@stackpointcloud.com',
                      'etag'              => 'b4854a82738079d2c7f43b5324bd92e3',
                      'lastModifiedDate'  => '2015-02-09T22:46:38Z',
                      'lastModifiedBy'    => 'test@stackpointcloud.com',
                      'state'             => 'AVAILABLE'
                    },
                    'properties' => {
                      'mac'             => '00:02:94:9e:f4:b0',
                      'ips'             => ['210.94.35.77'],
                      'dhcp'            => 'true',
                      'lan'             => 1,
                      'firewallActive'  => 'false'
                    },
                    'entities' => {
                      'firewallrules' => {
                        'id'    => '01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d/firewallrules',
                        'type'  => 'collection',
                        'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/664f0f1c-7384-462b-8f0c-cfc4c3f6e2a3/nics/01ea3bd9-047c-4941-85cf-ed6b7a2d1d7d/firewallrules",
                        'items' => []
                      }
                    }
                  }
                ]
              }
            },
            'datacenter_id' => dc1_id
          }
        ]
      },
      :locations => {
        "id"    => "locations",
        "type"  => "collection",
        "href"  => "https://api.profitbricks.com/rest/v2/locations",
        "items" =>
        [
          {
            'id'          => 'de/fkb',
            'type'        => 'location',
            'href'        => 'https://api.profitbricks.com/rest/v2/locations/de/fkb',
            'properties'  => {
              'name'      => 'karlsruhe',
              'features'  => %w(SSD MULTIPLE_CPU)
            }
          },
          {
            'id'          => 'de/fra',
            'type'        => 'location',
            'href'        => 'https://api.profitbricks.com/rest/v2/locations/de/fra',
            'properties'  => {
              'name'      => 'frankfurt',
              'features'  => %w(SSD MULTIPLE_CPU)
            }
          },
          {
            'id'          => 'us/las',
            'type'        => 'location',
            'href'        => 'https://api.profitbricks.com/rest/v2/locations/us/las',
            'properties'  => {
              'name'      => 'lasvegas',
              'features'  => %w(SSD MULTIPLE_CPU)
            }
          }
        ]
      },
      :images =>
      {
        "id"    => "images",
        "type"  => "collection",
        "href"  => "https://api.profitbricks.com/rest/v2/images",
        "items" =>
        [
          {
            'id'              => 'dfcb40db-28b5-11e6-9336-52540005ab80',
            'type'            => 'image',
            'href'            => 'https=>//api.profitbricks.com/rest/v2/images/dfcb40db-28b5-11e6-9336-52540005ab80',
            'metadata'        => {
              'createdDate'       => '2016-06-02T11:33:49Z',
              'createdBy'         => 'System',
              'etag'              => '9909709d99655c6f31aca789998d7d89',
              'lastModifiedDate'  => '2016-06-02T11:33:49Z',
              'lastModifiedBy'    => 'System',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'CentOS-6.8-x86_64-netinstall.iso',
              'description'         => '',
              'location'            => 'us/las',
              'size'                => 0.23,
              'cpuHotPlug'          => 'true',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'true',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'true',
              'nicHotUnplug'        => 'true',
              'discVirtioHotPlug'   => 'true',
              'discVirtioHotUnplug' => 'true',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'licenceType'         => 'LINUX',
              'imageType'           => 'CDROM',
              'public'              => 'true'
            }
          },
          {
            'id'              => 'dfcb40db-28b5-11e6-9336-52540005ab80',
            'type'            => 'image',
            'href'            => 'https=>//api.profitbricks.com/rest/v2/images/dfcb40db-28b5-11e6-9336-52540005ab80',
            'metadata'        => {
              'createdDate'       => '2016-06-02T11:33:49Z',
              'createdBy'         => 'System',
              'etag'              => '9909709d99655c6f31aca789998d7d89',
              'lastModifiedDate'  => '2016-06-02T11:33:49Z',
              'lastModifiedBy'    => 'System',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'CentOS-6.8-x86_64-netinstall.iso',
              'description'         => '',
              'location'            => 'us/las',
              'size'                => 0.23,
              'cpuHotPlug'          => 'true',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'true',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'true',
              'nicHotUnplug'        => 'true',
              'discVirtioHotPlug'   => 'true',
              'discVirtioHotUnplug' => 'true',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'licenceType'         => 'LINUX',
              'imageType'           => 'HDD',
              'public'              => 'true'
            }
          },
          {
            'id'              => '05cadf29-6c12-11e4-beeb-52540066fee9',
            'type'            => 'image',
            'href'            => 'https=>//api.profitbricks.com/rest/v2/images/05cadf29-6c12-11e4-beeb-52540066fee9',
            'metadata'        => {
              'createdDate'       => '2014-11-14T15:22:19Z',
              'createdBy'         => 'System',
              'etag'              => '957e0eac7456fa7554e73bf0d18860eb',
              'lastModifiedDate'  => '2014-11-14T15=>22=>19Z',
              'lastModifiedBy'    => 'System',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'Microsoft-SQL-2012-Full-trial-english.iso',
              'description'         => '',
              'location'            => 'us/las',
              'size'                => 4,
              'cpuHotPlug'          => 'false',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'false',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'false',
              'nicHotUnplug'        => 'false',
              'discVirtioHotPlug'   => 'false',
              'discVirtioHotUnplug' => 'false',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'licenceType'         => 'OTHER',
              'imageType'           => 'CDROM',
              'public'              => 'true'
            }
          }
        ]
      },
      :flavors =>
      [
        {
          'flavorId'   => Fog::UUID.uuid,
          'flavorName' => 'Micro',
          'ram'        => 1024,
          'disk'       => 50,
          'cores'      => 1
        },
        {
          'flavorId'   => Fog::UUID.uuid,
          'flavorName' => 'Small',
          'ram'        => 2048,
          'disk'       => 50,
          'cores'      => 1
        }
      ],
      :volumes => {
        "id"    => "#{dc1_id}/volumes",
        "type"  => 'collection',
        "href"  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes",
        "items" =>
        [
          {
            'id'        => vol1_id,
            'type'      => 'volume',
            'href'      => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/#{vol1_id}",
            'metadata'  => {
              'createdDate'       => '2015-03-18T19:00:51Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => 'c4a2fde6ba91a038ff953b939cc21efe',
              'lastModifiedDate'  => '2015-03-18T19=>00=>51Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'master 1 Storage',
              'type'                => 'HDD',
              'size'                => 50,
              'image'               => '681673e7-bfc2-11e4-850c-52540066fee9',
              'bus'                 => 'VIRTIO',
              'licenceType'         => 'OTHER',
              'cpuHotPlug'          => 'true',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'false',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'true',
              'nicHotUnplug'        => 'true',
              'discVirtioHotPlug'   => 'true',
              'discVirtioHotUnplug' => 'true',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'deviceNumber'        => 1
            },
            'datacenter_id' => dc1_id
          },
          {
            'id'        => vol2_id,
            'type'      => 'volume',
            'href'      => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/#{vol2_id}",
            'metadata'  => {
              'createdDate'       => '2015-03-18T21:31:10Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '0018832d7a7ba455db74ac41ae9f11fe',
              'lastModifiedDate'  => '2015-03-18T21:31:10Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'Docker Registry Volume',
              'type'                => 'HDD',
              'size'                => 50,
              'bus'                 => 'VIRTIO',
              'licenceType'         => 'OTHER',
              'cpuHotPlug'          => 'false',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'false',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'false',
              'nicHotUnplug'        => 'false',
              'discVirtioHotPlug'   => 'false',
              'discVirtioHotUnplug' => 'false',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'deviceNumber'        => 2
            },
            'datacenter_id' => dc1_id
          }
        ]
      },
      :lans => {
        'id'    => "#{dc1_id}/lans",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/lans",
        'items' =>
        [
          {
            'id'          => '9',
            'type'        => 'nic',
            'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/lans/9",
            'metadata'    => {
              'createdDate'       => '2015-03-18T19:00:51Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => 'faa67fbacb1c0e2e02cf9650657251f1',
              'lastModifiedDate'  => '2015-03-18T19:00:51Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'            => 'FogTestLAN_1',
              'public'          => 'true'
            },
            'entities' => {
              'nics' => {
                'id'    => '9/nics',
                'type'  => 'collection',
                'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/lans/9/nics",
                'items' => []
              }
            },
            'datacenter_id' => dc1_id
          }
        ]
      },
      :nics => {
        'id'    => "#{serv1_id}/nics",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics",
        'items' =>
        [
          {
            'id'          => nic1_id,
            'type'        => 'nic',
            'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}",
            'metadata'    => {
              'createdDate'       => '2015-03-18T19:00:51Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => 'faa67fbacb1c0e2e02cf9650657251f1',
              'lastModifiedDate'  => '2015-03-18T19:00:51Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'            => 'FogTestNIC_1',
              'mac'             => '02:01:36:5f:09:da',
              'ips'             => ['10.9.194.12'],
              'dhcp'            => 'true',
              'lan'             => 2,
              'firewallActive'  => 'false'
            },
            'entities' => {
              'firewallrules' => {
                'id'    => "#{nic1_id}/firewallrules",
                'type'  => 'collection',
                'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}/firewallrules",
                'items' => []
              }
            },
            'datacenter_id' => dc1_id
          },
          {
            'id'          => nic2_id,
            'type'        => 'nic',
            'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic2_id}",
            'metadata'    => {
              'createdDate'       => '2015-03-18T19:00:51Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => 'faa67fbacb1c0e2e02cf9650657251f1',
              'lastModifiedDate'  => '2015-03-18T19:00:51Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'            => 'FogTestNIC_2',
              'mac'             => '03:01:60:bf:d4:8a',
              'ips'             => ['192.96.159.188'],
              'dhcp'            => 'true',
              'lan'             => 1,
              'firewallActive'  => 'false'
            },
            'entities' => {
              'firewallrules' => {
                'id' => 'cf6d01d3-295d-48bd-8d07-568cce63cbbc/firewallrules',
                'type' => 'collection',
                'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic2_id}/firewallrules",
                'items' => []
              }
            },
            'datacenter_id' => dc1_id
          }
        ]
      },
      :snapshots => {
        'id'    => 'snapshots',
        'type'  => 'collection',
        'href'  => 'https =>//api.profitbricks.com/rest/v2/snapshots',
        'items' =>
        [
          {
            'id'          => '3d52b13d-bec4-49de-ad05-fd2f8c687be6',
            'type'        => 'snapshot',
            'href'        => 'https =>//api.profitbricks.com/rest/v2/snapshots/3d52b13d-bec4-49de-ad05-fd2f8c687be6',
            'metadata'    => {
              'createdDate'       => '2016-08-07T22:28:38Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '83ad78a4757ab0d9bdeaebc3a6485dcf',
              'lastModifiedDate'  => '2016-08-07T22:28:38Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'FogTestSnapshot',
              'description'         => 'Testing fog create volume snapshot',
              'location'            => 'de/fkb',
              'size'                => 5,
              'cpuHotPlug'          => 'false',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'false',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'false',
              'nicHotUnplug'        => 'false',
              'discVirtioHotPlug'   => 'false',
              'discVirtioHotUnplug' => 'false',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'licenceType'         => 'LINUX'
            }
          }
        ]
      },
      :requests => {
        'id'    => 'requests',
        'type'  => 'collection',
        'href'  => 'https=>//api.profitbricks.com/rest/v2/requests',
        'items' =>
        [
          {
            'id'        => req1_id,
            'type'      => 'request',
            'href'      => "https=>//api.profitbricks.com/rest/v2/requests/#{req1_id}",
            'metadata'  => {
              'createdDate'   => '2016-08-07T23:32:17Z',
              'createdBy'     => 'test@stackpointcloud.com',
              'etag'          => '37a6259cc0c1dae299a7866489dff0bd',
              'requestStatus' => {
                'id'    => "#{req1_id}/status",
                'type'  => 'request-status',
                'href'  => "https://api.profitbricks.com/rest/v2/requests/#{req1_id}/status"
              }
            },
            'properties' => {
              'method'  => 'POST',
              'headers' => {
                'content-type'        => 'application/x-www-form-urlencoded',
                'connection'          => 'Keep-Alive',
                'host'                => 'api.profitbricks.com',
                'x-forwarded-for'     => '100.00.00.01',
                'content-length'      => '47',
                'x-forwarded-host'    => 'api.profitbricks.com',
                'x-reseller'          => 'pb.domain',
                'user-agent'          => 'fog-core/1.42.0',
                'x-forwarded-server'  => 'my.profitbricks.com'
              },
              'body' => '{\'snapshotId\': \'3d52b13d-bec4-49de-ad05-fd2f8c687be6\'}',
              'url' => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/#{vol1_id}/restore-snapshot"
            }
          },
          {
            'id'        => req2_id,
            'type'      => 'request',
            'href'      => "https=>//api.profitbricks.com/rest/v2/requests/#{req2_id}",
            'metadata'  => {
              'createdDate'   => '2016-08-07T23:32:17Z',
              'createdBy'     => 'test@stackpointcloud.com',
              'etag'          => '37a6259cc0c1dae299a7866489dff0bd',
              'requestStatus' => {
                'id'    => "#{req2_id}/status",
                'type'  => 'request-status',
                'href'  => "https://api.profitbricks.com/rest/v2/requests/#{req2_id}/status"
              }
            },
            'properties' => {
              'method'  => 'POST',
              'headers' => {
                'content-type'        => 'application/x-www-form-urlencoded',
                'connection'          => 'Keep-Alive',
                'host'                => 'api.profitbricks.com',
                'x-forwarded-for'     => '100.00.00.01',
                'content-length'      => '47',
                'x-forwarded-host'    => 'api.profitbricks.com',
                'x-reseller'          => 'pb.domain',
                'user-agent'          => 'fog-core/1.42.0',
                'x-forwarded-server'  => 'my.profitbricks.com'
              },
              'body' => '{\'snapshotId\': \'3d52b13d-bec4-49de-ad05-fd2f8c687be6\'}',
              'url' => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/volumes/#{vol2_id}/restore-snapshot"
            }
          }
        ]
      },
      :request_status => {
        'id' => "#{req1_id}/status",
        'type' => 'request-status',
        'href' => "https=>//api.profitbricks.com/rest/v2/requests/#{req1_id}/status",
        'metadata' => {
          'status' => 'DONE',
          'message' => 'Request has been successfully executed',
          'etag' => '2ba22e58ca17bb728d522bba36cf8350',
          'targets' =>
          [
            {
              'target' => {
                'id' => '752df03a-b9a6-48ee-b9f5-58433184aa1a',
                'type' => 'volume',
                'href' => 'TO_BE_INJECTED'
              },
              'status' => 'DONE'
            }
          ]
        }
      },
      :ip_blocks => {
        'id' => 'ipblocks',
        'type' => 'collection',
        'href' => 'https://api.profitbricks.com/rest/v2/ipblocks',
        'items' =>
        [
          {
            'id' => ipb1_id,
            'type' => 'ipblock',
            'href' => "https://api.profitbricks.com/rest/v2/ipblocks/#{ipb1_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8702',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'ips'       => ["111.111.111.111", "222.222.222.222"],
              'location'  => 'us/las',
              'size'        => 2,
              'name' => 'Fog test IP Block 1'
            }
          },
          {
            'id' => ipb2_id,
            'type' => 'ipblock',
            'href' => "https://api.profitbricks.com/rest/v2/ipblocks/#{ipb2_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8702',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'ips'       => ["333.333.333.333"],
              'location'  => 'us/las',
              'size'        => 1,
              'name' => 'Fog test IP Block 2'
            }
          }
        ]
      },
      :firewall_rules => {
        'id'    => "#{nic1_id}/firewallrules",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}/firewallrules",
        'items' =>
        [
          {
            'id'    => fwr1_id,
            'type'  => 'firewall-rule',
            'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}/firewallrules/#{fwr1_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8703',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'            => 'Fog test Firewall Rule 1',
              'protocol'        => 'TCP',
              'sourceMac'       => 'null',
              'sourceIp'        => 'null',
              'targetIp'        => 'null',
              'icmpCode'        => 'null',
              'icmpType'        => 'null',
              'portRangeStart'  => 22,
              'portRangeEnd'    => 22
            },
            'datacenter_id' => dc1_id,
            'server_id'       => serv1_id,
            'nic_id'          => nic1_id
          },
          {
            'id'    => fwr2_id,
            'type'  => 'firewall-rule',
            'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}/firewallrules/#{fwr2_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8701',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'            => 'Fog test Firewall Rule 2',
              'protocol'        => 'TCP',
              'sourceMac'       => 'null',
              'sourceIp'        => 'null',
              'targetIp'        => 'null',
              'icmpCode'        => 'null',
              'icmpType'        => 'null',
              'portRangeStart'  => 24,
              'portRangeEnd'    => 25
            },
            'datacenter_id' => dc1_id,
            'server_id'       => serv1_id,
            'nic_id'          => nic1_id
          }
        ]
      },
      :load_balancers => {
        'id'    => "#{dc1_id}/loadbalancers",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/loadbalancers",
        'items' =>
        [
          {
            'id'    => lb1_id,
            'type'  => 'loadbalancer',
            'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/loadbalancers/#{lb1_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8723',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'  => 'Fog test Load Balancer 1',
              'ip'    => 'null',
              'dhcp'  => 'true'
            },
            'entities' => {
              'balancednics' => {
                'id'    => "#{lb1_id}/balancednics",
                'type'  => 'collection',
                'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/loadbalancers/#{lb1_id}/balancednics",
                'items' =>
                [
                  {
                    'id'          => nic1_id,
                    'type'        => 'nic',
                    'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}",
                    'metadata'    => {
                      'createdDate'       => '2015-03-18T19:00:51Z',
                      'createdBy'         => 'test@stackpointcloud.com',
                      'etag'              => 'faa67fbacb1c0e2e02cf9650657251f1',
                      'lastModifiedDate'  => '2015-03-18T19:00:51Z',
                      'lastModifiedBy'    => 'test@stackpointcloud.com',
                      'state'             => 'AVAILABLE'
                    },
                    'properties' => {
                      'name'            => 'FogTestLoadBalancedNIC_1',
                      'mac'             => '02:01:36:5f:09:da',
                      'ips'             => ['10.9.194.12'],
                      'dhcp'            => 'true',
                      'lan'             => 2,
                      'firewallActive'  => 'false'
                    },
                    'entities' => {
                      'firewallrules' => {
                        'id'    => "#{nic1_id}/firewallrules",
                        'type'  => 'collection',
                        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/servers/#{serv1_id}/nics/#{nic1_id}/firewallrules",
                        'items' => []
                      }
                    },
                    'datacenter_id' => dc1_id,
                    'load_balancer_id' => lb1_id
                  }
                ]
              }
            },
            'datacenter_id' => dc1_id
          },
          {
            'id'    => lb2_id,
            'type'  => 'loadbalancer',
            'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/loadbalancers/#{lb2_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8721',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'INACTIVE'
            },
            'properties' => {
              'name'  => 'Fog test Load Balancer 2',
              'ip'    => 'null',
              'dhcp'  => 'false'
            },
            'entities' => {
              'balancednics' => {
                'id' => "#{lb2_id}/balancednics",
                'type'  => 'collection',
                'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{dc1_id}/loadbalancers/#{lb2_id}/balancednics",
                'items' => []
              }
            },
            'datacenter_id' => dc1_id
          }
        ]
      },
      :contracts => {
        'type' => 'contract',
        'contractNumber'  => '12345678',
        'owner'  => 'test@domain.com',
        'status'  => 'BILLABLE',
        'resourceLimits' => {
          'coresPerServer'        => '20',
          'coresPerContract'      => '30',
          'coresProvisioned'      => '0',
          'ramPerServer'          => '204800',
          'ramPerContract'        => '3072000',
          'ramProvisioned'        => '0',
          'hddLimitPerVolume'     => '2048000',
          'hddLimitPerContract'   => '3072000',
          'hddVolumeProvisioned'  => '0',
          'ssdLimitPerVolume'     => '2048000',
          'ssdLimitPerContract'   => '3072000',
          'ssdVolumeProvisioned'  => '0',
          'reservableIps'         => '3',
          'reservedIpsOnContract' => '0',
          'reservedIpsInUse'      => '0',
        }
      },
      :groups => {
        'id'    => "groups",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/cloudapi/v4/um/groups",
        'items' => []
      },
      :shares => {
        'id'    => "059c4d71-f97a-4bfd-b3a5-XXXXXXXXXXXX/shares",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/cloudapi/v4/um/groups/059c4d71-f97a-4bfd-b3a5-XXXXXXXXXXXX/shares",
        'items' => []
      },
      :users => {
        'id'    => "users",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/cloudapi/v4/users",
        'items' => []
      },
      :resources => {
        'id'    => "resources",
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/cloudapi/v4/um/resources",
        'items' => [
          {
            'id'        => dc1_id,
            'type'      => 'datacenter',
            'href'      => "https://api.profitbricks.com/cloudapi/v4/um/resources/datacenter/#{dc1_id}",
            'metadata'  => {
              'createdDate' => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8702',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'entities' => {
              'groups' => {
                'id' => "#{dc1_id}/groups",
                'type' => 'collection',
                'href' => "https://api.profitbricks.com/cloudapi/v4/um/groups",
                'items' => []
              }
            }
          },
          {
            'id'              => 'dfcb40db-28b5-11e6-9336-52540005ab80',
            'type'            => 'image',
            'href'            => 'https://api.profitbricks.com/cloudapi/v4/um/resources/image/dfcb40db-28b5-11e6-9336-52540005ab80',
            'metadata'        => {
              'createdDate'       => '2016-06-02T11:33:49Z',
              'createdBy'         => 'System',
              'etag'              => '9909709d99655c6f31aca789998d7d89',
              'lastModifiedDate'  => '2016-06-02T11:33:49Z',
              'lastModifiedBy'    => 'System',
              'state'             => 'AVAILABLE'
            },
            'entities' => {
              'groups' => {
                'id' => "dfcb40db-28b5-11e6-9336-52540005ab80/groups",
                'type' => 'collection',
                'href' => "https://api.profitbricks.com/cloudapi/v4/um/groups",
                'items' => []
              }
            }
          },
          {
            'id'          => '3d52b13d-bec4-49de-ad05-fd2f8c687be6',
            'type'        => 'snapshot',
            'href'        => 'https://api.profitbricks.com/cloudapi/v4/um/resources/snapshot/3d52b13d-bec4-49de-ad05-fd2f8c687be6',
            'metadata'    => {
              'createdDate'       => '2016-08-07T22:28:38Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '83ad78a4757ab0d9bdeaebc3a6485dcf',
              'lastModifiedDate'  => '2016-08-07T22:28:38Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'entities' => {
              'groups' => {
                'id' => "3d52b13d-bec4-49de-ad05-fd2f8c687be6/groups",
                'type' => 'collection',
                'href' => "https://api.profitbricks.com/cloudapi/v4/um/groups",
                'items' => []
              }
            }
          },
          {
            'id' => ipb1_id,
            'type' => 'ipblock',
            'href' => "https://api.profitbricks.com/cloudapi/v4/um/resources/ipblock/#{ipb1_id}",
            'metadata' => {
              'createdDate'       => '2016-07-31T15:41:27Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => '5b91832ee85a758568d4523a86bd8702',
              'lastModifiedDate'  => '2016-07-31T15:41:27Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'entities' => {
              'groups' => {
                'id' => "#{ipb1_id}/groups",
                'type' => 'collection',
                'href' => "https://api.profitbricks.com/cloudapi/v4/um/groups",
                'items' => []
              }
            }
          }
        ]
      }
    }
  end
end
new(options = {}) click to toggle source
# File lib/fog/profitbricks/compute.rb, line 1270
def initialize(options = {})
  @profitbricks_username = options[:profitbricks_username]
  @profitbricks_password = options[:profitbricks_password]
end
reset() click to toggle source
# File lib/fog/profitbricks/compute.rb, line 1266
def self.reset
  @data = nil
end

Public Instance Methods

add_share(group_id, resource_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/add_share.rb, line 42
def add_share(group_id, resource_id, options = {})
  response = Excon::Response.new
  response.status = 202

  share = {
    'id' => resource_id,
    'type'      => 'resource',
    'href'      => "https=>//api.profitbricks.com/rest/v4/um/groups/#{group_id}/shares/#{resource_id}",
    'properties' => {
        'editPrivilege'  => options[:editPrivilege],
        'sharePrivilege' => options[:sharePrivilege]
    }
  }

  data[:shares]['items'] << share

  response.body = share
  response
end
add_user_to_group(group_id, user_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/add_user_to_group.rb, line 62
def add_user_to_group(group_id, user_id)
  response = Excon::Response.new
  response.status = 202

  if group = data[:groups]['items'].find do |grp|
    grp["id"] == group_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  if user = data[:users]['items'].find do |usr|
    usr["id"] == user_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  group['users']['items'] << user
  user['groups']['items'] << group

  response.body = user
  response
end
associate_nic_to_load_balancer(datacenter_id, load_balancer_id, nic_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/associate_nic_to_load_balancer.rb, line 84
def associate_nic_to_load_balancer(datacenter_id, load_balancer_id, nic_id)
  if load_balancer = data[:load_balancers]['items'].find do |lb|
    lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
  end
  else
    raise Fog::Errors::NotFound, "The requested resource could not be found"
  end

  unless load_balancer['entities'] && load_balancer['entities']['balancednics'] && load_balancer['entities']['balancednics']['items']
    nic = data[:nics]['items'].find do |nic|
      nic["datacenter_id"] == datacenter_id && nic["id"] == nic_id
    end

    load_balancer['entities'] = {
      'balancednics' => {
        'id'    => "#{load_balancer_id}/balancednics",
        'type'  => "collection",
        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}/balancednics",
        'items' => [nic]
      }
    }
  end

  response        = Excon::Response.new
  response.status = 202
  response.body   = nic
  response
end
attach_cdrom(datacenter_id, server_id, cdrom_image_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/attach_cdrom.rb, line 60
def attach_cdrom(datacenter_id, server_id, cdrom_image_id)
  if cdrom = data[:images]['items'].find do |cd|
    cd["id"] == cdrom_image_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  cdrom['properties'] = {}
  cdrom['properties']['name'] = cdrom['name']

  if server['cdroms'] && server['cdroms']['items']
    server['cdroms']['items'] << cdrom
  else
    server['cdroms'] = {
      'id' => "#{server['id']}/cdroms",
      'type' => 'collection',
      'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{server['datacenter_id']}/servers/#{server['id']}/cdroms",
      'items' => [cdrom]
    }
  end

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

  response
end
attach_volume(datacenter_id, server_id, storage_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/attach_volume.rb, line 61
def attach_volume(datacenter_id, server_id, storage_id)
  if volume = data[:volumes]['items'].find do |vlm|
    vlm["id"] == storage_id && vlm["datacenter_id"] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  volume['properties'] = {}
  volume['properties']['name'] = volume['name']
  volume['properties']['size'] = volume['size']
  volume['properties']['bus'] = volume['bus']
  volume['properties']['type'] = volume['type']
  volume['properties']['licenceType'] = 'LINUX'

  if server['entities'] && server['entities']['volumes'] && server['entities']['volumes']['items']
    server['entities']['volumes']['items'] << volume
  else
    server['entities'] = {
      'volumes' => {
        'id'    => "#{server_id}/volumes",
        'type'  => 'collection',
        'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
        'items' => [volume]
      }
    }
  end

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

  response
end
create_datacenter(options, entities={}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_datacenter.rb, line 59
def create_datacenter(options, entities={})
  dc = {
    :properties => options,
    :entities => entities
  }

  if dc[:properties][:location] == nil
    raise Excon::Error::HTTPStatus, "Attribute 'location' is required"
  end

  dc_3_id = Fog::UUID.uuid
  dc_4_id = Fog::UUID.uuid
  datacenter = {
    'id' => dc_3_id,
    'type' => 'datacenter',
    'properties' => {
      'name' => dc[:properties][:name],
      'description' => dc[:properties][:description],
      'location' => dc[:properties][:location],
      'version' => 1
    }
  }

  if entities != nil and entities != {}
    datacenter = {
      'id' => dc_4_id,
      'type' => 'datacenter',
      'properties' => {
        'name' => dc[:properties][:name],
        'description' => dc[:properties][:description],
        'location' => dc[:properties][:location],
        'version' => 1
      },
      'entities' => {
        'volumes' => {
          'items' =>
            [
              {
                'type' => 'volume',
                'properties' => {
                  'name' => dc[:entities][:volumes][:items][0][:properties][:name],
                  'type' => dc[:entities][:volumes][:items][0][:properties][:type],
                  'size' => dc[:entities][:volumes][:items][0][:properties][:size],
                  'bus' => dc[:entities][:volumes][:items][0][:properties][:bus],
                  'licenceType' => dc[:entities][:volumes][:items][0][:properties][:licenceType],
                  'availabilityZone' => dc[:entities][:volumes][:items][0][:properties][:availabilityZone]
                }
              }
            ]
        },
        'servers' => {
          'items' =>
            [
              {
                'properties' => {
                  'name' => dc[:entities][:servers][:items][0][:properties][:name],
                  'cores' => dc[:entities][:servers][:items][0][:properties][:cores],
                  'ram' => dc[:entities][:servers][:items][0][:properties][:ram]
                }
              }
            ]
        }
      }
    }
  end

  data[:datacenters]['items'] << datacenter
  response = Excon::Response.new
  response.status = 202
  response.body = datacenter
  response
end
create_firewall_rule(datacenter_id, server_id, nic_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_firewall_rule.rb, line 70
def create_firewall_rule(datacenter_id, server_id, nic_id, options = {})
  response = Excon::Response.new
  response.status = 202

  properties = {}
  properties['name'] = options[:name]
  properties['protocol'] = options[:protocol]
  properties['source_mac'] = options[:sourceMac]
  properties['port_range_start'] = options[:portRangeStart]
  properties['port_range_end'] = options[:portRangeEnd]

  firewall_rule_id = Fog::UUID.uuid
  firewall_rule = {
    'id' => firewall_rule_id,
    'type'        => 'firewall-rule',
    'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules/#{firewall_rule_id}",
    'metadata'    => {
      'createdDate' => '2015-03-18T19:00:51Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => 'faa67fbacb1c0e2e02cf9650657251f2',
      'lastModifiedDate'  => '2015-03-18T19:00:51Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties' => properties,
    'datacenter_id' => datacenter_id,
    'server_id'     => server_id,
    'nic_id'        => nic_id
  }

  data[:firewall_rules]['items'] << firewall_rule
  response.body = firewall_rule

  response
end
create_flavor(flavor_name, ram, cores) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_flavor.rb, line 22
def create_flavor(flavor_name, ram, cores)
  response = Excon::Response.new
  response.status = 200

  flavor = {
    'id'    => Fog::UUID.uuid,
    'name'  => flavor_name,
    'ram'   => ram,
    'cores' => cores
  }

  data[:flavors] << flavor
  response.body = { 'createFlavorResponse' => flavor }
  response
end
create_group(options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_group.rb, line 58
def create_group(options = {})
  if options[:name] == nil
    raise Excon::Error::HTTPStatus, "Attribute 'name' is required"
  end

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

  group_id = Fog::UUID.uuid

  group = {
    'id' => group_id,
    'type'      => 'group',
    'href'      => "https=>//api.profitbricks.com/rest/v4/um/groups/#{group_id}",
    'properties' => {
        'name'              => options[:name],
        'createDataCenter'  => options[:createDataCenter],
        'createSnapshot'    => options[:createSnapshot],
        'reserveIp'         => options[:reserveIp],
        'accessActivityLog' => options[:accessActivityLog]
    },
    'entities' => {
      'users' => {
        'id' => "#{group_id}/owns",
        'type' => 'collection',
        'href' => "https://api.profitbricks.com/cloudapi/v4/um/groups/#{group_id}/users",
        'items' => []
      },
      'resources' => {
        'id' => "#{group_id}/resources",
        'type' => 'collection',
        'href' => "https://api.profitbricks.com/cloudapi/v4/um/groups/#{group_id}/resources",
        'items' => []
      }
    }
  }

  data[:groups]['items'] << group

  response.body = group
  response
end
create_ip_block(options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_ip_block.rb, line 48
def create_ip_block(options = {})
  ipb_3_id = Fog::UUID.uuid
  ip_block = {
    'id' => ipb_3_id,
    'type' => 'ipblock',
    'href' => "https://api.profitbricks.com/rest/v2/ipblocks/#{ipb_3_id}",
    'metadata' => {
      'createdDate' => '2016-07-31T15:41:27Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => '5b91832ee85a758568d4523a86bd8702',
      'lastModifiedDate'  => '2016-07-31T15:41:27Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties' => {
      'ips' => ["777.777.777.777", "888.888.888.888"],
      'location' => options[:location],
      'size'        => options[:size],
      'name' => options[:name]
    }
  }

  data[:ip_blocks]['items'] << ip_block
  response        = Excon::Response.new
  response.status = 202
  response.body   = ip_block
  response
end
create_lan(datacenter_id, properties = {}, _entities = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_lan.rb, line 112
def create_lan(datacenter_id, properties = {}, _entities = {})
  response = Excon::Response.new
  response.status = 202

  if datacenter = data[:datacenters]['items'].find do |attrib|
    attrib['id'] == datacenter_id
  end

    datacenter['properties']['version'] += 1 if datacenter['properties']
    datacenter['version'] += 1 if datacenter['version']

  else
    raise Fog::Errors::NotFound, 'Data center resource could not be found'
  end

  lan = {
    'id' => '10',
    'type'        => 'lan',
    'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/lans/10",
    'metadata'    => {
      'createdDate' => '2015-03-18T19:00:51Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => 'faa67fbacb1c0e2e02cf9650657251f1',
      'lastModifiedDate'  => '2015-03-18T19:00:51Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties' => {
      'name' => properties[:name],
      'public' => properties[:public]
    },
    'entities' => {
      'nics' => {
        'id' => '10/nics',
        'type'  => 'collection',
        'href'  => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/lans/10/nics",
        'items' => []
      }
    },
    'datacenter_id' => datacenter_id
  }

  data[:lans]['items'] << lan

  response.body = lan
  response
end
create_load_balancer(datacenter_id, properties = {}, entities = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_load_balancer.rb, line 55
def create_load_balancer(datacenter_id, properties = {}, entities = {})
  response = Excon::Response.new
  response.status = 202

  load_balancer_id  = Fog::UUID.uuid
  nic_1_id          = Fog::UUID.uuid
  serv_1_id         = Fog::UUID.uuid
  properties[:ip] = '123.456.789'

  load_balancer = {
    'id' => load_balancer_id,
    'type'        => 'loadbalancer',
    'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/loadbalancers/#{load_balancer_id}",
    'metadata'    => {
      'createdDate' => '2015-03-18T19:00:51Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => 'faa67fbacb1c0e2e02cf9650657251f2',
      'lastModifiedDate'  => '2015-03-18T19:00:51Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties'      => properties,
    'entities'        => entities,
    'datacenter_id' => datacenter_id
  }

  data[:load_balancers]['items'] << load_balancer
  response.body = load_balancer

  response
end
create_nic(datacenter_id, server_id, options = {}, entities = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_nic.rb, line 91
def create_nic(datacenter_id, server_id, options = {}, entities = {})
  if options[:lan] == nil
    raise Excon::Error::HTTPStatus, "Attribute 'lan' is required"
  end

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

  nic_id = Fog::UUID.uuid
  nic = {
    'id' => nic_id,
    'type'        => 'nic',
    'href'        => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}",
    'metadata'    => {
      'createdDate' => '2015-03-18T19:00:51Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => 'faa67fbacb1c0e2e02cf9650657251f2',
      'lastModifiedDate'  => '2015-03-18T19:00:51Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties'      => options,
    'entities'        => entities,
    'datacenter_id' => datacenter_id,
    'server_id' => server_id
  }

  data[:nics]['items'] << nic
  response.body = nic

  response
end
create_server(datacenter_id, properties = {}, entities = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_server.rb, line 135
def create_server(datacenter_id, properties = {}, entities = {})
  if properties[:cores] == nil
    raise Excon::Error::HTTPStatus, "Attribute 'cores' is required"
  end

  server_id = Fog::UUID.uuid

  volume_id = if entities[:volumes] && entities[:volumes]['items'] && entities[:volumes]['items'][0] && entities[:volumes]['items'][0]['id']
                entities[:volumes]['items'][0]['id']
              else
                Fog::UUID.uuid
              end

  server = {
    'id'    => server_id,
    'type'  => 'server',
    'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}",
    'datacenter_id' => datacenter_id,
    'metadata' => {
      'createdDate'       => '2014-10-20T21:20:46Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => '0018832d7a7ba455db74ac41ae9f11fe',
      'lastModifiedDate'  => '2015-03-18T21:31:10Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties' => {
      'name'              => properties[:name],
      'cores'             => properties[:cores],
      'ram'               => properties[:ram],
      'availabilityZone'  => properties[:availabilityZone],
      'vmState'           => 'RUNNING',
      'cpuFamily' => properties[:cpuFamily],
      'bootVolume' => properties[:bootVolume]
    }
  }

  if entities[:volumes]
    server['entities'] = {
      'volumes' => {
        'id'    => "#{server_id}/volumes",
        'type'  => 'collection',
        'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
        'items' =>
        [
          {
            'id'          => volume_id,
            'type'        => 'volume',
            'href'        => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/volumes/#{volume_id}",
            'metadata'    => {
              'createdDate'       => '2015-03-18T19=>00=>51Z',
              'createdBy'         => 'test@stackpointcloud.com',
              'etag'              => 'c4a2fde6ba91a038ff953b939cc21efe',
              'lastModifiedDate'  => '2015-03-18T19=>00=>51Z',
              'lastModifiedBy'    => 'test@stackpointcloud.com',
              'state'             => 'AVAILABLE'
            },
            'properties' => {
              'name'                => 'FogRestTestVolume',
              'type'                => 'HDD',
              'size'                => 5,
              'image'               => '4f363db0-4955-11e4-b362-52540066fee9',
              'bus'                 => 'VIRTIO',
              'licenceType'         => 'OTHER',
              'cpuHotPlug'          => 'true',
              'cpuHotUnplug'        => 'false',
              'ramHotPlug'          => 'false',
              'ramHotUnplug'        => 'false',
              'nicHotPlug'          => 'true',
              'nicHotUnplug'        => 'true',
              'discVirtioHotPlug'   => 'true',
              'discVirtioHotUnplug' => 'true',
              'discScsiHotPlug'     => 'false',
              'discScsiHotUnplug'   => 'false',
              'deviceNumber'        => 1
            }
          }
        ]
      }
    }
  end

  if entities[:cdroms]
    server['entities']['cdroms'] = {
      'id'    => "#{server_id}/cdroms",
      'type'  => 'collection',
      'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
      'items' =>
      [
        {
          'id'        => 'dfcb40db-28b5-11e6-9336-52540005ab80',
          'type'      => 'image',
          'href'      => 'https=>//api.profitbricks.com/rest/v2/images/dfcb40db-28b5-11e6-9336-52540005ab80',
          'metadata'  => {
            'createdDate'       => '2016-06-02T11:33:49Z',
            'createdBy'         => 'System',
            'etag'              => '9909709d99655c6f31aca789998d7d89',
            'lastModifiedDate'  => '2016-06-02T11:33:49Z',
            'lastModifiedBy'    => 'System',
            'state'             => 'AVAILABLE'
          },
          'properties' => {
            'name'                => 'CentOS-6.8-x86_64-netinstall.iso',
            'description'         => '',
            'location'            => 'us/las',
            'size'                => 0.23,
            'cpuHotPlug'          => 'true',
            'cpuHotUnplug'        => 'false',
            'ramHotPlug'          => 'true',
            'ramHotUnplug'        => 'false',
            'nicHotPlug'          => 'true',
            'nicHotUnplug'        => 'true',
            'discVirtioHotPlug'   => 'true',
            'discVirtioHotUnplug' => 'true',
            'discScsiHotPlug'     => 'false',
            'discScsiHotUnplug'   => 'false',
            'licenceType'         => 'LINUX',
            'imageType'           => 'CDROM',
            'public'              => 'true'
          }
        }
      ]
    }
  end

  data[:servers]['items'] << server

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

  response
end
create_user(options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_user.rb, line 50
def create_user(options = {})
  if options[:email] == nil
    raise Excon::Error::HTTPStatus, "Attribute 'email' is required"
  end

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

  user_id = Fog::UUID.uuid

  user = {
    'id' => user_id,
    'type'      => 'user',
    'href'      => "https=>//api.profitbricks.com/rest/v4/um/users/#{user_id}",
    'metadata' => {
        'etag'         => '26a6259cc0c1dae299a5687455dff0ce',
        'creationDate' => '2017-05-22T08:15:55Z',
        'lastLogin'    => '',
    },
    'properties' => {
        'firstname'     => options[:firstname],
        'lastname'      => options[:lastname],
        'email'         => options[:email],
        'password'      => options[:password],
        'administrator' => options[:administrator],
        'forceSecAuth'  => options[:force_sec_auth] || false,
        'secAuthActive'  => options[:sec_auth_active] || false
    },
    'entities' => {
      'owns' => {
        'id' => "#{user_id}/owns",
        'type' => 'collection',
        'href' => "https://api.profitbricks.com/cloudapi/v4/um/users/#{user_id}/owns",
        'items' => []
      },
      'groups' => {
        'id' => "#{user_id}/groups",
        'type' => 'collection',
        'href' => "https://api.profitbricks.com/cloudapi/v4/um/users/#{user_id}/groups",
        'items' => []
      }
    }
  }

  data[:users]['items'] << user

  response.body = user
  response
end
create_volume(datacenter_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_volume.rb, line 76
def create_volume(datacenter_id, options = {})
  response = Excon::Response.new
  response.status = 202

  if options[:size] == nil
    raise Excon::Error::HTTPStatus, "Attribute 'size' is required"
  end

  if datacenter = data[:datacenters]['items'].find do |attrib|
    attrib['id'] == datacenter_id
  end

    datacenter['version'] += 1 if datacenter['version']
  else
    raise Excon::Error::HTTPStatus, 'Resource does not exist'
  end

  volume_id = Fog::UUID.uuid

  volume = {
    'id' => volume_id,
    'type'      => 'volume',
    'href'      => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter['id']}/volumes/#{volume_id}",
    'metadata'  => {
      'createdDate' => '2015-03-18T19=>00=>51Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => 'c4a2fde6ba91a038ff953b939cc21efe',
      'lastModifiedDate'  => '2015-03-18T19=>00=>51Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties' => {
      'name' => options[:name],
      'type'                => options[:type],
      'size'                => options[:size],
      'image'               => options[:image],
      'availabilityZone'    => options[:availabilityZone],
      'bus'                 => 'VIRTIO',
      'licenceType'         => 'OTHER',
      'cpuHotPlug'          => 'true',
      'cpuHotUnplug'        => 'false',
      'ramHotPlug'          => 'false',
      'ramHotUnplug'        => 'false',
      'nicHotPlug'          => 'true',
      'nicHotUnplug'        => 'true',
      'discVirtioHotPlug'   => 'true',
      'discVirtioHotUnplug' => 'true',
      'discScsiHotPlug'     => 'false',
      'discScsiHotUnplug'   => 'false',
      'deviceNumber'        => 1
    },
    'datacenter_id' => datacenter['id']
  }

  data[:volumes]['items'] << volume

  response.body = volume
  response
end
create_volume_snapshot(datacenter_id, _volume_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/create_volume_snapshot.rb, line 59
def create_volume_snapshot(datacenter_id, _volume_id, options = {})
  response = Excon::Response.new
  response.status = 202

  if datacenter = data[:datacenters]['items'].find do |attrib|
    attrib['id'] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, 'Data center resource could not be found'
  end

  snapshot_id = Fog::UUID.uuid
  snapshot = {
    'id' => snapshot_id,
    'type'        => 'snapshot',
    'href'        => "https =>//api.profitbricks.com/rest/v2/snapshots/#{snapshot_id}",
    'metadata'    => {
      'createdDate' => '2016-08-07T22:28:39Z',
      'createdBy'         => 'test@stackpointcloud.com',
      'etag'              => '83ad78a4757ab0d9bdeaebc3a6485dcf',
      'lastModifiedDate'  => '2016-08-07T22:28:39Z',
      'lastModifiedBy'    => 'test@stackpointcloud.com',
      'state'             => 'AVAILABLE'
    },
    'properties' => {
      'name' => options[:name],
      'description'         => options[:description],
      'location'            => 'us/las',
      'size'                => 5,
      'cpuHotPlug'          => 'true',
      'cpuHotUnplug'        => 'false',
      'ramHotPlug'          => 'false',
      'ramHotUnplug'        => 'false',
      'nicHotPlug'          => 'true',
      'nicHotUnplug'        => 'true',
      'discVirtioHotPlug'   => 'true',
      'discVirtioHotUnplug' => 'true',
      'discScsiHotPlug'     => 'false',
      'discScsiHotUnplug'   => 'false',
      'licenceType'         => 'OTHER'
    }
  }

  data[:snapshots]['items'] << snapshot

  response.body = snapshot
  response
end
data() click to toggle source
# File lib/fog/profitbricks/compute.rb, line 1275
def data
  self.class.data[@profitbricks_username]
end
delete_datacenter(datacenter_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_datacenter.rb, line 25
def delete_datacenter(datacenter_id)
  response = Excon::Response.new
  response.status = 202

  if dc = data[:datacenters]["items"].find do |datacenter|
    datacenter["id"] == datacenter_id
  end
  else
      raise Excon::Error::HTTPStatus, "The requested resource could not be found"
  end

  response
end
delete_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_firewall_rule.rb, line 28
def delete_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id)
  response = Excon::Response.new
  response.status = 202

  if firewall_rule = data[:firewall_rules]["items"].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["server_id"] == server_id && attribute["nic_id"] == nic_id && attribute["id"] == firewall_rule_id
  end
  else
    raise Fog::Errors::NotFound, "The requested firewall rule resource could not be found"
  end

  response
end
delete_group(group_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_group.rb, line 27
def delete_group(group_id)
  response = Excon::Response.new
  response.status = 202

  if group = data[:groups]['items'].find do |grp|
    grp['id'] == group_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response
end
delete_image(image_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_image.rb, line 25
def delete_image(image_id)
  response = Excon::Response.new
  response.status = 202

  if img = data[:images]["items"].find do |image|
    image["id"] == image_id
  end
  else
    raise Fog::Errors::NotFound, "The requested resource could not be found"
  end

  response
end
delete_ip_block(ip_block_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_ip_block.rb, line 25
def delete_ip_block(ip_block_id)
  response = Excon::Response.new
  response.status = 202

  if ip_block = data[:ip_blocks]["items"].find do |attribute|
    attribute["id"] == ip_block_id
  end
  else
    raise Fog::Errors::NotFound, "The requested IP Block could not be found"
  end

  response
end
delete_lan(datacenter_id, lan_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_lan.rb, line 26
def delete_lan(datacenter_id, lan_id)
  response = Excon::Response.new
  response.status = 202

  if lan = data[:lans]["items"].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["id"] == lan_id
  end
  else
    raise Fog::Errors::NotFound, "The requested lan could not be found"
  end

  response
end
delete_load_balancer(datacenter_id, load_balancer_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_load_balancer.rb, line 26
def delete_load_balancer(datacenter_id, load_balancer_id)
  response = Excon::Response.new
  response.status = 202

  if lb = data[:load_balancers]["items"].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["id"] == load_balancer_id
  end
  else
    raise Fog::Errors::NotFound, "The requested resource could not be found"
  end

  response
end
delete_nic(datacenter_id, server_id, nic_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_nic.rb, line 27
def delete_nic(datacenter_id, server_id, nic_id)
  response = Excon::Response.new
  response.status = 202

  if nic = data[:nics]["items"].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["server_id"] == server_id && attribute["id"] == nic_id
  end
  else
    raise Fog::Errors::NotFound, "The requested nic resource could not be found"
  end

  response
end
delete_server(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_server.rb, line 28
def delete_server(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |attrib|
    attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
  end
    data[:servers].delete(server)
  else
    raise Fog::Errors::NotFound, 'The requested server resource could not be found'
  end

  response        = Excon::Response.new
  response.status = 202
  response
end
delete_share(group_id, resource_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_share.rb, line 26
def delete_share(group_id, resource_id)
  response = Excon::Response.new
  response.status = 202

  if share = data[:shares]['items'].find do |shr|
    shr['id'] == resource_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response
end
delete_snapshot(snapshot_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_snapshot.rb, line 24
def delete_snapshot(snapshot_id)
  response = Excon::Response.new
  response.status = 202

  if snapshot = data[:snapshots]['items'].find do |attrib|
    attrib['id'] == snapshot_id
  end
  else
    raise Fog::Errors::NotFound, 'The requested resource could not be found'
  end

  response
end
delete_user(user_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_user.rb, line 27
def delete_user(user_id)
  response = Excon::Response.new
  response.status = 202

  if user = data[:users]['items'].find do |usr|
    usr['id'] == user_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response
end
delete_volume(datacenter_id, volume_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/delete_volume.rb, line 26
def delete_volume(datacenter_id, volume_id)
  response = Excon::Response.new
  response.status = 202

  if vlm = data[:volumes]["items"].find do |volume|
    volume["id"] == volume_id && volume["datacenter_id"] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, "The requested resource could not be found"
  end

  response
end
detach_cdrom(datacenter_id, server_id, cdrom_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/detach_cdrom.rb, line 27
def detach_cdrom(datacenter_id, server_id, cdrom_id)
  response = Excon::Response.new
  response.status = 202

  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  if cdrom = server['cdroms']['items'].find do |cd|
    cd['id'] == cdrom_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response
end
detach_volume(datacenter_id, server_id, volume_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/detach_volume.rb, line 28
def detach_volume(datacenter_id, server_id, volume_id)
  response = Excon::Response.new
  response.status = 202

  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Fog::Errors::NotFound, "The server resource could not be found"
  end

  if server['entities']
    volume = server['entities']['volumes']['items'].find do |vlm|
      vlm['id'] == volume_id
    end
  elsif server['volumes']
    volume = server['volumes']['items'].find do |vlm|
      vlm['id'] == volume_id
    end
  else
    raise Fog::Errors::NotFound, "The attached volume resource could not be found"
  end

  response
end
get_all_contract_resources() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_contract_resources.rb, line 46
def get_all_contract_resources
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:contracts]
  response
end
get_all_datacenters() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_datacenters.rb, line 50
def get_all_datacenters
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:datacenters]
  response
end
get_all_firewall_rules(datacenter_id, server_id, nic_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_firewall_rules.rb, line 55
def get_all_firewall_rules(datacenter_id, server_id, nic_id)
  firewall_rules = data[:firewall_rules]

  if nics = data[:firewall_rules]['items'].select do |attrib|
    attrib['datacenter_id'] == datacenter_id && attrib['server_id'] == server_id && attrib['nic_id'] == nic_id
  end
  else
    raise Fog::Errors::NotFound, 'The resource could not be found'
  end

  firewall_rules['items'] = nics
  response        = Excon::Response.new
  response.status = 200
  response.body   = firewall_rules

  response
end
get_all_flavors() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_flavors.rb, line 65
def get_all_flavors
  data = self.data[:flavors]
  response        = Excon::Response.new
  response.status = 200
  response.body   = {
    'getAllFlavorsResponse' => self.data[:flavors]
  }
  response
end
get_all_groups() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_groups.rb, line 52
def get_all_groups
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:groups]

  response
end
get_all_images() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_images.rb, line 57
def get_all_images
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:images]
  response
end
get_all_ip_blocks() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_ip_blocks.rb, line 44
def get_all_ip_blocks
  ip_blocks = data[:ip_blocks]

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

  response
end
get_all_lans(datacenter_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_lans.rb, line 101
def get_all_lans(datacenter_id)
  lans = data[:lans]

  if lns = data[:lans]['items'].select do |attrib|
    attrib['datacenter_id'] == datacenter_id
  end
  else
    raise Fog::Errors::NotFound, 'The resource could not be found'
  end

  lans['items']   = lns
  response        = Excon::Response.new
  response.status = 200
  response.body   = lans

  response
end
get_all_load_balanced_nics(datacenter_id, load_balancer_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_load_balanced_nics.rb, line 82
def get_all_load_balanced_nics(datacenter_id, load_balancer_id)
  if load_balancer = data[:load_balancers]['items'].find do |lb|
    lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
  end
  else
    raise Fog::Errors::NotFound, "The requested resource could not be found"
  end

  load_balanced_nics = nil

  load_balanced_nics = if load_balancer['entities']
                         load_balancer['entities']['balancednics']
                       else
                         load_balancer['balancednics']
                       end

  response        = Excon::Response.new
  response.status = 200
  response.body   = load_balanced_nics
  response
end
get_all_load_balancers(datacenter_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_load_balancers.rb, line 101
def get_all_load_balancers(datacenter_id)
  if load_balancers = data[:load_balancers]['items'].select do |attrib|
    attrib['datacenter_id'] == datacenter_id
  end
  else
    raise Fog::Errors::NotFound, 'The requested Load Balancer resource could not be found'
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:load_balancers]
  response
end
get_all_locations(_options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_locations.rb, line 35
def get_all_locations(_options = {})
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:locations]
  response
end
get_all_nic(datacenter_id, _server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_nic.rb, line 82
def get_all_nic(datacenter_id, _server_id)
  interfaces = data[:nics]

  if nics = interfaces['items'].select do |attrib|
    attrib['datacenter_id'] == datacenter_id
  end
  else
    raise Fog::Errors::NotFound, 'The resource could not be found'
  end

  interfaces['items'] = nics
  response        = Excon::Response.new
  response.status = 200
  response.body   = interfaces

  response
end
get_all_requests() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_requests.rb, line 32
def get_all_requests
  requests = data[:requests]
  response        = Excon::Response.new
  response.status = 200
  response.body   = requests

  response
end
get_all_resources() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_resources.rb, line 56
def get_all_resources
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:resources]

  response
end
get_all_servers(datacenter_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_servers.rb, line 117
def get_all_servers(datacenter_id)
  if servs = data[:servers]['items'].select do |attrib|
    attrib['datacenter_id'] == datacenter_id
  end
  else
    raise Fog::Errors::NotFound, 'Server resource could not be found'
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:servers]
  response
end
get_all_shares(group_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_shares.rb, line 36
def get_all_shares(group_id)
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:shares]

  response
end
get_all_snapshots() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_snapshots.rb, line 56
def get_all_snapshots
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:snapshots]

  response
end
get_all_users() click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_users.rb, line 60
def get_all_users
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:users]

  response
end
get_all_volumes(datacenter_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_all_volumes.rb, line 58
def get_all_volumes(datacenter_id)
  volumes = data[:volumes]

  if vlms = data[:volumes]['items'].select do |attrib|
    attrib['datacenter_id'] == datacenter_id
  end
  else
    raise Fog::Errors::NotFound, 'Volume resource could not be found'
  end

  volumes['items'] = vlms
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:volumes]

  response
end
get_attached_cdrom(datacenter_id, server_id, cdrom_image_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_attached_cdrom.rb, line 55
def get_attached_cdrom(datacenter_id, server_id, cdrom_image_id)
  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  if cdrom = server['cdroms']['items'].find do |cd|
    cd['id'] == cdrom_image_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = cdrom
  response
end
get_attached_volume(datacenter_id, server_id, volume_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_attached_volume.rb, line 56
def get_attached_volume(datacenter_id, server_id, volume_id)
  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Fog::Errors::NotFound, "The server resource could not be found"
  end

  if server['entities']
    volume = server['entities']['volumes']['items'].find do |vlm|
      vlm['id'] == volume_id
    end
  elsif server['volumes']
    volume = server['volumes']['items'].find do |vlm|
      vlm['id'] == volume_id
    end
  else
    raise Fog::Errors::NotFound, "The attached volume resource could not be found"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = volume
  response
end
get_datacenter(datacenter_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_datacenter.rb, line 47
def get_datacenter(datacenter_id)
  if dc = data[:datacenters]["items"].find do |datacenter|
    datacenter["id"] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = dc
  response
end
get_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_firewall_rule.rb, line 52
def get_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id)
  if firewall_rule = data[:firewall_rules]['items'].find do |fwr|
    fwr["datacenter_id"] == datacenter_id && fwr["server_id"] == server_id && fwr["nic_id"] == nic_id && fwr["id"] == firewall_rule_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = firewall_rule
  response
end
get_flavor(flavor_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_flavor.rb, line 65
def get_flavor(flavor_id)
  response        = Excon::Response.new
  response.status = 200

  if flavor = data[:flavors].find do |attrib|
    attrib["flavorId"] == flavor_id
  end
  else
    raise Fog::Errors::NotFound, "The requested flavor could not be found"
  end

  response.body = { "getFlavorResponse" => flavor }
  response
end
get_group(group_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_group.rb, line 48
def get_group(group_id)
  if group = data[:groups]['items'].find do |grp|
    grp["id"] == group_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = group
  response
end
get_group_users(group_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_group_users.rb, line 60
def get_group_users(group_id)
  if users = data[:groups]['items']['users'].find do |usr|
    usr["groups"]["items"].find do |grp|
      grp["id"] == group_id
    end
  end
  else
    raise Fog::Errors::NotFound, "The requested resource could not be found"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body = users
  response
end
get_image(image_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_image.rb, line 53
def get_image(image_id)
  if img = data[:images]["items"].find do |image|
    image["id"] == image_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = img
  response
end
get_ip_block(ip_block_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_ip_block.rb, line 40
def get_ip_block(ip_block_id)
  if ip_block = data[:ip_blocks]['items'].find do |ipb|
    ipb["id"] == ip_block_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = ip_block
  response
end
get_lan(datacenter_id, lan_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_lan.rb, line 102
def get_lan(datacenter_id, lan_id)
  if lan = data[:lans]['items'].find do |ln|
    ln["datacenter_id"] == datacenter_id && ln["id"] == lan_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = lan
  response
end
get_load_balanced_nic(datacenter_id, load_balancer_id, _nic_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_load_balanced_nic.rb, line 79
def get_load_balanced_nic(datacenter_id, load_balancer_id, _nic_id)
  if load_balancer = data[:load_balancers]['items'].find do |lb|
    lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  load_balanced_nic = nil

  load_balanced_nic = if load_balancer['entities']
                        load_balancer['entities']['balancednics']['items'][0]
                      else
                        load_balancer['balancednics']['items'][0]
                      end

  load_balanced_nic['mac'] = '01:23:45:67:89:00'
  load_balanced_nic['nat'] = false
  load_balanced_nic['firewall_active'] = true
  load_balanced_nic['lan'] = load_balanced_nic[:lan]
  load_balanced_nic['ips'] = load_balanced_nic[:ips]

  response        = Excon::Response.new
  response.status = 200
  response.body   = load_balanced_nic
  response
end
get_load_balancer(datacenter_id, load_balancer_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_load_balancer.rb, line 98
def get_load_balancer(datacenter_id, load_balancer_id)
  if load_balancer = data[:load_balancers]['items'].find do |lb|
    lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = load_balancer
  response
end
get_location(location_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_location.rb, line 31
def get_location(location_id)
  if loc = data[:locations]['items'].find do |lo|
    lo["id"] == location_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = loc
  response
end
get_nic(datacenter_id, server_id, nic_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_nic.rb, line 79
def get_nic(datacenter_id, server_id, nic_id)
  if nic = data[:nics]['items'].find do |nic|
    nic["id"] == nic_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = nic
  response
end
get_request(request_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_request.rb, line 49
def get_request(request_id)
  if request = data[:requests]["items"].find do |req|
    req["id"] == request_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:requests]['items'][0]

  response
  end
get_request_status(_request_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_request_status.rb, line 38
def get_request_status(_request_id)
  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:request_status]

  response
  end
get_resource_by_type(resource_type, resource_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_resource_by_type.rb, line 63
def get_resource_by_type(resource_type, resource_id)
  if resource = data[:resources]['items'].find do |r|
    r["type"] == resource_type && r["id"] == resource_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
get_resources_by_type(resource_type) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_resources_by_type.rb, line 34
def get_resources_by_type(resource_type)
  if resources = data[:resources]['items'].select {|resource| resource['type'] == resource_type}
    result = data[:resources].dup
    result['items'] = resources
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response = Excon::Response.new
  response.status = 200
  response.body = result
  response
end
get_server(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_server.rb, line 114
def get_server(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = server
  response
end
get_share(group_id, resource_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_share.rb, line 36
def get_share(group_id, resource_id)
  if share = data[:shares]['items'].find do |shr|
    shr["id"] == resource_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = share
  response
end
get_snapshot(snapshot_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_snapshot.rb, line 52
def get_snapshot(snapshot_id)
  if snapshot = data[:snapshots]['items'].find do |attrib|
    attrib["id"] == snapshot_id
  end
  else
    raise Excon::Error::HTTPStatus, 'Resource does not exist'
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = snapshot
  response
end
get_user(user_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_user.rb, line 56
def get_user(user_id)
  if user = data[:users]['items'].find do |usr|
    usr["id"] == user_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = user
  response
end
get_volume(datacenter_id, volume_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/get_volume.rb, line 55
def get_volume(datacenter_id, volume_id)
  if volume = data[:volumes]['items'].find do |vlm|
    vlm["id"] == volume_id && vlm["datacenter_id"] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body   = volume
  response
end
list_attached_cdroms(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/list_attached_cdroms.rb, line 58
def list_attached_cdroms(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  data[:images]['items'] = data[:images]['items'].select {|img| img['imageType'] == 'CDROM'}

  response        = Excon::Response.new
  response.status = 200
  response.body   = data[:images]
  response
end
list_attached_volumes(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/list_attached_volumes.rb, line 59
def list_attached_volumes(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |serv|
    serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response        = Excon::Response.new
  response.status = 200
  response.body = if server['volumes']
                    server['volumes']
                  else
                    {
                      'id' => "#{server_id}/volumes",
                      'type'  => 'collection',
                      'href'  => "https=>//api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/volumes",
                      'items' => []
                    }
                  end

  response
end
reboot_server(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/reboot_server.rb, line 28
def reboot_server(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |attrib|
    attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
  end
  else
    raise Fog::Errors::NotFound, 'The requested server resource could not be found'
  end

  response        = Excon::Response.new
  response.status = 202
  response
end
remove_nic_association(datacenter_id, load_balancer_id, _nic_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/remove_nic_association.rb, line 27
def remove_nic_association(datacenter_id, load_balancer_id, _nic_id)
  if load_balancer = data[:load_balancers]['items'].find do |lb|
    lb["datacenter_id"] == datacenter_id && lb["id"] == load_balancer_id
  end
  else
    raise Fog::Errors::NotFound, "The requested resource could not be found"
  end

  response        = Excon::Response.new
  response.status = 202
  response
end
remove_user_from_group(group_id, user_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/remove_user_from_group.rb, line 26
def remove_user_from_group(group_id, user_id)
  response = Excon::Response.new
  response.status = 202

  if group = data[:groups]['items'].find do |grp|
    grp["id"] == group_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  if user = data[:users]['items'].find do |usr|
    usr["id"] == user_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  response
end
reset_data() click to toggle source
# File lib/fog/profitbricks/compute.rb, line 1279
def reset_data
  self.class.data.delete(@profitbricks_username)
end
restore_volume_snapshot(datacenter_id, volume_id, _options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/restore_volume_snapshot.rb, line 36
def restore_volume_snapshot(datacenter_id, volume_id, _options = {})
  response = Excon::Response.new
  response.status = 202

  if datacenter = data[:datacenters]['items'].find do |attrib|
    attrib['id'] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, 'Data center resource could not be found'
  end

  if volume = data[:volumes]['items'].find do |attrib|
    attrib['id'] == volume_id && attrib['datacenter_id'] == datacenter_id
  end
  else
    raise Excon::Error::HTTPStatus, 'Volume resource could not be found'
  end

  response
end
start_server(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/start_server.rb, line 27
def start_server(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |attrib|
    attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
  end
  else
    raise Fog::Errors::NotFound, 'The requested server resource could not be found'
  end

  server['vm_state'] = 'RUNNING'
  server['state'] = 'AVAILABLE'

  response        = Excon::Response.new
  response.status = 202
  response
end
stop_server(datacenter_id, server_id) click to toggle source
# File lib/fog/profitbricks/requests/compute/stop_server.rb, line 28
def stop_server(datacenter_id, server_id)
  if server = data[:servers]['items'].find do |attrib|
    attrib['datacenter_id'] == datacenter_id && attrib['id'] == server_id
  end
  else
    raise Fog::Errors::NotFound, 'The requested server resource could not be found'
  end

  server['vm_state'] = 'SHUTOFF'
  server['state'] = 'INACTIVE'

  response        = Excon::Response.new
  response.status = 202
  response
end
update_datacenter(datacenter_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_datacenter.rb, line 49
def update_datacenter(datacenter_id, options = {})
  if dc = data[:datacenters]["items"].find do |datacenter|
    datacenter["id"] == datacenter_id
  end

    dc['properties']['version'] += 1 if dc['properties']
    dc['version'] += 1 if dc['version']

    dc['properties']['name'] = options[:properties][:name] if dc['properties']
    dc['name'] = options[:name] if dc['name']

  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
update_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_firewall_rule.rb, line 65
def update_firewall_rule(datacenter_id, server_id, nic_id, firewall_rule_id, options = {})
  if firewall_rule = data[:firewall_rules]['items'].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["server_id"] == server_id && attribute["nic_id"] == nic_id && attribute["id"] == firewall_rule_id
  end
    options.each do |key, value|
      firewall_rule[key] = value
    end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
update_group(group_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_group.rb, line 63
def update_group(group_id, options = {})
  if group = data[:groups]['items'].find do |grp|
    grp["id"] == group_id
  end
    group['name']               = options[:name]
    group['createDataCenter']   = options[:createDataCenter] if [true, false].include?(options[:createDataCenter])
    group['createSnapshot']     = options[:createSnapshot] if [true, false].include?(options[:createSnapshot])
    group['reserveIp']          = options[:reserveIp] if [true, false].include?(options[:reserveIp])
    group['accessActivityLog']  = options[:accessActivityLog] if [true, false].include?(options[:accessActivityLog])
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
update_image(image_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_image.rb, line 68
def update_image(image_id, options = {})
  if img = data[:images]["items"].find do |image|
    image["id"] == image_id
  end
    img['licenceType'] = options[:licenceType]
    options.each do |key, value|
      img[key.to_s] = value
    end

  else
    raise Excon::Error::HTTPStatus, "The requested resource could not be found"
  end

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

  response
end
update_lan(datacenter_id, lan_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_lan.rb, line 106
def update_lan(datacenter_id, lan_id, options = {})
  if lan = data[:lans]['items'].find do |attrib|
    attrib['datacenter_id'] == datacenter_id && attrib['id'] == lan_id
  end
    options.each do |key, value|
      lan[key] = value
    end
  else
    raise Fog::Errors::NotFound, 'The requested LAN resource could not be found'
  end

  response        = Excon::Response.new
  response.status = 202
  response.body   = lan
  response
end
update_load_balancer(datacenter_id, load_balancer_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_load_balancer.rb, line 48
def update_load_balancer(datacenter_id, load_balancer_id, options = {})
  if load_balancer = data[:load_balancers]['items'].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["id"] == load_balancer_id
  end
    options.each do |key, value|
      load_balancer[key] = value
    end
  else
    raise Fog::Errors::NotFound, 'The requested resource could not be found'
  end

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

  response
end
update_nic(datacenter_id, server_id, nic_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_nic.rb, line 85
def update_nic(datacenter_id, server_id, nic_id, options = {})
  if nic = data[:nics]['items'].find do |attribute|
    attribute["datacenter_id"] == datacenter_id && attribute["server_id"] == server_id && attribute["id"] == nic_id
  end
    nic['name'] = options[:name]
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
update_server(_datacenter_id, server_id, properties = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_server.rb, line 125
def update_server(_datacenter_id, server_id, properties = {})
  if server = data[:servers]['items'].find do |attrib|
    attrib['id'] == server_id
  end
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

  server['name'] = properties[:name]

  response        = Excon::Response.new
  response.status = 202
  response.body   = server
  response
end
update_share(group_id, resource_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_share.rb, line 48
def update_share(group_id, resource_id, options = {})
  if share = data[:shares]['items'].find do |shr|
    shr["id"] == resource_id
  end
    share['editPrivilege']   = options[:editPrivilege] if [true, false].include?(options[:editPrivilege])
    share['sharePrivilege']  = options[:sharePrivilege] if [true, false].include?(options[:sharePrivilege])
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
update_snapshot(snapshot_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_snapshot.rb, line 67
def update_snapshot(snapshot_id, options = {})
  if snapshot = data[:snapshots]['items'].find do |snpsht|
    snpsht["id"] == snapshot_id
  end
    options.each do |key, value|
      snapshot[key] = value
    end
  else
    raise Fog::Errors::NotFound, 'The requested resource could not be found'
  end

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

  response
end
update_user(user_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_user.rb, line 72
def update_user(user_id, options = {})
  if user = data[:users]['items'].find do |usr|
    usr["id"] == user_id
  end
    user['firstname']     = options[:firstname]
    user['lastname']      = options[:lastname]
    user['email']         = options[:email]
    user['administrator'] = options[:administrator]
    user['forceSecAuth']  = options[:force_sec_auth] || false
  else
    raise Excon::Error::HTTPStatus, "Resource does not exist"
  end

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

  response
end
update_volume(datacenter_id, volume_id, options = {}) click to toggle source
# File lib/fog/profitbricks/requests/compute/update_volume.rb, line 60
def update_volume(datacenter_id, volume_id, options = {})
  if volume = data[:volumes]['items'].find do |vlm|
    vlm["id"] == volume_id && vlm["datacenter_id"] == datacenter_id
  end
    volume['name'] = options[:name]
    volume['size'] = options[:size]
  else
    raise Excon::Error::HTTPStatus, 'The requested resource could not be found'
  end

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

  response
end