Class: Fog::Compute::Cloudstack::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/cloudstack/compute.rb,
lib/fog/cloudstack/requests/compute/list_zones.rb,
lib/fog/cloudstack/requests/compute/list_volumes.rb,
lib/fog/cloudstack/requests/compute/attach_volume.rb,
lib/fog/cloudstack/requests/compute/create_volume.rb,
lib/fog/cloudstack/requests/compute/delete_volume.rb,
lib/fog/cloudstack/requests/compute/detach_volume.rb,
lib/fog/cloudstack/requests/compute/list_os_types.rb,
lib/fog/cloudstack/requests/compute/list_snapshots.rb,
lib/fog/cloudstack/requests/compute/list_templates.rb,
lib/fog/cloudstack/requests/compute/create_snapshot.rb,
lib/fog/cloudstack/requests/compute/delete_snapshot.rb,
lib/fog/cloudstack/requests/compute/list_async_jobs.rb,
lib/fog/cloudstack/requests/compute/extract_template.rb,
lib/fog/cloudstack/requests/compute/register_template.rb,
lib/fog/cloudstack/requests/compute/list_disk_offerings.rb,
lib/fog/cloudstack/requests/compute/list_firewall_rules.rb,
lib/fog/cloudstack/requests/compute/associate_ip_address.rb,
lib/fog/cloudstack/requests/compute/create_disk_offering.rb,
lib/fog/cloudstack/requests/compute/create_firewall_rule.rb,
lib/fog/cloudstack/requests/compute/delete_disk_offering.rb,
lib/fog/cloudstack/requests/compute/delete_firewall_rule.rb,
lib/fog/cloudstack/requests/compute/list_security_groups.rb,
lib/fog/cloudstack/requests/compute/create_security_group.rb,
lib/fog/cloudstack/requests/compute/delete_security_group.rb,
lib/fog/cloudstack/requests/compute/list_virtual_machines.rb,
lib/fog/cloudstack/requests/compute/deploy_virtual_machine.rb,
lib/fog/cloudstack/requests/compute/list_network_offerings.rb,
lib/fog/cloudstack/requests/compute/list_service_offerings.rb,
lib/fog/cloudstack/requests/compute/query_async_job_result.rb,
lib/fog/cloudstack/requests/compute/reboot_virtual_machine.rb,
lib/fog/cloudstack/requests/compute/create_network_offering.rb,
lib/fog/cloudstack/requests/compute/create_service_offering.rb,
lib/fog/cloudstack/requests/compute/delete_network_offering.rb,
lib/fog/cloudstack/requests/compute/delete_service_offering.rb,
lib/fog/cloudstack/requests/compute/destroy_virtual_machine.rb,
lib/fog/cloudstack/requests/compute/disassociate_ip_address.rb,
lib/fog/cloudstack/requests/compute/list_public_ip_addresses.rb,
lib/fog/cloudstack/requests/compute/list_egress_firewall_rules.rb,
lib/fog/cloudstack/requests/compute/list_port_forwarding_rules.rb,
lib/fog/cloudstack/requests/compute/create_egress_firewall_rule.rb,
lib/fog/cloudstack/requests/compute/create_port_forwarding_rule.rb,
lib/fog/cloudstack/requests/compute/delete_egress_firewall_rule.rb,
lib/fog/cloudstack/requests/compute/revoke_security_group_egress.rb,
lib/fog/cloudstack/requests/compute/revoke_security_group_ingress.rb,
lib/fog/cloudstack/requests/compute/authorize_security_group_egress.rb,
lib/fog/cloudstack/requests/compute/authorize_security_group_ingress.rb

Overview

Real

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



661
662
663
664
# File 'lib/fog/cloudstack/compute.rb', line 661

def initialize(options={})
  @cloudstack_api_key = options[:cloudstack_api_key]
  @cloudstack_project_id = Fog.credentials[:cloudstack_project_id] || Fog::Cloudstack.uuid
end

Class Method Details

.dataObject



666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
# File 'lib/fog/cloudstack/compute.rb', line 666

def self.data
  @data ||= begin
    zone_id     = Fog.credentials[:cloudstack_zone_id]             || Fog::Cloudstack.uuid
    image_id    = Fog.credentials[:cloudstack_template_id]         || Fog::Cloudstack.uuid
    flavor_id   = Fog.credentials[:cloudstack_service_offering_id] || Fog::Cloudstack.uuid
    network_id  = (Array(Fog.credentials[:cloudstack_network_ids]) || [Fog::Cloudstack.uuid]).first
    domain_name = "exampleorg"
    , user_id, domain_id = Fog::Cloudstack.uuid, Fog::Cloudstack.uuid, Fog::Cloudstack.uuid
    domain = {
      "id"               => domain_id,
      "name"             => domain_name,
      "level"            => 1,
      "parentdomainid"   => Fog::Cloudstack.uuid,
      "parentdomainname" => "ROOT",
      "haschild"         => false,
      "path"             => "ROOT/accountname"
    }
    user = {
      "id"          => user_id,
      "username"    => "username",
      "firstname"   => "Bob",
      "lastname"    => "Lastname",
      "email"       => "[email protected]",
      "created"     => "2012-05-14T16:25:17-0500",
      "state"       => "enabled",
      "account"     => "accountname",
      "accounttype" => 2,
      "domainid"    => domain_id,
      "domain"      => domain_name,
      "apikey"      => Fog::Cloudstack.uuid,
      "secretkey"   => Fog::Cloudstack.uuid
    }
    {
      :users    => { user_id    => user },
      :networks => { network_id => {
        "id"                          => network_id,
        "name"                        => "10.56.23.0/26",
        "displaytext"                 => "10.56.23.0/26",
        "broadcastdomaintype"         => "Vlan",
        "traffictype"                 => "Guest",
        "gateway"                     => "10.56.23.1",
        "netmask"                     => "255.255.255.192",
        "cidr"                        => "10.56.23.0/26",
        "zoneid"                      => zone_id,
        "zonename"                    => "zone-00",
        "networkofferingid"           => "af0c9bd5-a1b2-4ad0-bf4b-d6fa9b1b9d5b",
        "networkofferingname"         => "DefaultSharedNetworkOffering",
        "networkofferingdisplaytext"  => "Offering for Shared networks",
        "networkofferingavailability" => "Optional",
        "issystem"                    => false,
        "state"                       => "Setup",
        "related"                     => "86bbc9fc-d92e-49db-9fdc-296189090017",
        "broadcasturi"                => "vlan://800",
        "dns1"                        => "10.0.80.11",
        "type"                        => "Shared",
        "vlan"                        => "800",
        "acltype"                     => "Domain",
        "subdomainaccess"             => true,
        "domainid"                    => domain_id,
        "domain"                      => "ROOT",
        "service" => [
          {"name" => "UserData"},
          {"name" => "Dhcp"},
          {
            "name"       => "Dns",
            "capability" => [
              {
                "name"                       => "AllowDnsSuffixModification",
                "value"                      => "true",
                "canchooseservicecapability" => false
              }
            ]
        }],
        "networkdomain"     => "cs1cloud.internal",
        "physicalnetworkid" => "8f4627c5-1fdd-4504-8a92-f61b4e9cb3e3",
        "restartrequired"   => false,
        "specifyipranges"   => true}
      },
      :public_ip_addresses => { "0e276270-7950-4483-bf21-3dc897dbe08a" => {
        "id"                => "0e276270-7950-4483-bf21-3dc897dbe08a",
        "ipaddress"         => "192.168.200.2",
        "allocated"         => "2014-11-26T22:32:39+0000",
        "zoneid"            => "0e276270-7950-4483-bf21-3dc897dbe08a",
        "zonename"          => "Toronto",
        "issourcenat"       => false,
        "projectid"         => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
        "project"           => "TestProject",
        "domainid"          => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
        "domain"            => "TestDomain",
        "forvirtualnetwork" => true,
        "isstaticnat"       => false,
        "issystem"          => false,
        "associatednetworkid" => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
        "associatednetworkname" => "TestNetwork",
        "networkid"         => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
        "state"             => "Allocated",
        "physicalnetworkid" => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
        "tags"              => []
      }},
      :zones => { zone_id => {
        "id"                    => zone_id,
        "name"                  => "zone-00",
        "domainid"              => 1,
        "domainname"            => "ROOT",
        "networktype"           => "Advanced",
        "securitygroupsenabled" => false,
        "allocationstate"       => "Enabled",
        "zonetoken"             => Fog::Cloudstack.uuid,
        "dhcpprovider"          => "VirtualRouter"}},
      :images => { image_id => {
        "id"              => image_id,
        "name"            => "CentOS 5.6(64-bit) no GUI (XenServer)",
        "displaytext"     => "CentOS 5.6(64-bit) no GUI (XenServer)",
        "ispublic"        => true,
        "created"         => "2012-05-09T15:29:33-0500",
        "isready"         => true,
        "passwordenabled" => false,
        "format"          => "VHD",
        "isfeatured"      => true,
        "crossZones"      => true,
        "ostypeid"        => "a6a6694a-18f5-4765-8418-2b7a5f37cd0f",
        "ostypename"      => "CentOS 5.3 (64-bit)",
        "account"         => "system",
        "zoneid"          => zone_id,
        "zonename"        => "zone-00",
        "status"          => "Download Complete",
        "size"            => 21474836480,
        "templatetype"    => "BUILTIN",
        "domain"          => "ROOT",
        "domainid"        => "6023b6fe-5bef-4358-bc76-9f4e75afa52f",
        "isextractable"   => true,
        "checksum"        => "905cec879afd9c9d22ecc8036131a180",
        "hypervisor"      => "Xen"
      }},
      :flavors => { flavor_id => {
        "id"          => flavor_id,
        "name"        => "Medium Instance",
        "displaytext" => "Medium Instance",
        "cpunumber"   => 1,
        "cpuspeed"    => 1000,
        "memory"      => 1024,
        "created"     => "2012-05-09T14:48:36-0500",
        "storagetype" => "shared",
        "offerha"     => false,
        "limitcpuuse" => false,
        "issystem"    => false,
        "defaultuse"  => false
      }},
      :accounts => {  => {
        "id"                => ,
        "name"              => "accountname",
        "accounttype"       => 2,
        "domainid"          => domain_id,
        "domain"            => domain_name,
        "receivedbytes"     => 0,
        "sentbytes"         => 0,
        "vmlimit"           => "Unlimited",
        "vmtotal"           => 0,
        "vmavailable"       => "Unlimited",
        "iplimit"           => "Unlimited",
        "iptotal"           => 0,
        "ipavailable"       => "Unlimited",
        "volumelimit"       => "Unlimited",
        "volumetotal"       => 0,
        "volumeavailable"   => "Unlimited",
        "snapshotlimit"     => "Unlimited",
        "snapshottotal"     => 0,
        "snapshotavailable" => "Unlimited",
        "templatelimit"     => "Unlimited",
        "templatetotal"     => 0,
        "templateavailable" => "Unlimited",
        "vmstopped"         => 0,
        "vmrunning"         => 0,
        "projectlimit"      => "Unlimited",
        "projecttotal"      => 1,
        "projectavailable"  => "Unlimited",
        "networklimit"      => "Unlimited",
        "networktotal"      => 0,
        "networkavailable"  => "Unlimited",
        "state"             => "enabled",
        "user"              => [user]}
      },
      :domains         => {domain_id => domain},
      :servers         => {},
      :jobs            => {},
      :volumes         => {
        "89198f7c-0245-aa1d-136a-c5f479ef9db7" => {
          "id"=> "89198f7c-0245-aa1d-136a-c5f479ef9db7",
          "name"=>"test volume",
          "zoneid"=> zone_id,
          "zonename"=>"zone-00",
          "type"=>"DATADISK",
          "deviceid"=>1,
          "virtualmachineid"=> "51dcffee-5f9f-29a4-acee-2717e1a3656b",
          "vmname"=>"i-2824-11621-VM",
          "vmdisplayname"=>"test vm",
          "vmstate"=>"Running",
          "size"=>17179869184,
          "created"=>"2013-04-16T12:33:41+0000",
          "state"=>"Ready",
          "account"=> 'accountname',
          "domainid"=> domain_id,
          "domain"=> domain_name,
          "storagetype"=>"shared",
          "hypervisor"=>"KVM",
          "diskofferingid"=> "cc4de87d-672d-4353-abb5-6a8a4c0abf59",
          "diskofferingname"=>"Small Disk",
          "diskofferingdisplaytext"=>"Small Disk [16GB Disk]",
          "storage"=>"ps1",
          "attached"=>"2013-04-16T12:34:07+0000",
          "destroyed"=>false,
          "isextractable"=>false
          },
        },
      :security_groups => {},
      :snapshots       => {},
      :disk_offerings  => {
        "cc4de87d-672d-4353-abb5-6a8a4c0abf59" => {
          "id"           => "cc4de87d-672d-4353-abb5-6a8a4c0abf59",
          "domainid"     => domain_id,
          "domain"       => domain_name,
          "name"         => "Small Disk",
          "displaytext"  => "Small Disk [16GB Disk]",
          "disksize"     => 16,
          "created"      => "2013-02-21T03:12:520300",
          "iscustomized" => false,
          "storagetype"  =>  "shared"
        },
        "d5deeb0c-de03-4ebf-820a-dc74221bcaeb" => {
          "id"           => "d5deeb0c-de03-4ebf-820a-dc74221bcaeb",
          "domainid"     => domain_id,
          "domain"       => domain_name,
          "name"         => "Medium Disk",
          "displaytext"  => "Medium Disk [32GB Disk]",
          "disksize"     => 32,
          "created"      => "2013-02-21T03:12:520300",
          "iscustomized" => false,
          "storagetype"  => "shared"
        }
      },
      :network_offerings  => {
        "cc4de87d-672d-4353-abb5-6a8a4c0abf59" => {
          "id"                => "cc4de87d-672d-4353-abb5-6a8a4c0abf59",
          "name"              => "Shared Network With Security Groups",
          "displaytext"       => "Shared Network With Security Groups",
          "traffictype"       => "Guest",
          "isdefault"         => true,
          "specifyvlan"       => true,
          "conservemode"      => true,
          "specifyipranges"   => true,
          "availability"      =>  "Optional",
          "networkrate"       =>  200,
          "state"             =>  "Enabled",
          "guestiptype"       =>  "Shared",
          "serviceofferingid" =>  "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1"
        }
      },
      :firewall_rules => {
        "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1" => {
          "id"=> "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
          "protocol"=> "tcp",
          "startport" => "443",
          "endport" => "443",
          "ipaddressid" => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
          "networkid"=> "31c4b26e-4be9-11e4-8304-00163e5b5f54",
          "ipaddress" => "192.168.200.1",
          "state" => "Active",
          "cidrlist" => "255.255.255.0/24",
          "tags" => []
        }
      },
      :egress_firewall_rules => {
        "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1" => {
          "id"=>"f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
          "protocol"=>"tcp",
          "networkid"=> "31c4b26e-4be9-11e4-8304-00163e5b5f54",
          "state"=>"Active",
          "cidrlist"=>"10.2.1.0/24",
          "tags"=>[]
        }
      },
      :port_forwarding_rules => {
        "8f4627c5-1fdd-4504-8a92-f61b4e9cb3e3" => {
          'id' => "8f4627c5-1fdd-4504-8a92-f61b4e9cb3e3",
          'privateport' => "25",
          'privateendport' => "25",
          'protocol' => "tcp",
          'publicport' => "25",
          'publicendport' => "25",
          'virtualmachineid' => "8f4627c5-1fdd-4504-8a92-f61b4e9cb3e3",
          'virtualmachinename' => "LoadBalancer",
          'virtualmachinedisplayname' => "LoadBalancer",
          'ipaddressid' => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
          'ipaddress' => "192.168.200.200",
          'state' => "Active",
          'cidrlist' => "",
          'tags' => []
        }
      },
      :os_types  => {
        "51ef854d-279e-4e68-9059-74980fd7b29b" => {
          "id"           => "51ef854d-279e-4e68-9059-74980fd7b29b",
          "oscategoryid" => "56f67279-e082-45c3-a01c-d290d6cd4ce2",
          "description"  => "Asianux 3(32-bit)"
          },
        "daf124c8-95d8-4756-8e1c-1871b073babb" => {
          "id"           => "daf124c8-95d8-4756-8e1c-1871b073babb",
          "oscategoryid" => "56f67279-e082-45c3-a01c-d290d6cd4ce2",
          "description"  => "Asianux 3(64-bit)"
          }
      }
    }
  end
end

.resetObject



981
982
983
# File 'lib/fog/cloudstack/compute.rb', line 981

def self.reset
  @data = nil
end

Instance Method Details

#add_delete_snapshot_job(snapshot_id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/cloudstack/requests/compute/delete_snapshot.rb', line 37

def add_delete_snapshot_job(snapshot_id)
  job_id = Fog::Cloudstack.uuid

  job = {
    'id' => job_id,
    'user_id' => self.data[:users].first, # TODO use current user
    'account_id' => self.data[:accounts].first, # TODO use current user
    'cmd' => 'com.cloud.api.commands.DeleteSnapshotCmd',
    'job_status'=> 1,
    'job_result_type' => nil,
    'job_result_code' => 0,
    'job_proc_status' => 0,
    'created_at' => Time.now.iso8601,
    'job_result' => { "success" => true }
  }

  self.data[:jobs][job_id] = job
  job_id
end

#associate_ip_address(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/cloudstack/requests/compute/associate_ip_address.rb', line 24

def associate_ip_address(*args)
  public_ip_address = {
    "id"                => "f2f2f2f2-f2f2-f2f2-f2f2-f2f2f2f2f2",
    "ipaddress"         => "192.168.200.3",
    "allocated"         => "2014-12-22T22:32:39+0000",
    "zoneid"            => "0e276270-7950-4483-bf21-3dc897dbe08a",
    "zonename"          => "Toronto",
    "issourcenat"       => false,
    "projectid"         => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
    "project"           => "TestProject",
    "domainid"          => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
    "domain"            => "TestDomain",
    "forvirtualnetwork" => true,
    "isstaticnat"       => false,
    "issystem"          => false,
    "associatednetworkid" => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
    "associatednetworkname" => "TestNetwork",
    "networkid"         => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
    "state"             => "Allocated",
    "physicalnetworkid" => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
    "tags"              => []

  }
  self.data[:public_ip_addresses][public_ip_address_id]= public_ip_address
  {'associateipaddressresponse' => public_ip_address}
end

#attach_volume(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/cloudstack/requests/compute/attach_volume.rb', line 25

def attach_volume(options={})
  volume_id = options['id']
  server_id = options['virtualmachineid']

  volume = self.data[:volumes][volume_id]
  unless volume
    raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command attachvolume due to invalid value. Object volumes(uuid: #{volume_id}) does not exist.")
  end

  server = self.data[:servers][server_id]
  unless server
    raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command attachvolume due to invalid value. Object vm_instance(uuid: #{server_id}) does not exist.")
  end

  volume['virtualmachineid']= server['id']
  volume['vmname']= server['name']
  volume['vmdisplayname']= server['displayname']

  job_id = Fog::Cloudstack.uuid

  # FIXME: need to determine current user
   = self.data[:accounts].first
  user_id = self.data[:users].first

  job = {
    "accountid"     => ,
    "userid"        => user_id,
    "cmd"           => "com.cloud.api.commands.AttachVolumeCmd",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     =>
      {"volume"     => volume}
  }

  self.data[:jobs][job_id]= job

  {
    "attachvolumeresponse" => {
      "jobid" => job_id
    }
  }
end

#authorize_security_group_egress(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fog/cloudstack/requests/compute/authorize_security_group_egress.rb', line 22

def authorize_security_group_egress(options={})
  security_group_id      = options['securitygroupid']
  security_group_rule_id = Fog::Cloudstack.uuid

  unless cidr = options['cidrlist']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter cidr')
  end

  unless start_port = options['startport']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter start_port')
  end

  unless end_port = options['endport']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter end_port')
  end

  unless protocol = options['protocol']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter protocol')
  end

  rule = {
    "ruleid"    => security_group_rule_id,
    "cidr"      => cidr,
    "startport" => start_port,
    "endport"   => end_port,
    "protocol"  => protocol
  }

  unless security_group = self.data[:security_groups][security_group_id]
    raise Fog::Compute::Cloudstack::BadRequest.new("Security group id #{security_group_id} does not exist")
  end

  security_group["egressrule"] ||= []
  security_group["egressrule"] << rule

  job_id = Fog::Cloudstack.uuid
  job = {
    "cmd"           => "com.cloud.api.commands.authorizeSecurityGroupEgress",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     => { "securitygroup" => security_group }
  }

  self.data[:jobs][job_id]= job

  { "authorizesecuritygroupegressresponse" => { "jobid" => job_id } }
end

#authorize_security_group_ingress(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/fog/cloudstack/requests/compute/authorize_security_group_ingress.rb', line 22

def authorize_security_group_ingress(options={})
  security_group_id      = options['securitygroupid']
  security_group_rule_id = Fog::Cloudstack.uuid

  unless cidr = options['cidrlist']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter cidr')
  end

  unless start_port = options['startport']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter start_port')
  end

  unless end_port = options['endport']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter end_port')
  end

  unless protocol = options['protocol']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter protocol')
  end

  rule = {
    "ruleid"    => security_group_rule_id,
    "cidr"      => cidr,
    "startport" => start_port,
    "endport"   => end_port,
    "protocol"  => protocol
  }

  unless security_group = self.data[:security_groups][security_group_id]
    raise Fog::Compute::Cloudstack::BadRequest.new("Security group id #{security_group_id} does not exist")
  end

  security_group["ingressrule"] ||= []
  security_group["ingressrule"] << rule

  job_id = Fog::Cloudstack.uuid
  job = {
    "cmd"           => "com.cloud.api.commands.authorizeSecurityGroupIngress",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     => { "securitygroup" => security_group }
  }

  self.data[:jobs][job_id]= job

  { "authorizesecuritygroupingressresponse" => { "jobid" => job_id } }
end

#create_disk_offering(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fog/cloudstack/requests/compute/create_disk_offering.rb', line 25

def create_disk_offering(options={})
  disk_offering_id = Fog::Cloudstack.uuid

  first_domain_data = data[:domains].first.last
  domain_id = options['domainid'] || first_domain_data['id']
  domain_name = data[:domains][domain_id]['name']

  storage_type = options['storagetype'] || 'shared'
  customized = options['customized'] || false
  disk_size = options['disk_size'] || 1

  disk_offering = {
    "id"           => disk_offering_id,
    "domainid"     => domain_id,
    "domain"       => domain_name,
    "name"         => options['name'],
    "displaytext"  => options['display_text'],
    "disksize"     => disk_size,
    "created"      => Time.now.iso8601,
    "iscustomized" => customized,
    "storagetype"  => storage_type
  }

  self.data[:disk_offerings][disk_offering_id] = disk_offering

  {'creatediskofferingresponse' => disk_offering}
end

#create_egress_firewall_rule(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/cloudstack/requests/compute/create_egress_firewall_rule.rb', line 24

def create_egress_firewall_rule(*args)
  egress_firewall_rule_id = Fog::Cloudstack.uuid

  egress_firewall_rule = {
    "id" => egress_firewall_rule_id,
    "protocol" => "tcp",
    "networkid" => "f1f1f1-f1f1-f1f1f1-f1f1f1f1f1",
    "state" => "Active",
    "cidrlist" => "10.2.1.0/24",
  }

  self.data[:egress_firewall_rules][egress_firewall_rule_id] = egress_firewall_rule

  {'createegressfirewallruleresponse' => egress_firewall_rule}
end

#create_firewall_rule(options = {}) ⇒ Object



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

def create_firewall_rule(options={})
  firewall_rule_id = Fog::Cloudstack.uuid

  firewall_rule = {
    "id"              => network_offering_id,
    "protocol"        => "tcp",
    "startport"       => 80,
    "endport"         => 80,
    "ipaddressid"     => "f1f1f1f1-f1f1-f1f1-f1f1f1f1f1f1",
    "networkid"       => "f1f1f1f1-f1f1-f1f1-f1f1f1f1f1f1",
    "ipaddress"       => "10.1.1.253",
    "state"           => "Active",
    "cidrlist"        => "255.255.255.0/24"
  }

  self.data[:firewall_rules][firewall_rule_id] = firewall_ruleetwork_offering

  {'createfirewallruleresponse' => firewall_rule}
end

#create_network_offering(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/cloudstack/requests/compute/create_network_offering.rb', line 27

def create_network_offering(options={})
  network_offering_id = Fog::Cloudstack.uuid

  network_offering = {
    "id"              => network_offering_id,
    "name"            => "Isolated Network for VPC",
    "displaytext"     => "Isolated Network for VPC",
    "traffictype"     => "Guest",
    "isdefault"       => true,
    "specifyvlan"     => true,
    "conservemode"    => true,
    "specifyipranges" => false,
    "availability"    => "Optional",
    "networkrate"     => 200,
    "state"           => "Enabled",
    "guestiptype"     => "Isolated",
    "serviceofferingid" => "eaec129c-f1f1-f1f1-f1f1-a379f6b2897d"
  }

  self.data[:network_offerings][network_offering_id] = network_offering

  {'createnetworkofferingresponse' => network_offering}
end

#create_port_forwarding_rule(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/cloudstack/requests/compute/create_port_forwarding_rule.rb', line 27

def create_port_forwarding_rule(*args)
  port_forwarding_rule_id = "43192143-5828-6831-58286837474"
  port_forwarding_rule = {
    'id'                      => port_forwarding_rule_id,
    'privateport' => "110",
    'privateendport' => "110",
    'protocol' => "tcp",
    'publicport' => "111",
    'publicendport' => "111",
    'virtualmachineid' => "8f4627c5-1fdd-4504-8a92-f61b4e9cb3e3",
    'virtualmachinename' => "Pop3LoadBalancer",
    'virtualmachinedisplayname' => "Pop3LoadBalancer",
    'ipaddressid' => "f1f1f1f1-f1f1-f1f1-f1f1-f1f1f1f1f1",
    'ipaddress' => "192.168.200.201",
    'state' => "Active",
    'cidrlist' => "",
    'tags' => []
  }

  self.data[:port_forwarding_rules][port_forwarding_rule_id]= port_forwarding_rule
  {'createportforwardingruleresponse' => port_forwarding_rule}

end

#create_security_group(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/cloudstack/requests/compute/create_security_group.rb', line 23

def create_security_group(options={})
  security_group_id = Fog::Cloudstack.uuid

  security_group = {
    "id" => security_group_id,
  }.merge(options)

  self.data[:security_groups][security_group_id]= security_group
  {"createsecuritygroupresponse" => { "securitygroup" => security_group}}
end

#create_service_offering(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/cloudstack/requests/compute/create_service_offering.rb', line 25

def create_service_offering(options={})
  flavour_id = Fog::Cloudstack.uuid

  flavour = {
    "id"            => flavour_id,
    "name"          => "4CPU, 4 GB RAM, High Availability",
    "displaytext"   => "4CPU, 4 GB RAM, High Availability",
    "cpunumber"     => 4,
    "cpuspeed"      => 2000,
    "memory"        => 4096,
    "created"       => Time.now.iso8601,
    "storagetype"   => "shared",
    "offerha"       => true,
    "limitcpuuse"   => false,
    "isvolatile"    => false,
    "issytem"       => false,
    "defaultuse"    => false,
    "iscustomized"  => false,
    "tags"          => []
  }

  self.data[:flavours][flavour_id] = flavour

  {'createserviceofferingresponse' => flavour}
end

#create_snapshot(options = {}) ⇒ Object



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

def create_snapshot(options={})
  snapshot_id = Fog::Cloudstack.uuid

  unless volume_id = options['volumeid']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command createsnapshot due to missing parameter volumeid')
  end

  snapshot = {
     "id"                      => snapshot_id,
     "name"                    => "ROOT-6",
     "created"                 => "2013-05-22T14:52:55-0500",
     "state"                   => "BackedUp",
     "account"                 => "accountname",
     "domainid"                => "6023b6fe-5bef-4358-bc76-9f4e75afa52f",
     "domain"                  => "ROOT",
     "intervaltype"            => "weekly"
  }

  self.data[:snapshots][snapshot_id]= snapshot
  {'createsnapshotresponse' => snapshot}
end

#create_volume(options = {}) ⇒ Object



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

def create_volume(options={})
  volume_id = Fog::Cloudstack.uuid

  unless volume_name = options['name']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command createvolume due to missing parameter name')
  end

  unless zone_id = options['zoneid']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command createvolume due to missing parameter zoneid')
  end

  unless disk_offering_id = options['diskofferingid']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command createvolume due to missing parameter diskofferingid')
  end

  volume = {
     "id"                      => volume_id,
     "name"                    => volume_name,
     "zoneid"                  => zone_id,
     "zonename"                => "ey-wdc-00",
     "type"                    => "DATADISK",
     "size"                    => 5368709120,
     "created"                 => "2012-05-22T14:52:55-0500",
     "state"                   => "Allocated",
     "account"                 => "accountname",
     "domainid"                => "6023b6fe-5bef-4358-bc76-9f4e75afa52f",
     "domain"                  => "ROOT",
     "storagetype"             => "shared",
     "hypervisor"              => "None",
     "diskofferingid"          => disk_offering_id,
     "diskofferingname"        => "Small",
     "diskofferingdisplaytext" => "Small Disk, 5 GB",
     "storage"                 => "none",
     "destroyed"               => false,
     "isextractable"           => false
  }

  self.data[:volumes][volume_id]= volume
  {'createvolumeresponse' => volume}
end

#dataObject



985
986
987
# File 'lib/fog/cloudstack/compute.rb', line 985

def data
  self.class.data
end

#delete_disk_offering(options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/fog/cloudstack/requests/compute/delete_disk_offering.rb', line 23

def delete_disk_offering(options={})
  disk_offering_id = options['id']
  data[:disk_offerings].delete(disk_offering_id) if data[:disk_offerings][disk_offering_id]

  { 'deletediskofferingresponse' => { 'success' => 'true' } }
end

#delete_egress_firewall_rule(options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/fog/cloudstack/requests/compute/delete_egress_firewall_rule.rb', line 23

def delete_egress_firewall_rule(options={})
  egress_firewall_rule_id = options['id']
  data[:egress_firewall_rules].delete(egress_firewall_rule_id) if data[:egress_firewall_rules][egress_firewall_rule_id]

  { 'deleteegressfirewallruleresponse' => { 'success' => 'true' } }
end

#delete_firewall_rule(options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/fog/cloudstack/requests/compute/delete_firewall_rule.rb', line 23

def delete_firewall_rule(options={})
  firewall_rule_id = options['id']
  data[:firewall_rules].delete(firewall_rule_id) if data[:firewall_rules][firewall_rule_id]

  { 'deletefirewallruleresponse' => { 'success' => 'true' } }
end

#delete_network_offering(options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/fog/cloudstack/requests/compute/delete_network_offering.rb', line 23

def delete_network_offering(options={})
  network_offering_id = options['id']
  data[:network_offerings].delete(network_offering_id) if data[:network_offerings][network_offering_id]

  { 'deletenetworkofferingresponse' => { 'success' => 'true' } }
end

#delete_security_group(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/cloudstack/requests/compute/delete_security_group.rb', line 22

def delete_security_group(options={})
  security_group_id = options['id']
  if self.data[:security_groups][security_group_id]
    self.data[:security_groups].delete(security_group_id)
    {
      "deletesecuritygroupresponse" => {
        "success" => "true"
      }
    }
  else
    raise Fog::Compute::Cloudstack::BadRequest.new('No security_group found')
  end
end

#delete_service_offering(options = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/fog/cloudstack/requests/compute/delete_service_offering.rb', line 23

def delete_service_offering(options={})
  service_offering_id = options['id']
  data[:favours].delete(service_offering_id) if data[:flavours][service_offering_id]

  { 'deleteserviceofferingresponse' => { 'success' => 'true' } }
end

#delete_snapshot(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/cloudstack/requests/compute/delete_snapshot.rb', line 23

def delete_snapshot(options={})
  snapshot_id = options['id']
  snapshots = self.data[:snapshots]

  if snapshots[snapshot_id]

    snapshots.delete(snapshot_id)
    job_id = add_delete_snapshot_job(snapshot_id)

    {'deletesnapshotresponse' => {'jobid' => job_id}}
  end
  # TODO add cases for empty or wrong id
end

#delete_volume(options = {}) ⇒ Object



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

def delete_volume(options={})
  volume_id = options['id']
  if self.data[:volumes][volume_id]
    self.data[:volumes].delete(volume_id)
    {
      "deletevolumeresponse" => {
        "success" => "true"
      }
    }
  else # FIXME: mayhaps
    self.data[:volumes].delete(volume_id)
    {
      "deletevolumeresponse" => {
        "success" => "false"
      }
    }
  end
end

#deploy_virtual_machine(options = {}) ⇒ Object



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

def deploy_virtual_machine(options={})
  zone_id = options['zoneid']
  unless zone_id
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter zoneid')
  end
  unless zone = self.data[:zones][zone_id]
    raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command deployvirtualmachine due to invalid value. Object zone(uuid: #{zone_id}) does not exist.")
  end
  zone_name = zone[:name]

  template_id = options['templateid']
  unless template = self.data[:images][template_id]
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter templateid')
  end
  template_name = template[:name]
  template_display_text = template[:display_text]

  service_offering_id = options['serviceofferingid']
  unless service_offering = self.data[:flavors][service_offering_id]
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command deployvirtualmachine due to missing parameter serviceofferingid')
  end

  service_offering_name = service_offering[:name]
  service_offering_cpu_number = service_offering[:cpunumber]
  service_offering_cpu_speed = service_offering[:cpuspeed]
  service_offering_memory = service_offering[:cpumemory]

  identity = Fog::Cloudstack.uuid
  name = options['name'] || Fog::Cloudstack.uuid
  display_name = options['displayname'] || name
   = options['account'] || self.data[:accounts].first[1]["name"]

  domain = options['domainid'] ? self.data[:domains][options['domainid']] : self.data[:domains].first[1]
  domain_id = domain[:id]
  domain_name = domain[:name]

  # how is this setup
  password = nil
  password_enabled = false

  guest_os_id = Fog::Cloudstack.uuid

  security_group_ids = options['securitygroupids'] || [] # TODO: for now

  network_ids = Array(options['networkids']) || [self.data[:networks].first[1]["id"]]
  networks = network_ids.map{|nid| self.data[:networks][nid]}
  nic = networks.map do |network|
    {
      "id" => Fog::Cloudstack.uuid,
      "networkid" => network["id"],
      "netmask" => Fog::Cloudstack.ip_address,
      "gateway" => network["gateway"],
      "ipaddress" => Fog::Cloudstack.ip_address,
      "traffictype" => "Guest", # TODO: ?
      "type" => network["type"],
      "isdefault" => true, # TODO: ?
      "macaddress" => Fog::Cloudstack.mac_address
    }
  end

  virtual_machine = {
    "id" => identity,
    "name" => name,
    "displayname" => display_name,
    "account" => ,
    "domainid" => domain_id,
    "domain" => domain_name,
    "created" => Time.now.to_s,
    "state" => "Running",
    "haenable" => false,
    "zoneid" => zone_id,
    "zonename" => zone_name,
    "templateid" => template_id,
    "templatename" => template_name,
    "templatedisplaytext" => template_display_text,
    "passwordenabled" => false,
    "serviceofferingid" => service_offering_id,
    "serviceofferingname" => service_offering_name,
    "cpunumber" => service_offering_cpu_number,
    "cpuspeed" => service_offering_cpu_speed,
    "memory" => service_offering_memory,
    "cpuused" => "0%",
    "networkkbsread" => 0,
    "networkkbswrite" => 0,
    "guestosid" => guest_os_id,
    "rootdeviceid" => 0,
    "rootdevicetype" => "NetworkFilesystem",
    "securitygroup" => security_group_ids, # TODO: mayhaps?
    "nic" => nic
  }

  self.data[:servers][identity]= virtual_machine
  {'deployvirtualmachineresponse' => virtual_machine}
end

#destroy_virtual_machine(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fog/cloudstack/requests/compute/destroy_virtual_machine.rb', line 23

def destroy_virtual_machine(options={})
  identity = options["id"]

  server = self.data[:servers][identity]
  unless server
    raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command attachserver due to invalid value. Object servers(uuid: #{identity}) does not exist.")
  end

  job_id = Fog::Cloudstack.uuid

  job = {
    "cmd"           => "com.cloud.api.commands.DestroyVirtualMachineCmd",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     =>
      {"virtualmachine" => server}
  }

  self.data[:jobs][job_id]= job
  self.data[:servers].delete(identity)

  {"destroyvirtualmachineresponse" => {"jobid" => job_id}}
end

#detach_volume(options = {}) ⇒ Object



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

def detach_volume(options={})
  volume_id = options['id']

  volume = self.data[:volumes][volume_id]
  unless volume
    raise Fog::Compute::Cloudstack::BadRequest.new("Unable to execute API command attachvolume due to invalid value. Object volumes(uuid: #{volume_id}) does not exist.")
  end

  volume['virtualmachineid']= volume['vmname']= volume['vmdisplayname']= nil

  job_id = Fog::Cloudstack.uuid

  # FIXME: need to determine current user
   = self.data[:accounts].first
  user_id = self.data[:users].first

  job = {
    "accountid"     => ,
    "userid"        => user_id,
    "cmd"           => "com.cloud.api.commands.DetachVolumeCmd",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     =>
      {"volume"     => volume}
  }

  self.data[:jobs][job_id]= job

  {
    "detachvolumeresponse" => {
      "jobid" => job_id
    }
  }
end

#disassociate_ip_address(*args) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/fog/cloudstack/requests/compute/disassociate_ip_address.rb', line 23

def disassociate_ip_address(*args)
  public_ip_address_id = options['id']
  if self.data[:public_ip_addresses][public_ip_address_id]
    self.data[:public_ip_addresses].delete(public_ip_address_id)
    { "disassociateipaddressresponse" => { "success" => "true" }}
  end
end

#extract_template(options = {}) ⇒ Object



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

def extract_template(options={})
  Fog.credentials[:cloudstack_zone_id] = 1105

  template_id = options['id']
  template_mode = options['mode']

  zoneid = self.data[:zones].keys[0]
  zone = self.data[:zones][zoneid]

  template = {}
  template['id'] = template_id
  template['name'] = "test template"
  template['extractId'] = 1
  template['accountid'] = 1
  template['state'] = "DOWNLOAD_URL_CREATED"
  template['zoneid'] = zoneid
  template['zonename'] = self.data[:zones][zoneid]["name"]
  template['extractMode'] = template_mode
  template['url'] = "http:%2F%2Fexample.com"

  job_id = 1
  job = {
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     => { "template" => template }
  }

  self.data[:jobs][job_id] = job
  {
    "extracttemplateresponse" => {
      "jobid" => job_id
    }
  }
end

#list_async_jobs(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/cloudstack/requests/compute/list_async_jobs.rb', line 22

def list_async_jobs(options={})
  # FIXME: support paging
  jobs = self.data[:jobs]
  {
    'listasyncjobsresponse' => {
      'count' => jobs.size,
      'asyncjobs' => jobs
    }
  }
end

#list_disk_offerings(options = {}) ⇒ Object

TODO: add id, name filters and paging params



23
24
25
26
# File 'lib/fog/cloudstack/requests/compute/list_disk_offerings.rb', line 23

def list_disk_offerings(options={})
  disk_offerings = self.data[:disk_offerings]
  { "listdiskofferingsresponse" => { "count"=> disk_offerings.count, "diskoffering"=> disk_offerings.values } }
end

#list_egress_firewall_rules(*arg) ⇒ Object



26
27
28
29
# File 'lib/fog/cloudstack/requests/compute/list_egress_firewall_rules.rb', line 26

def list_egress_firewall_rules(*arg)
  firewall_rules = self.data[:egress_firewall_rules]
  { "listegressfirewallrulesresponse" => { "count"=> firewall_rules.count, "firewallrule"=> firewall_rules.values } }
end

#list_firewall_rules(*arg) ⇒ Object



26
27
28
29
# File 'lib/fog/cloudstack/requests/compute/list_firewall_rules.rb', line 26

def list_firewall_rules(*arg)
  firewall_rules = self.data[:firewall_rules]
  { "listfirewallrulesresponse" => { "count"=> firewall_rules.count, "firewallrule"=> firewall_rules.values } }
end

#list_network_offerings(*arg) ⇒ Object



22
23
24
25
# File 'lib/fog/cloudstack/requests/compute/list_network_offerings.rb', line 22

def list_network_offerings(*arg)
  network_offerings = self.data[:network_offerings]
  { "listnetworkofferingsresponse" => { "count"=> network_offerings.count, "networkoffering"=> network_offerings.values } }
end

#list_os_types(options = {}) ⇒ Object

TODO: add id, category_id filters and paging params



23
24
25
26
# File 'lib/fog/cloudstack/requests/compute/list_os_types.rb', line 23

def list_os_types(options={})
  os_types = self.data[:os_types]
  { "listostypesresponse" => { "count"=> os_types.count, "ostype"=> os_types.values } }
end

#list_port_forwarding_rules(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/fog/cloudstack/requests/compute/list_port_forwarding_rules.rb', line 26

def list_port_forwarding_rules(*args)
  port_forwarding_rules = self.data[:port_forwarding_rules]
  {
    'listportforwardingrulesresponse' => {
      'count' => port_forwarding_rules.size,
      'portforwardingrule' => port_forwarding_rules.values
    }
  }
end

#list_public_ip_addresses(*arg) ⇒ Object



26
27
28
29
# File 'lib/fog/cloudstack/requests/compute/list_public_ip_addresses.rb', line 26

def list_public_ip_addresses(*arg)
  public_ip_addresses = self.data[:public_ip_addresses]
  { "listpublicipaddressesresponse" => { "count"=> public_ip_addresses.count, "publicipaddress"=> public_ip_addresses.values } }
end

#list_security_groups(options = {}) ⇒ Object



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

def list_security_groups(options={})
  security_groups = []
  if security_group_id = options['id']
    security_group = self.data[:security_groups][security_group_id]
    raise Fog::Compute::Cloudstack::BadRequest unless security_group
    security_groups = [security_group]
  else
    security_groups = self.data[:security_groups].values
  end

  {
    "listsecuritygroupsresponse" =>
    {
      "count"         => security_groups.size,
      "securitygroup" => security_groups
    }
  }
end

#list_service_offerings(options = {}) ⇒ Object



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

def list_service_offerings(options={})
  id = options['id']
  if id && self.data[:flavors][id].nil?
    # received 'id' filter for element that does not exist
    response = { "listserviceofferingsresponse" => { "count" => 0, "serviceoffering" => []}}
  elsif self.data[:flavors][id]
    # received 'id' filter for a specific element
    flavors =  { id => self.data[:flavors][id] }
    response = { "listserviceofferingsresponse" => { "count" => flavors.size, "serviceoffering"=> flavors.values}}
  else
    # no filter specified
    flavors = self.data[:flavors]
    response = { "listserviceofferingsresponse" => { "count" => flavors.size, "serviceoffering"=> flavors.values}}
  end

  return response
end

#list_snapshots(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/cloudstack/requests/compute/list_snapshots.rb', line 24

def list_snapshots(options={})
  snapshot_id = options.delete('id')
  if snapshot_id
    snapshots = [self.data[:snapshots][snapshot_id]]
  else
    snapshots = self.data[:snapshots].values
  end

  {
    'listsnapshotsresponse' => {
      'count' => snapshots.size,
      'snapshot' => snapshots
    }
  }
end

#list_templates(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fog/cloudstack/requests/compute/list_templates.rb', line 27

def list_templates(options={})
  templates = self.data[:images].values

  {
    "listtemplatesresponse" =>
      {
        "count" => templates.size,
        "template"=> templates
      }
  }
end

#list_virtual_machines(options = {}) ⇒ Object



24
25
26
27
# File 'lib/fog/cloudstack/requests/compute/list_virtual_machines.rb', line 24

def list_virtual_machines(options={})
  {"listvirtualmachinesresponse" =>
    {"count" => self.data[:servers].values.size, "virtualmachine" => self.data[:servers].values}}
end

#list_volumes(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/cloudstack/requests/compute/list_volumes.rb', line 24

def list_volumes(options={})
  volume_id = options.delete('id')
  if volume_id
    volumes = [self.data[:volumes][volume_id]]
  else
    volumes = self.data[:volumes].values
  end

  {
    'listvolumesresponse' => {
      'count' => volumes.size,
      'volume' => volumes
    }
  }
end

#list_zones(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/cloudstack/requests/compute/list_zones.rb', line 22

def list_zones(options={})
  zones = self.data[:zones].values

  {
    "listzonesresponse"=>
    {
      "count" => zones.size,
      "zone" => zones
    }
  }
end

#query_async_job_result(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/cloudstack/requests/compute/query_async_job_result.rb', line 23

def query_async_job_result(options={})
  unless job_id = options['jobid']
    raise Fog::Compute::Cloudstack::BadRequest.new("Missing required parameter jobid")
  end

  unless job = self.data[:jobs][job_id]
    raise Fog::Compute::Cloudstack::BadRequest.new("Unknown job id #{job_id}")
  end

  {'queryasyncjobresultresponse' => job }
end

#reboot_virtual_machine(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/fog/cloudstack/requests/compute/reboot_virtual_machine.rb', line 23

def reboot_virtual_machine(options={})
  job_id = Fog::Cloudstack.uuid
  {
    "rebootvirtualmachineresponse" => {
      "jobid" => job_id
    }
  }
end

#register_template(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/cloudstack/requests/compute/register_template.rb', line 29

def register_template(options={})
  mock_template_id = self.data[:images].keys.first
  registered_template = self.data[:images][mock_template_id]

  {
      'registertemplateresponse' =>
      {
          'count' => 1,
          'template' => [registered_template]
      }
  }
end

#reset_dataObject



989
990
991
# File 'lib/fog/cloudstack/compute.rb', line 989

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

#revoke_security_group_egress(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/cloudstack/requests/compute/revoke_security_group_egress.rb', line 23

def revoke_security_group_egress(options={})
  unless security_group_rule_id = options['id']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter id')
  end

  security_group = self.data[:security_groups].values.find do |group|
    (rule = (group['egressrule'] || []).find{|r| r['ruleid'] == security_group_rule_id}) && group['egressrule'].delete(rule)
  end

  job_id = Fog::Cloudstack.uuid
  job = {
    "cmd"           => "com.cloud.api.commands.revokeSecurityGroupEgress",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     => { "securitygroup" => security_group }
  }

  self.data[:jobs][job_id]= job

  {"revokesecuritygroupegress" => { "jobid" => job_id }}
end

#revoke_security_group_ingress(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/cloudstack/requests/compute/revoke_security_group_ingress.rb', line 23

def revoke_security_group_ingress(options={})
  unless security_group_rule_id = options['id']
    raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command missing parameter id')
  end

  security_group = self.data[:security_groups].values.find do |group|
    (rule = (group['ingressrule'] || []).find{|r| r['ruleid'] == security_group_rule_id}) && group['ingressrule'].delete(rule)
  end

  job_id = Fog::Cloudstack.uuid
  job = {
    "cmd"           => "com.cloud.api.commands.revokeSecurityGroupIngress",
    "created"       => Time.now.iso8601,
    "jobid"         => job_id,
    "jobstatus"     => 1,
    "jobprocstatus" => 0,
    "jobresultcode" => 0,
    "jobresulttype" => "object",
    "jobresult"     => { "securitygroup" => security_group }
  }

  self.data[:jobs][job_id]= job

  {"revokesecuritygroupingress" => { "jobid" => job_id }}
end