lorj 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +46 -0
  4. data/Gemfile +15 -15
  5. data/README.md +22 -17
  6. data/Rakefile +12 -2
  7. data/bin/cloud_test.rb +13 -65
  8. data/example/students_1/process/students.rb +39 -0
  9. data/example/students_1/students.rb +22 -5
  10. data/example/students_2/process/students.rb +48 -0
  11. data/example/students_2/students.rb +39 -16
  12. data/example/students_3/controller/yaml_students.rb +50 -43
  13. data/example/students_3/controller/yaml_students_controller.rb +100 -87
  14. data/example/students_3/process/students.rb +161 -97
  15. data/example/students_3/students.rb +85 -56
  16. data/example/yaml_students/students.rb +40 -40
  17. data/example/yaml_students/yaml_students.rb +103 -90
  18. data/lib/core/core.rb +356 -696
  19. data/lib/core/core_controller.rb +227 -0
  20. data/lib/core/core_internal.rb +339 -0
  21. data/lib/core/core_model.rb +328 -0
  22. data/lib/core/core_object_data.rb +330 -0
  23. data/lib/core/core_object_params.rb +230 -0
  24. data/lib/core/core_process.rb +391 -0
  25. data/lib/core/core_process_setup.rb +353 -0
  26. data/lib/core/core_setup_ask.rb +241 -0
  27. data/lib/core/core_setup_encrypt.rb +146 -0
  28. data/lib/core/core_setup_init.rb +229 -0
  29. data/lib/core/core_setup_list.rb +160 -0
  30. data/lib/core/definition.rb +647 -469
  31. data/lib/core/definition_internal.rb +264 -308
  32. data/lib/core/lorj_basecontroller.rb +95 -0
  33. data/lib/core/lorj_basedefinition.rb +307 -0
  34. data/lib/core/lorj_baseprocess.rb +265 -0
  35. data/lib/core/lorj_data.rb +583 -0
  36. data/lib/core/lorj_keypath.rb +119 -0
  37. data/lib/core_process/cloud/process/common.rb +63 -0
  38. data/lib/core_process/cloud/process/connection.rb +93 -0
  39. data/lib/core_process/cloud/process/external_network.rb +94 -0
  40. data/lib/core_process/cloud/process/flavor.rb +99 -0
  41. data/lib/core_process/cloud/process/images.rb +87 -0
  42. data/lib/core_process/cloud/process/internet_network.rb +34 -0
  43. data/lib/core_process/cloud/process/internet_server.rb +30 -0
  44. data/lib/core_process/cloud/process/keypairs.rb +276 -0
  45. data/lib/core_process/cloud/process/network.rb +108 -0
  46. data/lib/core_process/cloud/process/public_ip.rb +100 -0
  47. data/lib/core_process/cloud/process/router.rb +260 -0
  48. data/lib/core_process/cloud/process/rules.rb +120 -0
  49. data/lib/core_process/cloud/process/security_groups.rb +121 -0
  50. data/lib/core_process/cloud/process/server.rb +127 -0
  51. data/lib/core_process/cloud/process/server_log.rb +35 -0
  52. data/lib/core_process/cloud/process/subnetwork.rb +108 -0
  53. data/lib/core_process/cloud_process.rb +30 -0
  54. data/lib/logging.rb +298 -0
  55. data/lib/lorj/version.rb +18 -1
  56. data/lib/lorj.rb +58 -18
  57. data/lib/lorj_account.rb +556 -0
  58. data/lib/lorj_config.rb +468 -0
  59. data/lib/lorj_defaults.rb +278 -0
  60. data/lib/prc.rb +136 -104
  61. data/lib/prc_base_config.rb +285 -0
  62. data/lib/prc_core_config.rb +878 -0
  63. data/lib/prc_section_config.rb +57 -0
  64. data/lib/providers/hpcloud/compute.rb +81 -93
  65. data/lib/providers/hpcloud/hpcloud.rb +462 -0
  66. data/lib/providers/hpcloud/network.rb +96 -98
  67. data/lib/providers/hpcloud/security_groups.rb +41 -40
  68. data/lib/providers/mock/mock.rb +144 -0
  69. data/lib/providers/openstack/openstack.rb +45 -0
  70. data/lib/providers/templates/compute.rb +21 -23
  71. data/lib/providers/templates/mycloud.rb +72 -0
  72. data/lib/providers/templates/network.rb +11 -12
  73. data/lib/rh.rb +339 -0
  74. data/lorj-spec/defaults.yaml +4 -0
  75. data/lorj.gemspec +6 -0
  76. data/spec/00_lorj_log_spec.rb +53 -0
  77. data/spec/01_hash_rh_spec.rb +243 -0
  78. data/spec/02_prc_base_config_spec.rb +216 -0
  79. data/spec/04_prc_core_config_spec.rb +83 -0
  80. data/spec/11_lorj_config_spec.rb +263 -0
  81. data/spec/12_lorj_account_spec.rb +181 -0
  82. metadata +76 -28
  83. data/Gemfile.lock +0 -37
  84. data/example/students_1/process/Students.rb +0 -20
  85. data/example/students_2/process/Students.rb +0 -27
  86. data/example/students_4/controller/yaml_students.rb +0 -82
  87. data/example/students_4/controller/yaml_students_controller.rb +0 -141
  88. data/example/students_4/process/students.rb +0 -112
  89. data/example/students_4/students.rb +0 -103
  90. data/lib/core/lorj-basecontroller.rb +0 -90
  91. data/lib/core/lorj-basedefinition.rb +0 -1139
  92. data/lib/core/lorj-baseprocess.rb +0 -236
  93. data/lib/core/lorj-data.rb +0 -567
  94. data/lib/core/lorj-keypath.rb +0 -115
  95. data/lib/core_process/CloudProcess.rb +0 -337
  96. data/lib/core_process/global_process.rb +0 -502
  97. data/lib/core_process/network_process.rb +0 -605
  98. data/lib/prc-account.rb +0 -339
  99. data/lib/prc-config.rb +0 -1030
  100. data/lib/prc-logging.rb +0 -261
  101. data/lib/providers/hpcloud/Hpcloud.rb +0 -426
  102. data/lib/providers/mock/Mock.rb +0 -141
  103. data/lib/providers/openstack/Openstack.rb +0 -47
  104. data/lib/providers/templates/core.rb +0 -61
  105. data/spec/forj-account_spec.rb +0 -75
  106. data/spec/forj-config_spec.rb +0 -196
@@ -1,112 +0,0 @@
1
- # Students process
2
- class StudentsProcess
3
- def create_student(sObjectType, hParams)
4
- PrcLib::state ("Running creation process for object '%s' = '%s'" % [sObjectType, hParams[:student_name] ])
5
-
6
- aStudentName = hParams[:student_name].split(" ")
7
- # config object is a reference to runtime/config data.
8
- config[:first_name] = aStudentName[0]
9
- config[:last_name] = aStudentName[1]
10
-
11
- oList = Query(sObjectType, {:name => hParams[:student_name]})
12
- case oList.length
13
- when 0
14
- oObject = controller_create(sObjectType)
15
- raise "Student '%s' not created." % hParams[:student_name] if oObject.nil?
16
- PrcLib::info ("'%s': '%s' created with id %s" % [sObjectType, hParams[:student_name], oObject[:id]])
17
- when 1
18
- oObject = oList[0]
19
- PrcLib::info ("'%s': '%s' loaded with id %s" % [sObjectType, hParams[:student_name], oObject[:id]])
20
- else
21
- oObject = oList[0]
22
- PrcLib::warning("More than one student named '%s' is found: %s records. Selecting the first one and removing duplicates." % [hParams[:student_name], oList.length])
23
- iCount = 0
24
- oList[1..-1].each { | elem |
25
- register(elem)
26
- iCount += controller_delete(sObjectType)
27
- }
28
- PrcLib::info ("'%s': %s duplicated '%s' removed. First loaded with id %s" % [sObjectType, iCount, hParams[:student_name], oObject[:id]])
29
- end
30
- oObject
31
- end
32
-
33
- def query_student(sObjectType, sQuery, hParams)
34
- PrcLib::state ("Running query process for object '%s' with query '%s'" % [sObjectType, sQuery])
35
-
36
- oObjects = controller_query(sObjectType, sQuery)
37
- raise "Query error." if oObjects.nil?
38
-
39
- PrcLib::info ("'%s': Queried. %s records found." % [sObjectType, oObjects.length])
40
- oObjects
41
- end
42
-
43
- def get_student(sObjectType, sId, hParams)
44
- PrcLib::state ("Running get process for object '%s' with ID %s" % [sObjectType, sId ])
45
-
46
- oObject = controller_get(sObjectType, sId)
47
- PrcLib::debug("No ID %s found." % sId) if oObject.nil?
48
-
49
- oObject
50
- end
51
-
52
- def delete_student(sObjectType, hParams)
53
- Error "Unable to delete students, if at least one student is not loaded, or query not defined." if not hParams.exist?(:student) and not hParams.exist?(:query)
54
-
55
- # This student deletion process supports 2 modes:
56
- # - Delete from a query field (:query hParams)
57
- # - Delete the latest loaded student.
58
-
59
- if hParams.exist?(:query)
60
- result = Query(sObjectType, hParams[:query])
61
- if result.length > 0
62
- result.each { | student |
63
- puts "Student to remove: %s = %s" % [student[:id], student[:name]]
64
- register(student)
65
- controller_delete(:student)
66
- PrcLib::info ("'%s:%s' student removed" % [student[:id], student[:name]])
67
- }
68
- end
69
- else
70
- controller_delete(:student)
71
- end
72
- end
73
- end
74
-
75
- # Declaring your data model and handlers.
76
- class Lorj::BaseDefinition
77
-
78
- # We need to define the student object and the handler to use while we need to create it.
79
- define_obj(:student,
80
- {
81
- :create_e => :create_student, # The function to call in the class Students
82
- :query_e => :query_student,
83
- :delete_e => :delete_student,
84
- :get_e => :get_student
85
- })
86
-
87
- # All obj_needs will be collected and passed to the process handler as hParams.
88
- # Data required to create a student
89
- obj_needs :data, :student_name, { :for => [:create_e] }
90
-
91
- # Data optional for any kind of event
92
- obj_needs_optional
93
- obj_needs :data, :query, { :for => [:delete_e] }
94
- obj_needs :data, :first_name
95
- obj_needs :data, :last_name
96
- obj_needs :data, :course
97
-
98
- # Define Data a student object needs to take care.
99
- # The controller should map it if needed (if the value exists)
100
- # But it can also add some extra attributes not predefined by the process.
101
- # Usually, the process should ignore it.
102
- # But if it detect it, the process should be careful with this data
103
- # which are really specific to only one controller and may break the controller agnostic capability.
104
- def_attribute :course
105
- def_attribute :first_name
106
- def_attribute :last_name
107
- def_attribute :name
108
- def_attribute :status
109
- end
110
-
111
- class Lorj::BaseDefinition
112
- end
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $APP_PATH = File.dirname(__FILE__)
4
- require 'lorj'
5
- require 'ansi'
6
-
7
- # If you want to see what is happening in the framework, uncomment debug settings.
8
- #PrcLib.level = Logger::DEBUG # Printed out to your console.
9
- #PrcLib.core_level = 3 # framework debug levels. (0 to 5)
10
-
11
- # Load global Config
12
-
13
- # This object is used to provide configuration data to lorj
14
-
15
- # The config search is:
16
- # 1- Application defaults (defaults.yaml) - Not defined by default. update the following line and create defaults.yaml
17
- # PrcLib.app_defaults = $APP_PATH
18
- # 2- Local defaults (~/.<Application Name>/config.yaml) - <Application Name> is 'Lorj' by default. Can be updated with following line.
19
- # PrcLib.app_name = 'myapp'
20
- # 3 - runtime. Those variables are set, with oConfig[key] = value
21
-
22
- oConfig = Lorj::Config.new() # Use Simple Config Object
23
-
24
- # You can use an account object, which add an extra account level
25
- # between runtime and config.yaml/app default
26
- # oConfig = Lorj::Account.new('MyAccount')
27
-
28
-
29
- # Initialize the framework
30
- # Use students process
31
- hProcesses = [ File.join($APP_PATH, 'process', 'students.rb')]
32
- # Use yaml_students controller
33
- sController = File.join($APP_PATH, 'controller', 'yaml_students.rb')
34
- oStudentCore = Lorj::Core.new( oConfig, hProcesses, sController )
35
-
36
- # This kind of connection_string should be part of an Account Data.
37
- # So, we won't need to set this config.
38
- # But you can imagine to set at runtime this config as well.
39
- oConfig[:connection_string] = "/tmp/students.yaml"
40
-
41
- # Note that we have commented the next line.
42
- # oStudentCore.Create(:connection, :connection_string => "/tmp/students.yaml")
43
- # This call is not required, as the framework has all the information to create
44
- # the connection, at the first time this connection is required.
45
- # ie, while starting to create a student.
46
-
47
-
48
- # Set the student name to use
49
- oConfig[:student_name] = "Robert Redford"
50
-
51
- # Ask the framework to create the object student 'Robert Redford'
52
- puts ANSI.bold("Create 1st student:")
53
- oStudentCore.Create(:student)
54
- # The connection is made because creating a student requires
55
- # the object :connection. (See example/students_4/controller/yaml_students.rb, around line 70)
56
-
57
- puts ANSI.bold("Create 2nd student:")
58
- # Want to create a duplicated student 'Robert Redford'?
59
- oStudentCore.Create(:student)
60
- # Because the process ensure that there is no duplicate, this won't create duplicates
61
-
62
- # We can set runtime configuration instantly from the Create call
63
- # The following line :
64
- puts ANSI.bold("Create 3rd student:")
65
- oStudentCore.Create(:student, {:student_name => "Anthony Hopkins"})
66
- # replaced the following :
67
- # oConfig[:student_name] = "Anthony Hopkins"
68
- # oStudentCore.Create(:student)
69
-
70
- # Let's query students named "Robert Redford"
71
- puts ANSI.bold("Querying students as 'Robert Redford':")
72
- oStudents = oStudentCore.Query(:student, { :name => "Robert Redford" } )
73
-
74
- puts "%s students found for '%s':" % [oStudents.length, "Robert Redford"]
75
-
76
- oStudents.each { | oStudent |
77
- puts "%s: %s" % [oStudent[:id], oStudent[:name]]
78
- }
79
-
80
- # let's check the get function, who is the ID 2?
81
- puts ANSI.bold("Who is student ID 2?")
82
- oStudent = oStudentCore.Get(:student, 2)
83
-
84
- puts "\nThe student ID 2 is %s" % oStudent[:name] unless oStudent.nil?
85
- puts "\nThe student ID 2 doesn't exist." if oStudent.nil?
86
-
87
- puts ANSI.bold("Create mistake")
88
- oStudentCore.Create(:student, {
89
- :student_name => "Anthony Mistake",
90
- :course => 'what ever you want!!!'
91
- })
92
-
93
- # The query logic has been implemented directly in the process,
94
- # so now, any kind of controller Delete will have the same behavior...
95
- puts ANSI.bold("Remove mistake")
96
- hQuery = { :name => "Anthony Mistake"}
97
- oStudentCore.Delete(:student, :query => hQuery)
98
-
99
- puts ANSI.bold("List of students for 'Art Drama':")
100
- puts oStudentCore.Query(:student, { :course => "Art Drama"}).to_a
101
-
102
- puts ANSI.bold("Deleted students:")
103
- puts oStudentCore.Query(:student,{ :status => :removed}).to_a
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- # Module Lorj which contains several classes.
19
- #
20
- # Those classes describes :
21
- # - processes (BaseProcess) : How to create/delete/edit/query object.
22
- # - controler (BaseControler) : If a provider is defined, define how will do object creation/etc...
23
- # - definition(BaseDefinition): Functions to declare objects, query/data mapping and setup
24
- # this task to make it to work.
25
-
26
- module Lorj
27
-
28
- class BaseController
29
- # Default handlers which needs to be defined by the controller,
30
- # called by BaseDefinition Create functions.
31
- def connect(sObjectType, hParams)
32
- raise Lorj::PrcError.new(), "connect has not been redefined by the controller '%s'" % self.class
33
- end
34
-
35
- # Default handlers which needs to be defined by the controller,
36
- # called by BaseDefinition Create functions.
37
- def create(sObjectType, hParams)
38
- raise Lorj::PrcError.new(), "create_object has not been redefined by the controller '%s'" % self.class
39
- end
40
-
41
- # Default handlers which needs to be defined by the controller,
42
- # called by BaseDefinition Delete functions.
43
- def delete(sObjectType, hParams)
44
- raise Lorj::PrcError.new(), "delete_object has not been redefined by the controller '%s'" % self.class
45
- end
46
-
47
- # Default handlers which needs to be defined by the controller,
48
- # called by BaseDefinition Get functions.
49
- def get(sObjectType, sUniqId, hParams)
50
- raise Lorj::PrcError.new(), "get_object has not been redefined by the controller '%s'" % self.class
51
- end
52
-
53
- # Default handlers which needs to be defined by the controller,
54
- # called by BaseDefinition Query functions.
55
- def query(sObjectType, sQuery, hParams)
56
- raise Lorj::PrcError.new(), "query_object has not been redefined by the controller '%s'" % self.class
57
- end
58
-
59
- # Default handlers which needs to be defined by the controller,
60
- # called by BaseDefinition Update functions.
61
- def update(sObjectType, oObject, hParams)
62
- raise Lorj::PrcError.new(), "update_object has not been redefined by the controller '%s'" % self.class
63
- end
64
-
65
- # Simply raise an error
66
- #
67
- # * *Args* :
68
- # - +Msg+ : Error message to print out.
69
- # * *Returns* :
70
- # - nil
71
- # * *Raises* :
72
- # - Lorj::PrcError
73
- def Error(msg)
74
- raise Lorj::PrcError.new(), "%s: %s" % [self.class, msg]
75
- end
76
-
77
- # check if required data is loaded. raise an error if not
78
- #
79
- # * *Args* :
80
- # - +Params+ : Lorj::ObjectData object for controller.
81
- # - +key+ : Key to check.
82
- # * *Returns* :
83
- # - nil
84
- # * *Raises* :
85
- # - +Error+ if the key do not exist.
86
- def required?(oParams, *key)
87
- raise Lorj::PrcError.new(), "%s: %s is not set." % [self.class, key] if not oParams.exist?(key)
88
- end
89
- end
90
- end