chef-provisioning-opennebula 0.4.4 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +273 -4
  3. data/lib/chef/provider/one_flow_service.rb +346 -0
  4. data/lib/chef/provider/one_flow_template.rb +175 -0
  5. data/lib/chef/provider/one_image.rb +6 -6
  6. data/lib/chef/provider/one_template.rb +4 -6
  7. data/lib/chef/provider/one_user.rb +11 -14
  8. data/lib/chef/provider/one_vnet.rb +6 -9
  9. data/lib/chef/provider/one_vnet_lease.rb +3 -3
  10. data/lib/chef/provisioning/driver_init/opennebula.rb +1 -1
  11. data/lib/chef/provisioning/driver_init/server_version.rb +28 -0
  12. data/lib/chef/provisioning/opennebula_driver.rb +1 -1
  13. data/lib/chef/provisioning/opennebula_driver/credentials.rb +2 -2
  14. data/lib/chef/provisioning/opennebula_driver/driver.rb +132 -34
  15. data/lib/chef/provisioning/opennebula_driver/flow_lib.rb +491 -0
  16. data/lib/chef/provisioning/opennebula_driver/one_lib.rb +39 -49
  17. data/lib/chef/provisioning/opennebula_driver/resources.rb +2 -2
  18. data/lib/chef/provisioning/opennebula_driver/version.rb +2 -2
  19. data/lib/chef/resource/one_flow_service.rb +61 -0
  20. data/lib/chef/resource/one_flow_template.rb +53 -0
  21. data/lib/chef/resource/one_image.rb +2 -2
  22. data/lib/chef/resource/one_template.rb +1 -1
  23. data/lib/chef/resource/one_user.rb +1 -1
  24. data/lib/chef/resource/one_vnet.rb +2 -2
  25. data/lib/chef/resource/one_vnet_lease.rb +1 -1
  26. data/spec/config_sample.rb +12 -3
  27. data/spec/integration/test_all_integration_spec.rb +6 -272
  28. data/spec/integration/test_one_driver.rb +177 -0
  29. data/spec/integration/test_one_flow.rb +546 -0
  30. data/spec/recipes/OneDriver/{instantiate_one_template_spec.rb → allocate_change_profile.rb} +5 -7
  31. data/spec/recipes/OneDriver/{converge_back_two_vm_spec.rb → attach_one_image.rb} +4 -5
  32. data/spec/recipes/OneDriver/create_one_image.rb +20 -0
  33. data/spec/recipes/OneDriver/{create_one_template_int_spec.rb → create_one_template_ints.rb} +21 -4
  34. data/spec/recipes/OneDriver/create_one_template_mix.rb +51 -0
  35. data/spec/recipes/OneDriver/{create_one_image_spec.rb → create_one_template_strings.rb} +18 -7
  36. data/spec/recipes/OneDriver/{converge_back_one_vm_spec.rb → create_one_vnet.rb} +5 -5
  37. data/spec/recipes/OneDriver/delete/{OpenNebula-tpl-1-vm.rb → OpenNebula-test-img.rb} +2 -4
  38. data/spec/recipes/OneDriver/delete/{OpenNebula-back-1-vm.rb → OpenNebula-test-snap-img.rb} +2 -4
  39. data/spec/recipes/OneDriver/delete/OpenNebula-test-tpl-ints.rb +2 -4
  40. data/spec/recipes/OneDriver/delete/{OpenNebula-test-tpl.rb → OpenNebula-test-tpl-mix.rb} +2 -4
  41. data/spec/recipes/OneDriver/delete/OpenNebula-test-tpl-strings.rb +17 -0
  42. data/spec/recipes/OneDriver/delete/{OpenNebula-back-2-vm.rb → OpenNebula-test-vm-vnet.rb} +2 -4
  43. data/spec/recipes/OneDriver/delete/{OpenNebula-bootstrap-vm.rb → OpenNebula-test-vm.rb} +2 -4
  44. data/spec/recipes/OneDriver/delete/OpenNebula-test-vnet.rb +17 -0
  45. data/spec/recipes/OneDriver/{attach_back_one_vm_spec.rb → instantiate_one_template.rb} +7 -6
  46. data/spec/recipes/OneDriver/{converge_bootstrap_vm_spec.rb → instantiate_one_template_vnet.rb} +10 -8
  47. data/spec/recipes/OneDriver/snapshot_one_image.rb +19 -0
  48. data/spec/recipes/OneFlowService/action/boot.rb +19 -0
  49. data/spec/recipes/OneFlowService/action/delete.rb +18 -0
  50. data/spec/recipes/OneFlowService/action/delete_recreate.rb +18 -0
  51. data/spec/recipes/OneFlowService/action/hold.rb +19 -0
  52. data/spec/recipes/OneFlowService/action/poweroff.rb +18 -0
  53. data/spec/recipes/OneFlowService/action/poweroff_hard.rb +18 -0
  54. data/spec/recipes/OneFlowService/action/reboot.rb +18 -0
  55. data/spec/recipes/OneFlowService/action/reboot_hard.rb +18 -0
  56. data/spec/recipes/OneFlowService/action/release.rb +19 -0
  57. data/spec/recipes/OneFlowService/action/resume.rb +18 -0
  58. data/spec/recipes/OneFlowService/action/scale.rb +19 -0
  59. data/spec/recipes/OneFlowService/action/shutdown.rb +18 -0
  60. data/spec/recipes/OneFlowService/action/shutdown_hard.rb +18 -0
  61. data/spec/recipes/OneFlowService/action/shutdown_service.rb +17 -0
  62. data/spec/recipes/OneFlowService/action/snapshot_create.rb +18 -0
  63. data/spec/recipes/OneFlowService/action/stop.rb +18 -0
  64. data/spec/recipes/OneFlowService/action/suspend.rb +18 -0
  65. data/spec/recipes/OneFlowService/action/undeploy.rb +18 -0
  66. data/spec/recipes/OneFlowService/action/undeploy_hard.rb +18 -0
  67. data/spec/recipes/OneFlowService/chmod_simple_by_name.rb +19 -0
  68. data/spec/recipes/OneFlowService/chmod_simple_by_name_2.rb +18 -0
  69. data/spec/recipes/OneFlowService/chmod_tpl_opts.rb +31 -0
  70. data/spec/recipes/OneFlowService/delete/test_instance_template_options.rb +17 -0
  71. data/spec/recipes/OneFlowService/delete/test_role_action.rb +17 -0
  72. data/spec/recipes/OneFlowService/delete/test_simple_instance.rb +17 -0
  73. data/spec/recipes/OneFlowService/delete/test_simple_instance_by_id.rb +17 -0
  74. data/spec/recipes/{OneDriver/create_bootstrap_vm_spec.rb → OneFlowService/instance_role_action.rb} +19 -11
  75. data/spec/recipes/OneFlowService/instance_simple_by_id.rb +20 -0
  76. data/spec/recipes/OneFlowService/instance_simple_by_name.rb +18 -0
  77. data/spec/recipes/OneFlowService/instance_tpl_opts.rb +30 -0
  78. data/spec/recipes/OneFlowTemplate/chmod_simple_from_hash.rb +17 -0
  79. data/spec/recipes/OneFlowTemplate/chmod_update_simple_from_file.rb +19 -0
  80. data/spec/recipes/OneFlowTemplate/create_branch_from_one_id.rb +43 -0
  81. data/spec/recipes/OneFlowTemplate/create_branch_from_one_name.rb +20 -0
  82. data/spec/recipes/OneFlowTemplate/create_role_action_instance.rb +99 -0
  83. data/spec/recipes/OneFlowTemplate/create_simple_from_file.rb +18 -0
  84. data/spec/recipes/{OneDriver/attach_back_two_vm_spec.rb → OneFlowTemplate/create_simple_from_hash.rb} +8 -6
  85. data/spec/recipes/OneFlowTemplate/create_simple_from_web.rb +17 -0
  86. data/spec/recipes/{OneDriver/attach_one_image_spec.rb → OneFlowTemplate/create_simple_instance_tpl.rb} +8 -6
  87. data/spec/recipes/OneFlowTemplate/create_tpl_opts_from_file.rb +30 -0
  88. data/spec/recipes/OneFlowTemplate/create_tpl_opts_from_hash.rb +35 -0
  89. data/spec/recipes/OneFlowTemplate/delete/branch_from_one_id.rb +17 -0
  90. data/spec/recipes/OneFlowTemplate/delete/branch_from_one_name.rb +17 -0
  91. data/spec/recipes/OneFlowTemplate/delete/role_action_instance.rb +17 -0
  92. data/spec/recipes/OneFlowTemplate/delete/simple_from_file.rb +17 -0
  93. data/spec/recipes/OneFlowTemplate/delete/simple_from_hash.rb +17 -0
  94. data/spec/recipes/OneFlowTemplate/delete/simple_from_web.rb +17 -0
  95. data/spec/recipes/OneFlowTemplate/delete/simple_instance_tpl.rb +17 -0
  96. data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_file.rb +17 -0
  97. data/spec/recipes/OneFlowTemplate/delete/tpl_opts_from_hash.rb +17 -0
  98. data/spec/recipes/OneFlowTemplate/update_simple_from_hash.rb +57 -0
  99. data/spec/recipes/{driver_options_spec.rb → common.rb} +9 -3
  100. data/spec/spec_helper.rb +22 -17
  101. data/spec/support/opennebula_support.rb +75 -45
  102. metadata +114 -27
  103. data/spec/recipes/OneDriver/create_back_one_vm_spec.rb +0 -20
  104. data/spec/recipes/OneDriver/create_back_two_vm_spec.rb +0 -20
  105. data/spec/recipes/OneDriver/create_one_template_spec.rb +0 -21
  106. data/spec/recipes/OneDriver/delete/OpenNebula-bootstrap-img.rb +0 -19
  107. data/spec/recipes/OneDriver/delete/OpenNebula-snap-1-img.rb +0 -19
  108. data/spec/recipes/OneDriver/delete/OpenNebula-snap-2-img.rb +0 -19
  109. data/spec/recipes/OneDriver/snapshot_one_image_spec.rb +0 -21
  110. data/spec/recipes/OneDriver/snapshot_two_image_spec.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f967f28103c43f8a53e87e54eddd0de8fd1f9af1
4
- data.tar.gz: cbb861a93ed158a967a661937c9ac3576ad9c66a
3
+ metadata.gz: be70c3a2ff409635c15cdb3983c4947e526b1af4
4
+ data.tar.gz: f0d93e05af640ebc8672f0ad9ed7cf83d5f41a94
5
5
  SHA512:
6
- metadata.gz: 0d755e26ff9c70c4b08615f051d25747d0f9268bf9c14cd2ef62261161a63d759e65d44045a9ec52ee373fd0ed2cb0c39d1eef54fa382570f94d6e205387df94
7
- data.tar.gz: 4eeb678cf8030a172988142c77ec676ad9ebfc3944a548069f29c6c59398caaf9d7a0b8ca2a0955b00610e82734d6056045afb428dc4f22d217d8798d7573891
6
+ metadata.gz: 432068196cae2b47b31b434588493dba50f99972d4d06004ca6ffd0dc60c54b448b7ef6ee049951c87833a451259ed9bd3b4ea4806beca28185a2c4bb2d885bf
7
+ data.tar.gz: 957716c65b152719733f36643b1629b511c392f28e9c4459dec66eb5a8041708c7c4a1c958dacae2835e1f9f4e4199e88840d43be2207d8d2c360446653b6703
data/README.md CHANGED
@@ -7,6 +7,7 @@ This is the implementation of the OpenNebula driver for chef-provisioning. It a
7
7
  * Image (one_image)
8
8
  * VNET (one_vnet)
9
9
  * Lease (one_vnet_lease)
10
+ * OneFlow (one_flow_template & one_flow_service)
10
11
 
11
12
  Setup
12
13
  -----
@@ -45,6 +46,14 @@ A sample one_config file would look like this:
45
46
  }
46
47
  ```
47
48
 
49
+ To use OneFlow, you also need to specify a ```with_flow_url``` directive. This is the API endpoint of your OneFlow.
50
+
51
+ Example:
52
+
53
+ ```ruby
54
+ with_flow_url "http://gary.1.2.3.4:9876"
55
+ ```
56
+
48
57
  In context of OpenNebula ```machine``` resource will take the following additional options:
49
58
 
50
59
  ```ruby
@@ -89,7 +98,7 @@ Resources
89
98
 
90
99
  ## one_template
91
100
 
92
- This resource will allow to create and delete OpenNebula templates.
101
+ This resource will allow you to create and delete OpenNebula templates.
93
102
 
94
103
  ### Attributes
95
104
 
@@ -332,7 +341,7 @@ This resource will allow to create and delete OpenNebula vnets.
332
341
 
333
342
  ### Examples
334
343
 
335
- #### 1. Reserver vnet 'boggi_vnet' from parent vnet 12345 with default size 1
344
+ #### 1. Reserve vnet 'boggi_vnet' from parent vnet 12345 with default size 1
336
345
 
337
346
  ```ruby
338
347
  one_vnet "boggi_vnet" do
@@ -341,7 +350,7 @@ one_vnet "boggi_vnet" do
341
350
  end
342
351
  ```
343
352
 
344
- #### 2. Reserver vnet 'boggi_vnet' from parent vnet 12345 with size 100
353
+ #### 2. Reserve vnet 'boggi_vnet' from parent vnet 12345 with size 100
345
354
 
346
355
  ```ruby
347
356
  one_vnet "boggi_vnet" do
@@ -478,10 +487,270 @@ one_user "boggi" do
478
487
  end
479
488
  ```
480
489
 
490
+ ## one_flow_template
491
+
492
+ This resource will allow you to create, delete, and instantiate OneFlow templates.
493
+
494
+ ### Attributes
495
+
496
+ ```ruby
497
+ :name => String name of the OneFlow template you are targeting, default is what you put between 'one_flow_template' and 'do'
498
+ :template => Hash defining your OneFlow template, or Fixnum ID of a OneFlow template from ONE, or String file location denoted by file://my_template.json or web location denoted by http(s)://1.2.3.4/my_template.json
499
+ :template_options => Hash that override-merges into template
500
+ :mode => String octet to set permissions, default is '600'
501
+ ```
502
+
503
+ ### Actions
504
+
505
+ ```ruby
506
+ actions :create, :delete
507
+ default_action :create
508
+ ```
509
+
510
+ ### Examples
511
+
512
+ #### 1. Create OneFlow template from file with mode 640
513
+
514
+ ```ruby
515
+ one_flow_template "garys_flow_template" do
516
+ template "file:///opt/one/flow_templates/my_template.tpl"
517
+ mode '640'
518
+ action :create
519
+ end
520
+ ```
521
+ **Note:** If 'name' is not specified in the template file, the template will be named 'garys_flow_template'
522
+ If you want to get it from a url, you can do any of the following:
523
+ ```ruby
524
+ template "http://1.2.3.4/my_template.tpl"
525
+ template "gary@https://1.2.3.4/my_template.tpl"
526
+ template "gary:password@https://1.2.3.4/my_template.tpl"
527
+ ```
528
+
529
+ #### 2. Create OneFlow template from hash
530
+
531
+ ```ruby
532
+ one_flow_template "I can write anything I want here" do
533
+ template :name => "garys_flow_template",
534
+ :description => "This is my description.",
535
+ :shutdown_action => "shutdown-hard",
536
+ :deployment => "straight",
537
+ :ready_status_gate => true,
538
+ :roles => [
539
+ {
540
+ :vm_template => 1398, # OR :vm_template => 'name_of_vm_template',
541
+ :scheduled_policies => [
542
+ {
543
+ :type => "CHANGE",
544
+ :adjust => 1,
545
+ :start_time => "0 3 1-10 * *"
546
+ },
547
+ {
548
+ :type => "CARDINALITY",
549
+ :recurrence => "0 4 1-10 * *",
550
+ :adjust => 2
551
+ },
552
+ {
553
+ :type => "PERCENTAGE_CHANGE",
554
+ :recurrence => "0 1 1-10 * *",
555
+ :adjust => 3,
556
+ :min_adjust_step => 14
557
+ }
558
+ ],
559
+ :max_vms => 4,
560
+ :cooldown => 15,
561
+ :elasticity_policies => [
562
+ {
563
+ :type => "CHANGE",
564
+ :cooldown => 17,
565
+ :period => 15,
566
+ :adjust => 2,
567
+ :period_number => 2,
568
+ :expression => "ATT == 20"
569
+ },
570
+ {
571
+ :type => "CARDINALITY",
572
+ :cooldown => 14,
573
+ :period => 13,
574
+ :adjust => 3,
575
+ :period_number => 1,
576
+ :expression => "ATT > 20"
577
+ },
578
+ {
579
+ :type => "PERCENTAGE_CHANGE",
580
+ :cooldown => 13,
581
+ :period => 12,
582
+ :adjust => 1,
583
+ :period_number => 3,
584
+ :expression => "ATT < 20",
585
+ :min_adjust_step => 13
586
+ }
587
+ ],
588
+ :cardinality => 3,
589
+ :shutdown_action => "shutdown",
590
+ :name => "gary_role_1",
591
+ :vm_template_contents => "NIC=[NETWORK_ID=\"$NetConfg1\"]\nNIC=[NETWORK_ID=\"$NetConfg2\"]\n",
592
+ :min_vms => 2
593
+ }
594
+ ],
595
+ :custom_attrs => {
596
+ :NetConfg2 => "M|vnet_id|another description",
597
+ :NetConfg1 => "M|vnet_id|description for net confg 1"
598
+ }
599
+ action :create
600
+ end
601
+ ```
602
+ **Note:** This is a template with (nearly) all fields filled out. By no means should you use this template, all the values were entered randomly.
603
+ Notice that I specified 'name' in my hash. As for vm_template, you can either put the name of a VM template or put its ID. Using ID will be faster.
604
+ See here for more info: http://docs.opennebula.org/4.14/integration/system_interfaces/appflow_api.html#examples
605
+
606
+ #### 3. Update OneFlow template from hash (overwrite-merge)
607
+
608
+ ```ruby
609
+ one_flow_template "garys_flow_template" do
610
+ template :deployment => nil, # setting any value to nil will reset it back to default
611
+ :roles => [
612
+ {
613
+ :name => 'delete_this_role',
614
+ :delete_role => nil # specifying this will delete this role
615
+ },
616
+ {
617
+ :name => 'new_role', # assuming new_role does not exist, creates a new role
618
+ :vm_template => 'gary-ubuntu-14.04',
619
+ :cooldown => 8
620
+ },
621
+ {
622
+ :name => 'existing_role', # assuming existing_role exists, updates cooldown to 88 seconds
623
+ :vm_template => 'gary-ubuntu-14.04',
624
+ :cooldown => 88
625
+ }
626
+ ]
627
+ action :update
628
+ end
629
+ ```
630
+
631
+ #### 4. Delete a OneFlow template
632
+
633
+ ```ruby
634
+ one_flow_template "garys_flow_template" do
635
+ action :delete
636
+ end
637
+ ```
638
+
639
+ #### 5. Change the permissions of a OneFlow template
640
+
641
+ ```ruby
642
+ one_flow_template "garys_flow_template" do
643
+ mode '640'
644
+ action :create
645
+ end
646
+ ```
647
+
648
+ ## one_flow_service
649
+
650
+ This resource will allow you to create, delete, and instantiate OneFlow templates.
651
+
652
+ ### Attributes
653
+
654
+ ```ruby
655
+ :name => String name of the OneFlow service you are targeting, default is what you put between 'one_flow_service' and 'do'
656
+ :template => String name or Fixnum ID of the template you want to instantiate
657
+ :template_options => Hash that override-merges into template
658
+ :mode => String octet to set permissions, default is '600'
659
+ :role => String name of the role of a service you are targeting
660
+ :period => Integer seconds between each group of actions
661
+ :number => Integer number of VMs to apply the action to each period
662
+ :cardinality => Integer number of VMs to deploy
663
+ :force_scale => Boolean that allows scaling to cardinality above or below templated range
664
+ :override_failsafe => Boolean that allows the user to ignore aborts due to untested / partionally implemented code and execute the action anyways, default false
665
+ ```
666
+ **More on override_failsafe:** This only affects the actions :hold, :release, and :boot. The reason for this is because I was unable to figure out how to get the my VMs in a state that allows the running of these actions. As such, I was unable to test these actions.
667
+ Here is the warning you will receive:
668
+ ```ruby
669
+ Chef::Log.warn('You have chose to use an action that is untested / partially implemented.')
670
+ Chef::Log.warn('Specifically, the driver will send the appropriate POST request to the Flow API')
671
+ Chef::Log.warn('But the driver will not verify that the action ran successfully, or ran at all.')
672
+ Chef::Log.warn('Moreover, the driver will not wait for the action complete, as in, the action will')
673
+ Chef::Log.warn('run asynchronously, meaning dependent actions after this one may fail.')
674
+ Chef::Log.warn('Use at your own risk. Please report any issues.')
675
+ ```
676
+
677
+ ### Actions
678
+
679
+ ```ruby
680
+ actions :instantiate, :recover, :delete, :shutdown,
681
+ :scale, :shutdown_hard, :undeploy, :undeploy_hard,
682
+ :hold, :release, :stop, :suspend, :resume, :boot,
683
+ :delete_recreate, :reboot, :reboot_hard, :poweroff,
684
+ :poweroff_hard, :snapshot_create
685
+ default_action :instantiate
686
+ ```
687
+
688
+ ### Examples
689
+
690
+ #### 1. Instantiate a service from template
691
+
692
+ ```ruby
693
+ one_flow_service "gary_service" do
694
+ template garys_flow_template # or ID, eg. template 555
695
+ template_options :roles => [
696
+ {
697
+ :name => 'random_role',
698
+ :vm_template => 'gary-ubuntu-14.04',
699
+ :cooldown => 10
700
+ }
701
+ ]
702
+ mode '640'
703
+ action :instantiate
704
+ end
705
+ ```
706
+
707
+ #### 2. Recover a service (or delete / shutdown)
708
+
709
+ ```ruby
710
+ one_flow_service "gary_service" do
711
+ action :recover # or :delete / :shutdown
712
+ end
713
+ ```
714
+
715
+ #### 3. Change permissions of a service
716
+
717
+ ```ruby
718
+ one_flow_service "I can write anything I want here" do
719
+ name "gary_service"
720
+ mode "640"
721
+ action :instantiate
722
+ end
723
+ ```
724
+
725
+ #### 4. Scale a role of a service to have 3 VMs regardless of the min/max VM setting
726
+
727
+ ```ruby
728
+ one_flow_service "gary_service" do
729
+ cardinality 3
730
+ force_scale true # optional, default = false
731
+ role "gary_role"
732
+ action :scale
733
+ end
734
+ ```
735
+
736
+ #### 5. Perform a hard poweroff of a role
737
+
738
+ ```ruby
739
+ one_flow_service "gary_service" do
740
+ role "gary_role"
741
+ period 3 # optional
742
+ number 5 # optional
743
+ action :poweroff_hard
744
+ end
745
+ ```
746
+ **Note:** All actions listed above except for :recover can be performed in the same manner.
747
+
481
748
  ## Rspec Integration tests
482
749
 
483
750
  - Create and configure `spec/config.rb` from `spec/config_sample.rb`, be sure to **read the comments**
484
- - Run `bundle exec rspec ./spec/integration/test_all_integration_spec.rb` from your chef-provisioning-opennebula folder
751
+ - From your chef-provisioning-opennebula folder, run:
752
+ - `bundle install`
753
+ - `rspec ./spec/integration/test_all_integration_spec.rb`
485
754
 
486
755
  ## <a name="development"></a> Development
487
756
 
@@ -0,0 +1,346 @@
1
+ # Copyright 2016, BlackBerry Limited
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'chef/provisioning/opennebula_driver/flow_lib'
16
+ require 'set'
17
+
18
+ #
19
+ # Implementation of Provider class.
20
+ #
21
+ class Chef
22
+ #
23
+ # Implementation of Provider class.
24
+ #
25
+ class Provider
26
+ #
27
+ # Implementation of Provider class.
28
+ #
29
+ class OneFlowService < Chef::Provider::LWRPBase
30
+ use_inline_resources
31
+
32
+ provides :one_flow_service
33
+
34
+ def initialize(*args)
35
+ super
36
+ if !@new_resource.flow_url.nil?
37
+ flow_url = @new_resource.flow_url
38
+ elsif !run_context.chef_provisioning.flow_url.nil?
39
+ flow_url = run_context.chef_provisioning.flow_url
40
+ elsif !ENV['ONE_FLOW_URL'].nil?
41
+ flow_url = ENV['ONE_FLOW_URL']
42
+ else
43
+ fail 'OneFlow API URL must be specified.'
44
+ end
45
+ @flow_lib = Chef::Provisioning::OpenNebulaDriver::FlowLib.new(flow_url, driver.one.client.one_auth)
46
+ end
47
+
48
+ def whyrun_supported?
49
+ true
50
+ end
51
+
52
+ def load_current_resource
53
+ @current_resource = Chef::Resource::OneFlowService.new(@new_resource.name, run_context)
54
+ service_id = @flow_lib.get_unique_service_id(@new_resource.name, true)
55
+
56
+ @current_resource.exists = !service_id.nil?
57
+ return unless @current_resource.exists
58
+
59
+ if @new_resource.template.nil?
60
+ @current_resource.template_equal = true
61
+ else
62
+ one_tpl_id = @new_resource.template.is_a?(Fixnum) ? @new_resource.template : @flow_lib.get_unique_template_id(@new_resource.template)
63
+ new_service_template = @flow_lib.get_template(one_tpl_id)
64
+ new_service_template = @flow_lib.normalize_template(@new_resource.name, driver, @flow_lib.merge_template(new_service_template, @new_resource.template_options, true))
65
+ new_service_template.delete(:name)
66
+ new_service_template[:roles].each { |role| [:cardinality, :vm_template_contents].each { |key| role.delete(key) } }
67
+ current_service_template = @flow_lib.get_reduced_service_template(service_id)
68
+ @current_resource.template_equal = @flow_lib.hash_eq?(new_service_template, current_service_template)
69
+ end
70
+
71
+ @current_resource.mode(@flow_lib.get_service_permissions(service_id))
72
+ @current_resource.mode_equal = @new_resource.mode == @current_resource.mode
73
+
74
+ @current_resource.in_running_state = @flow_lib.get_service_state(service_id) == @flow_lib.class::SERVICE_RUNNING
75
+
76
+ @current_resource.equal = @current_resource.template_equal && @current_resource.mode_equal && @current_resource.in_running_state
77
+ end
78
+
79
+ action :instantiate do
80
+ if @current_resource.exists
81
+ # recover and/or chmod
82
+ unless @current_resource.equal
83
+ service_id = @flow_lib.get_unique_service_id(@new_resource.name)
84
+ converge_by "updated service '#{@new_resource.name}'" do
85
+ unless @current_resource.in_running_state
86
+ @flow_lib.recover_service(service_id, @new_resource.name)
87
+ end
88
+ unless @current_resource.mode_equal
89
+ @flow_lib.chmod_service(service_id, @new_resource.mode)
90
+ end
91
+ @new_resource.updated_by_last_action(true)
92
+ end
93
+ end
94
+ else
95
+ # create and chmod
96
+ fail 'You must specify a Flow template to instantiate' if @new_resource.template.nil?
97
+ one_tpl_id = @new_resource.template.is_a?(Fixnum) ? @new_resource.template : @flow_lib.get_unique_template_id(@new_resource.template)
98
+ new_service_template = @flow_lib.normalize_template(@new_resource.name, driver, @flow_lib.get_template(one_tpl_id))
99
+ new_service_template = @flow_lib.normalize_template(@new_resource.name, driver, @flow_lib.merge_template(new_service_template, @new_resource.template_options, true))
100
+ new_service_template[:name] = @new_resource.name
101
+ converge_by "instantiated service '#{@new_resource.name}'" do
102
+ one_tpl_id = @new_resource.template.is_a?(Fixnum) ? @new_resource.template : @flow_lib.get_unique_template_id(@new_resource.template)
103
+ @flow_lib.instantiate_template(one_tpl_id, new_service_template, @new_resource.name)
104
+ service_id = @flow_lib.get_unique_service_id(@new_resource.name)
105
+ @flow_lib.chmod_service(service_id, @new_resource.mode)
106
+ @new_resource.updated_by_last_action(true)
107
+ end
108
+ end
109
+ end
110
+
111
+ action :recover do
112
+ service_id = @flow_lib.get_unique_service_id(@new_resource.name)
113
+ dont_recover = Set[
114
+ @flow_lib.class::SERVICE_RUNNING,
115
+ @flow_lib.class::SERVICE_DEPLOYING,
116
+ @flow_lib.class::SERVICE_PENDING,
117
+ @flow_lib.class::SERVICE_SCALING
118
+ ].include?(@flow_lib.get_service_state(service_id))
119
+ unless dont_recover
120
+ converge_by "recovered service '#{@new_resource.name}'" do
121
+ @flow_lib.recover_service(service_id, @new_resource.name)
122
+ @new_resource.updated_by_last_action(true)
123
+ end
124
+ end
125
+ end
126
+
127
+ action :delete do
128
+ if @new_resource.role.nil?
129
+ if @current_resource.exists
130
+ service_id = @flow_lib.get_unique_service_id(@new_resource.name, true)
131
+ converge_by "deleted service '#{@new_resource.name}'" do
132
+ @flow_lib.delete_service(service_id)
133
+ @new_resource.updated_by_last_action(true)
134
+ end
135
+ end
136
+ else
137
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
138
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_NO_VMS
139
+ converge_by "deleted role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
140
+ @flow_lib.role_action(sid, @new_resource.role, 'delete', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_NO_VMS)
141
+ @new_resource.updated_by_last_action(true)
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ action :shutdown do
148
+ if @new_resource.role.nil?
149
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
150
+ dont_shutdown = Set[
151
+ @flow_lib.class::SERVICE_DONE,
152
+ @flow_lib.class::SERVICE_UNDEPLOYING,
153
+ @flow_lib.class::SERVICE_FAILED_DEPLOYING
154
+ ].include?(@flow_lib.get_service_state(sid))
155
+ unless dont_shutdown
156
+ converge_by "shutdown service '#{@new_resource.name}'" do
157
+ @flow_lib.shutdown_service(@new_resource.name, sid)
158
+ @new_resource.updated_by_last_action(true)
159
+ end
160
+ end
161
+ else
162
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
163
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_NO_VMS
164
+ converge_by "shutdown role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
165
+ @flow_lib.role_action(sid, @new_resource.role, 'shutdown', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_NO_VMS)
166
+ @new_resource.updated_by_last_action(true)
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ action :scale do
173
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
174
+ fail 'You must specify the attribute cardinality, and cardinality >= 0' if @new_resource.cardinality < 0
175
+
176
+ service_id = @flow_lib.get_unique_service_id(@new_resource.name)
177
+ unless @flow_lib.get_role_cardinality(service_id, @new_resource.role) == @new_resource.cardinality
178
+ converge_by "scaled role '#{@new_resource.role}' of service '#{@new_resource.name}' to cardinality '#{@new_resource.cardinality}'" do
179
+ @flow_lib.role_scale(service_id, @new_resource.name, @new_resource.role, @new_resource.cardinality, @new_resource.force_scale)
180
+ @new_resource.updated_by_last_action(true)
181
+ end
182
+ end
183
+ end
184
+
185
+ action :shutdown_hard do
186
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
187
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
188
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_NO_VMS
189
+ converge_by "performed hard shutdown of role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
190
+ @flow_lib.role_action(sid, @new_resource.role, 'shutdown-hard', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_NO_VMS)
191
+ @new_resource.updated_by_last_action(true)
192
+ end
193
+ end
194
+ end
195
+
196
+ action :undeploy do
197
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
198
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
199
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_UNDEPLOYED
200
+ converge_by "undeployed role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
201
+ @flow_lib.role_action(sid, @new_resource.role, 'undeploy', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_UNDEPLOYED)
202
+ @new_resource.updated_by_last_action(true)
203
+ end
204
+ end
205
+ end
206
+
207
+ action :undeploy_hard do
208
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
209
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
210
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_UNDEPLOYED
211
+ converge_by "hard undeployed role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
212
+ @flow_lib.role_action(sid, @new_resource.role, 'undeploy-hard', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_UNDEPLOYED)
213
+ @new_resource.updated_by_last_action(true)
214
+ end
215
+ end
216
+ end
217
+
218
+ action :hold do
219
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
220
+ @new_resource.override_failsafe ? @flow_lib.override_failsafe_warn : fail('UNTESTED / PARTIALLY IMPLEMENTED')
221
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
222
+ converge_by "held role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
223
+ @flow_lib.role_action(sid, @new_resource.role, 'hold', @new_resource.period.to_s, @new_resource.number.to_s)
224
+ @new_resource.updated_by_last_action(true)
225
+ end
226
+ end
227
+
228
+ action :release do
229
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
230
+ @new_resource.override_failsafe ? @flow_lib.override_failsafe_warn : fail('UNTESTED / PARTIALLY IMPLEMENTED')
231
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
232
+ converge_by "released role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
233
+ @flow_lib.role_action(sid, @new_resource.role, 'release', @new_resource.period.to_s, @new_resource.number.to_s)
234
+ @new_resource.updated_by_last_action(true)
235
+ end
236
+ end
237
+
238
+ action :stop do
239
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
240
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
241
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_STOPPED
242
+ converge_by "stopped role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
243
+ @flow_lib.role_action(sid, @new_resource.role, 'stop', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_STOPPED)
244
+ @new_resource.updated_by_last_action(true)
245
+ end
246
+ end
247
+ end
248
+
249
+ action :suspend do
250
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
251
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
252
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_SUSPENDED
253
+ converge_by "suspended role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
254
+ @flow_lib.role_action(sid, @new_resource.role, 'suspend', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_SUSPENDED)
255
+ @new_resource.updated_by_last_action(true)
256
+ end
257
+ end
258
+ end
259
+
260
+ action :resume do
261
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
262
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
263
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_RUNNING
264
+ converge_by "resumed role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
265
+ @flow_lib.role_action(sid, @new_resource.role, 'resume', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_RUNNING)
266
+ @new_resource.updated_by_last_action(true)
267
+ end
268
+ end
269
+ end
270
+
271
+ action :boot do
272
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
273
+ @new_resource.override_failsafe ? @flow_lib.override_failsafe_warn : fail('UNTESTED / PARTIALLY IMPLEMENTED')
274
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
275
+ converge_by "booted role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
276
+ @flow_lib.role_action(sid, @new_resource.role, 'boot', @new_resource.period.to_s, @new_resource.number.to_s)
277
+ @new_resource.updated_by_last_action(true)
278
+ end
279
+ end
280
+
281
+ action :delete_recreate do
282
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
283
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
284
+ converge_by "deleted and recreated role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
285
+ @flow_lib.role_action(sid, @new_resource.role, 'delete-recreate', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_RUNNING)
286
+ @new_resource.updated_by_last_action(true)
287
+ end
288
+ end
289
+
290
+ action :reboot do
291
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
292
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
293
+ converge_by "rebooted role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
294
+ @flow_lib.role_action(sid, @new_resource.role, 'reboot', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_RUNNING)
295
+ @new_resource.updated_by_last_action(true)
296
+ end
297
+ end
298
+
299
+ action :reboot_hard do
300
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
301
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
302
+ converge_by "hard rebooted role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
303
+ @flow_lib.role_action(sid, @new_resource.role, 'reboot-hard', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_RUNNING)
304
+ @new_resource.updated_by_last_action(true)
305
+ end
306
+ end
307
+
308
+ action :poweroff do
309
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
310
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
311
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_POWEROFF
312
+ converge_by "powered-off role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
313
+ @flow_lib.role_action(sid, @new_resource.role, 'poweroff', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_POWEROFF)
314
+ @new_resource.updated_by_last_action(true)
315
+ end
316
+ end
317
+ end
318
+
319
+ action :poweroff_hard do
320
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
321
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
322
+ unless @flow_lib.get_role_state(sid, @new_resource.role) == @flow_lib.class::ROLE_POWEROFF
323
+ converge_by "hard powered-off role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
324
+ @flow_lib.role_action(sid, @new_resource.role, 'poweroff-hard', @new_resource.period.to_s, @new_resource.number.to_s, @flow_lib.class::ROLE_POWEROFF)
325
+ @new_resource.updated_by_last_action(true)
326
+ end
327
+ end
328
+ end
329
+
330
+ action :snapshot_create do
331
+ fail 'You specified an action that is role specific, but did not provide a role.' if @new_resource.role.nil?
332
+ sid = @flow_lib.get_unique_service_id(@new_resource.name)
333
+ converge_by "created a snapshot for role '#{@new_resource.role}' of service '#{@new_resource.name}'" do
334
+ @flow_lib.role_action(sid, @new_resource.role, 'snapshot-create', @new_resource.period.to_s, @new_resource.number.to_s)
335
+ @new_resource.updated_by_last_action(true)
336
+ end
337
+ end
338
+
339
+ protected
340
+
341
+ def driver
342
+ @new_resource.driver.nil? ? run_context.chef_provisioning.current_driver : run_context.chef_provisioning.driver_for(@new_resource.driver)
343
+ end
344
+ end
345
+ end
346
+ end