occi-core 4.3.6 → 5.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.fasterer.yml +3 -0
- data/.gitignore +9 -16
- data/.rspec +1 -1
- data/.rubocop.yml +69 -0
- data/.travis.yml +27 -0
- data/AUTHORS +8 -6
- data/CHANGELOG.md +0 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +25 -170
- data/Rakefile +25 -17
- data/examples/initialize_model.rb +10 -0
- data/examples/parse_action_instance_json.rb +15 -0
- data/examples/parse_action_instance_text.rb +15 -0
- data/examples/parse_categories_json.rb +15 -0
- data/examples/parse_categories_text.rb +15 -0
- data/examples/parse_instance_json.rb +15 -0
- data/examples/parse_instance_text.rb +15 -0
- data/examples/parse_model_json.rb +9 -0
- data/examples/parse_model_text.rb +9 -0
- data/examples/render_action_instance_json.rb +17 -0
- data/examples/render_action_instance_text.rb +17 -0
- data/examples/render_instance_json.rb +20 -0
- data/examples/render_instance_text.rb +20 -0
- data/examples/render_model_json.rb +12 -0
- data/examples/render_model_text.rb +12 -0
- data/examples/rendering/action_instance.json +6 -0
- data/examples/rendering/action_instance.txt +2 -0
- data/examples/rendering/categories.json +78 -0
- data/examples/rendering/categories.txt +4 -0
- data/examples/rendering/instance.json +70 -0
- data/examples/rendering/instance.txt +12 -0
- data/examples/rendering/model.alt.json +1716 -0
- data/examples/rendering/model.json +785 -0
- data/examples/rendering/model.txt +68 -0
- data/lib/occi/core/action.rb +12 -26
- data/lib/occi/core/action_instance.rb +109 -65
- data/lib/occi/core/attribute.rb +136 -0
- data/lib/occi/core/attribute_definition.rb +269 -0
- data/lib/occi/core/category.rb +110 -83
- data/lib/occi/core/collection.rb +255 -0
- data/lib/occi/core/constants.rb +14 -0
- data/lib/occi/core/entity.rb +301 -195
- data/lib/occi/core/errors/.gitkeep +0 -0
- data/lib/occi/core/errors/attribute_definition_error.rb +11 -0
- data/lib/occi/core/errors/attribute_validation_error.rb +13 -0
- data/lib/occi/core/errors/category_validation_error.rb +13 -0
- data/lib/occi/core/errors/collection_lookup_error.rb +11 -0
- data/lib/occi/core/errors/instance_validation_error.rb +13 -0
- data/lib/occi/core/errors/mandatory_argument_error.rb +11 -0
- data/lib/occi/core/errors/model_lookup_error.rb +11 -0
- data/lib/occi/core/errors/parser_error.rb +11 -0
- data/lib/occi/core/errors/parsing_error.rb +11 -0
- data/lib/occi/core/errors/renderer_error.rb +11 -0
- data/lib/occi/core/errors/rendering_error.rb +11 -0
- data/lib/occi/core/errors/validation_error.rb +11 -0
- data/lib/occi/core/errors.rb +9 -0
- data/lib/occi/core/helpers/.gitkeep +0 -0
- data/lib/occi/core/helpers/argument_validator.rb +27 -0
- data/lib/occi/core/helpers/attributes_accessor.rb +22 -0
- data/lib/occi/core/helpers/error_handler.rb +29 -0
- data/lib/occi/core/helpers/hash_dereferencer.rb +149 -0
- data/lib/occi/core/helpers/identifier_validator.rb +135 -0
- data/lib/occi/core/helpers/instance_attribute_resetter.rb +131 -0
- data/lib/occi/core/helpers/instance_attributes_accessor.rb +30 -0
- data/lib/occi/core/helpers/locatable.rb +40 -0
- data/lib/occi/core/helpers/parser_dereferencer.rb +96 -0
- data/lib/occi/core/helpers/raw_json_parser.rb +18 -0
- data/lib/occi/core/helpers/renderable.rb +93 -0
- data/lib/occi/core/helpers/yaml_summoner.rb +44 -0
- data/lib/occi/core/helpers.rb +13 -0
- data/lib/occi/core/instance_builder.rb +162 -0
- data/lib/occi/core/kind.rb +100 -132
- data/lib/occi/core/link.rb +47 -72
- data/lib/occi/core/mixin.rb +76 -61
- data/lib/occi/core/model.rb +341 -0
- data/lib/occi/core/parsers/.gitkeep +0 -0
- data/lib/occi/core/parsers/base_parser.rb +168 -0
- data/lib/occi/core/parsers/json/.gitkeep +0 -0
- data/lib/occi/core/parsers/json/action_instance.rb +36 -0
- data/lib/occi/core/parsers/json/category.rb +113 -0
- data/lib/occi/core/parsers/json/entity.rb +156 -0
- data/lib/occi/core/parsers/json/validator/.gitkeep +0 -0
- data/lib/occi/core/parsers/json/validator/action-instance.json +3 -0
- data/lib/occi/core/parsers/json/validator/entity-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/link-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/link.json +3 -0
- data/lib/occi/core/parsers/json/validator/locations.json +3 -0
- data/lib/occi/core/parsers/json/validator/mixin-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/model.json +3 -0
- data/lib/occi/core/parsers/json/validator/occi-schema.json +277 -0
- data/lib/occi/core/parsers/json/validator/resource-collection.json +3 -0
- data/lib/occi/core/parsers/json/validator/resource.json +3 -0
- data/lib/occi/core/parsers/json/validator.rb +87 -0
- data/lib/occi/core/parsers/json_parser.rb +128 -0
- data/lib/occi/core/parsers/text/.gitkeep +0 -0
- data/lib/occi/core/parsers/text/category.rb +183 -0
- data/lib/occi/core/parsers/text/constants.rb +89 -0
- data/lib/occi/core/parsers/text/entity.rb +257 -0
- data/lib/occi/core/parsers/text/location.rb +48 -0
- data/lib/occi/core/parsers/text_parser.rb +257 -0
- data/lib/occi/core/parsers.rb +18 -0
- data/lib/occi/core/renderer_factory.rb +213 -0
- data/lib/occi/core/renderers/.gitkeep +0 -0
- data/lib/occi/core/renderers/base_renderer.rb +81 -0
- data/lib/occi/core/renderers/json/.gitkeep +0 -0
- data/lib/occi/core/renderers/json/action_instance.rb +24 -0
- data/lib/occi/core/renderers/json/attributes.rb +50 -0
- data/lib/occi/core/renderers/json/base.rb +46 -0
- data/lib/occi/core/renderers/json/category.rb +85 -0
- data/lib/occi/core/renderers/json/collection.rb +52 -0
- data/lib/occi/core/renderers/json/instance.rb +39 -0
- data/lib/occi/core/renderers/json/link.rb +48 -0
- data/lib/occi/core/renderers/json/model.rb +26 -0
- data/lib/occi/core/renderers/json/resource.rb +27 -0
- data/lib/occi/core/renderers/json_renderer.rb +72 -0
- data/lib/occi/core/renderers/text/.gitkeep +0 -0
- data/lib/occi/core/renderers/text/action_instance.rb +36 -0
- data/lib/occi/core/renderers/text/attributes.rb +87 -0
- data/lib/occi/core/renderers/text/base.rb +82 -0
- data/lib/occi/core/renderers/text/category.rb +183 -0
- data/lib/occi/core/renderers/text/collection.rb +65 -0
- data/lib/occi/core/renderers/text/instance.rb +44 -0
- data/lib/occi/core/renderers/text/link.rb +40 -0
- data/lib/occi/core/renderers/text/model.rb +41 -0
- data/lib/occi/core/renderers/text/resource.rb +109 -0
- data/lib/occi/core/renderers/text_renderer.rb +72 -0
- data/lib/occi/core/renderers.rb +20 -0
- data/lib/occi/core/resource.rb +93 -57
- data/lib/occi/core/utils/.gitkeep +0 -0
- data/lib/occi/core/version.rb +17 -0
- data/lib/occi/core/warehouse/actions/.gitkeep +0 -0
- data/lib/occi/core/warehouse/actions/attributes/.gitkeep +0 -0
- data/lib/occi/core/warehouse/kinds/.gitkeep +0 -0
- data/lib/occi/core/warehouse/kinds/attributes/.gitkeep +0 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.id.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.source.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.summary.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.target.yml +7 -0
- data/lib/occi/core/warehouse/kinds/attributes/occi.core.title.yml +7 -0
- data/lib/occi/core/warehouse/kinds/entity.yml +10 -0
- data/lib/occi/core/warehouse/kinds/link.yml +10 -0
- data/lib/occi/core/warehouse/kinds/resource.yml +9 -0
- data/lib/occi/core/warehouse/mixins/.gitkeep +0 -0
- data/lib/occi/core/warehouse/mixins/attributes/.gitkeep +0 -0
- data/lib/occi/core/warehouse.rb +115 -0
- data/lib/occi/core.rb +59 -23
- data/lib/occi/infrastructure/compute.rb +5 -122
- data/lib/occi/infrastructure/constants.rb +25 -0
- data/lib/occi/infrastructure/instance_builder.rb +24 -0
- data/lib/occi/infrastructure/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure/mixins/os_tpl.rb +19 -0
- data/lib/occi/infrastructure/mixins/resource_tpl.rb +19 -0
- data/lib/occi/infrastructure/mixins.rb +12 -0
- data/lib/occi/infrastructure/model.rb +27 -0
- data/lib/occi/infrastructure/network.rb +5 -104
- data/lib/occi/infrastructure/networkinterface.rb +5 -100
- data/lib/occi/infrastructure/storage.rb +5 -59
- data/lib/occi/infrastructure/storagelink.rb +5 -54
- data/lib/occi/infrastructure/version.rb +5 -0
- data/lib/occi/infrastructure/warehouse/actions/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/actions/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_restart.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_save.yml +19 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_start.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_stop.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/compute_suspend.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/network_down.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/network_up.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/networkinterface_down.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/networkinterface_up.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_backup.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_offline.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_online.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_resize.yml +12 -0
- data/lib/occi/infrastructure/warehouse/actions/storage_snapshot.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storagelink_offline.yml +4 -0
- data/lib/occi/infrastructure/warehouse/actions/storagelink_online.yml +4 -0
- data/lib/occi/infrastructure/warehouse/kinds/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.architecture.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.cores.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.hostname.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.memory.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.speed.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.compute.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.label.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.network.vlan.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.interface.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.mac.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.networkinterface.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.size.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storage.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.deviceid.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.mountpoint.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/attributes/occi.storagelink.state.yml +7 -0
- data/lib/occi/infrastructure/warehouse/kinds/compute.yml +19 -0
- data/lib/occi/infrastructure/warehouse/kinds/network.yml +13 -0
- data/lib/occi/infrastructure/warehouse/kinds/networkinterface.yml +13 -0
- data/lib/occi/infrastructure/warehouse/kinds/storage.yml +15 -0
- data/lib/occi/infrastructure/warehouse/kinds/storagelink.yml +13 -0
- data/lib/occi/infrastructure/warehouse/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.address.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.allocation.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.network.gateway.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.address.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.allocation.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/attributes/occi.networkinterface.gateway.yml +7 -0
- data/lib/occi/infrastructure/warehouse/mixins/ipnetwork.yml +11 -0
- data/lib/occi/infrastructure/warehouse/mixins/ipnetworkinterface.yml +11 -0
- data/lib/occi/infrastructure/warehouse.rb +20 -0
- data/lib/occi/infrastructure-ext.rb +35 -0
- data/lib/occi/infrastructure.rb +34 -19
- data/lib/occi/infrastructure_ext/constants.rb +20 -0
- data/lib/occi/infrastructure_ext/instance_builder.rb +22 -0
- data/lib/occi/infrastructure_ext/ipreservation.rb +9 -0
- data/lib/occi/infrastructure_ext/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/mixins/availability_zone.rb +19 -0
- data/lib/occi/infrastructure_ext/mixins.rb +12 -0
- data/lib/occi/infrastructure_ext/model.rb +26 -0
- data/lib/occi/infrastructure_ext/securitygroup.rb +9 -0
- data/lib/occi/infrastructure_ext/securitygrouplink.rb +9 -0
- data/lib/occi/infrastructure_ext/version.rb +5 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_down.yml +4 -0
- data/lib/occi/infrastructure_ext/warehouse/actions/ipreservation_up.yml +4 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.address.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.state.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.ipreservation.used.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.rules.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygroup.state.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/attributes/occi.securitygrouplink.state.yml +7 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/ipreservation.yml +13 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/securitygroup.yml +9 -0
- data/lib/occi/infrastructure_ext/warehouse/kinds/securitygrouplink.yml +8 -0
- data/lib/occi/infrastructure_ext/warehouse/mixins/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse/mixins/attributes/.gitkeep +0 -0
- data/lib/occi/infrastructure_ext/warehouse.rb +20 -0
- data/lib/occi/monkey_island/boolean.rb +6 -0
- data/lib/occi/monkey_island/hash.rb +4 -0
- data/occi-core.gemspec +26 -26
- metadata +312 -243
- data/.yardopts +0 -1
- data/config/occi.yml +0 -4
- data/lib/occi/collection.rb +0 -265
- data/lib/occi/core/actions.rb +0 -21
- data/lib/occi/core/attributes.rb +0 -411
- data/lib/occi/core/categories.rb +0 -64
- data/lib/occi/core/dependencies.rb +0 -7
- data/lib/occi/core/entities.rb +0 -48
- data/lib/occi/core/kinds.rb +0 -22
- data/lib/occi/core/links.rb +0 -37
- data/lib/occi/core/mixins.rb +0 -37
- data/lib/occi/core/properties.rb +0 -108
- data/lib/occi/core/resources.rb +0 -14
- data/lib/occi/errors/attribute_definitions_converted_error.rb +0 -5
- data/lib/occi/errors/attribute_missing_error.rb +0 -5
- data/lib/occi/errors/attribute_name_invalid_error.rb +0 -5
- data/lib/occi/errors/attribute_not_defined_error.rb +0 -5
- data/lib/occi/errors/attribute_property_type_error.rb +0 -5
- data/lib/occi/errors/attribute_type_error.rb +0 -5
- data/lib/occi/errors/category_not_defined_error.rb +0 -5
- data/lib/occi/errors/kind_not_defined_error.rb +0 -5
- data/lib/occi/errors/parser_input_error.rb +0 -5
- data/lib/occi/errors/parser_type_error.rb +0 -5
- data/lib/occi/errors.rb +0 -1
- data/lib/occi/extensions/hashie.rb +0 -25
- data/lib/occi/helpers/comparators/action_instance.rb +0 -22
- data/lib/occi/helpers/comparators/attributes.rb +0 -22
- data/lib/occi/helpers/comparators/categories.rb +0 -22
- data/lib/occi/helpers/comparators/category.rb +0 -22
- data/lib/occi/helpers/comparators/collection.rb +0 -40
- data/lib/occi/helpers/comparators/entities.rb +0 -22
- data/lib/occi/helpers/comparators/entity.rb +0 -22
- data/lib/occi/helpers/comparators/properties.rb +0 -26
- data/lib/occi/helpers/comparators.rb +0 -1
- data/lib/occi/helpers/inspect.rb +0 -12
- data/lib/occi/infrastructure/network/ipnetwork.rb +0 -28
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +0 -28
- data/lib/occi/infrastructure/os_tpl.rb +0 -20
- data/lib/occi/infrastructure/resource_tpl.rb +0 -20
- data/lib/occi/log.rb +0 -71
- data/lib/occi/model.rb +0 -87
- data/lib/occi/parser/json.rb +0 -38
- data/lib/occi/parser/text/constants.rb +0 -89
- data/lib/occi/parser/text.rb +0 -280
- data/lib/occi/parser.rb +0 -144
- data/lib/occi/settings.rb +0 -10
- data/lib/occi/version.rb +0 -3
- data/lib/occi-core.rb +0 -53
- data/spec/helpers/to_plain.rb +0 -39
- data/spec/helpers/yaml_hash.rb +0 -32
- data/spec/occi/collection_samples/collection1.json +0 -1
- data/spec/occi/collection_samples/directory2/collection2.json +0 -1
- data/spec/occi/collection_spec.rb +0 -1003
- data/spec/occi/core/action_instance_spec.rb +0 -317
- data/spec/occi/core/action_spec.rb +0 -71
- data/spec/occi/core/attributes_spec.rb +0 -665
- data/spec/occi/core/categories_spec.rb +0 -28
- data/spec/occi/core/category_spec.rb +0 -216
- data/spec/occi/core/entities_spec.rb +0 -160
- data/spec/occi/core/entity_spec.rb +0 -374
- data/spec/occi/core/kind_spec.rb +0 -182
- data/spec/occi/core/link_spec.rb +0 -52
- data/spec/occi/core/links_spec.rb +0 -132
- data/spec/occi/core/mixin_spec.rb +0 -38
- data/spec/occi/core/mixins_spec.rb +0 -107
- data/spec/occi/core/properties_spec.rb +0 -171
- data/spec/occi/core/resource_spec.rb +0 -42
- data/spec/occi/core_spec.rb +0 -12
- data/spec/occi/infrastructure/compute_spec.rb +0 -229
- data/spec/occi/infrastructure/network_spec.rb +0 -96
- data/spec/occi/infrastructure/networkinterface_spec.rb +0 -96
- data/spec/occi/infrastructure/storage_spec.rb +0 -33
- data/spec/occi/infrastructure/storagelink_spec.rb +0 -45
- data/spec/occi/log_spec.rb +0 -117
- data/spec/occi/model_spec.rb +0 -256
- data/spec/occi/parser/json_samples/test.json +0 -49
- data/spec/occi/parser/text_samples/occi_categories.body_plain.expected +0 -2
- data/spec/occi/parser/text_samples/occi_categories.expected +0 -2
- data/spec/occi/parser/text_samples/occi_categories.parse_headers.expected +0 -2
- data/spec/occi/parser/text_samples/occi_categories.text +0 -2
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.expected +0 -11
- data/spec/occi/parser/text_samples/occi_compute_rocci_server.text +0 -10
- data/spec/occi/parser/text_samples/occi_link_resource_instance.body_plain.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_resource_instance.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_resource_instance.parse.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_resource_instance.text +0 -7
- data/spec/occi/parser/text_samples/occi_link_simple.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_simple.text +0 -1
- data/spec/occi/parser/text_samples/occi_link_w_attributes.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_w_attributes.text +0 -7
- data/spec/occi/parser/text_samples/occi_link_w_category.expected +0 -7
- data/spec/occi/parser/text_samples/occi_link_w_category.text +0 -3
- data/spec/occi/parser/text_samples/occi_model_categories.expected +0 -3
- data/spec/occi/parser/text_samples/occi_model_rocci_server.text +0 -51
- data/spec/occi/parser/text_samples/occi_network_rocci_server.body_plain.expected +0 -11
- data/spec/occi/parser/text_samples/occi_network_rocci_server.expected +0 -11
- data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.header.expected +0 -9
- data/spec/occi/parser/text_samples/occi_network_rocci_server.resource.rack.expected +0 -9
- data/spec/occi/parser/text_samples/occi_network_rocci_server.text +0 -11
- data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.parse.expected +0 -15
- data/spec/occi/parser/text_samples/occi_resource_custom_class_w_attributes.text +0 -15
- data/spec/occi/parser/text_samples/occi_resource_w_attributes.text +0 -11
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.expected +0 -1
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links.text +0 -16
- data/spec/occi/parser/text_samples/occi_resource_w_inline_links_only.text +0 -13
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.expected +0 -9
- data/spec/occi/parser/text_samples/occi_storage_rocci_server.text +0 -9
- data/spec/occi/parser/text_spec.rb +0 -320
- data/spec/occi/parser_spec.rb +0 -259
- data/spec/occi-core_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -18
@@ -0,0 +1,96 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
module Helpers
|
4
|
+
# Introduces dereferencing capabilities to various parsers. This allowes
|
5
|
+
# parsers to convert `Occi::Core::Category` sub-types from identifier into proper objects.
|
6
|
+
#
|
7
|
+
# @author Boris Parak <parak@cesnet.cz>
|
8
|
+
module ParserDereferencer
|
9
|
+
# Dereferences cross-category references. Takes existing string
|
10
|
+
# identifiers for actions, mixins, and kinds and replaces them
|
11
|
+
# with actual instances.
|
12
|
+
#
|
13
|
+
# @param derefd [Array] list of instances needing dereferencing
|
14
|
+
# @param parsed [Array] list of raw parsed categories (as hashes)
|
15
|
+
# @return [Array] dereferenced list of instances
|
16
|
+
def dereference_identifiers!(derefd, parsed)
|
17
|
+
derefd.each do |cat|
|
18
|
+
next if cat.is_a?(Occi::Core::Action) # nothing to do here
|
19
|
+
lookup_references!(cat, derefd, parsed)
|
20
|
+
end
|
21
|
+
derefd
|
22
|
+
end
|
23
|
+
|
24
|
+
# Looks up inter-category references and replaces them with existing objects.
|
25
|
+
#
|
26
|
+
# @param cat [Occi::Core::Mixin, Occi::Core::Kind] category to dereference
|
27
|
+
# @param derefd [Array] list of known categories
|
28
|
+
# @param parsed [Array] list of original parsed category structures
|
29
|
+
def lookup_references!(cat, derefd, parsed)
|
30
|
+
parsed_cat = parsed.detect { |pcat| "#{pcat[:scheme]}#{pcat[:term]}" == cat.identifier }
|
31
|
+
raise Occi::Core::Errors::ParsingError, "#{self} -> #{cat.identifier} not in the model" unless parsed_cat
|
32
|
+
lookup_action_references!(cat, derefd, parsed_cat[:actions])
|
33
|
+
|
34
|
+
if cat.is_a?(Occi::Core::Mixin)
|
35
|
+
lookup_depends_references!(cat, derefd, parsed_cat[self::DEPENDS_KEY])
|
36
|
+
lookup_applies_references!(cat, derefd, parsed_cat[self::APPLIES_KEY])
|
37
|
+
else
|
38
|
+
# only Occi::Core::Kind is left here
|
39
|
+
lookup_parent_references!(cat, derefd, parsed_cat[self::PARENT_KEY])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# @param cat [Occi::Core::Mixin, Occi::Core::Kind] category instance needing action dereferencing
|
44
|
+
# @param derefd [Array] list of all available category instances
|
45
|
+
# @param parsed_actions [Array] textual representation of needed actions
|
46
|
+
def lookup_action_references!(cat, derefd, parsed_actions)
|
47
|
+
return if parsed_actions.blank?
|
48
|
+
parsed_actions.each { |action| cat.actions << first_or_die(derefd, action) }
|
49
|
+
end
|
50
|
+
|
51
|
+
# @param kind [Occi::Core::Kind] kind instance needing parent dereferencing
|
52
|
+
# @param derefd [Array] list of all available category instances
|
53
|
+
# @param parsed_rel [Array] textual representation of needed parent(s)
|
54
|
+
def lookup_parent_references!(kind, derefd, parsed_rel)
|
55
|
+
return if parsed_rel.blank? || kind.parent.is_a?(Occi::Core::Kind)
|
56
|
+
if parsed_rel.is_a?(Enumerable)
|
57
|
+
if parsed_rel.count > 1
|
58
|
+
raise Occi::Core::Errors::ParsingError,
|
59
|
+
"#{self} -> Kind #{kind} with multiple parents #{parsed_rel.inspect}"
|
60
|
+
end
|
61
|
+
parsed_rel = parsed_rel.first
|
62
|
+
end
|
63
|
+
|
64
|
+
kind.parent = first_or_die(derefd, parsed_rel)
|
65
|
+
kind.send(:load_parent_attributes!) # this is safe because there was no previous parent!
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param mixin [Occi::Core::Mixin] mixin instance needing applicability dereferencing
|
69
|
+
# @param derefd [Array] list of all available category instances
|
70
|
+
# @param parsed_rel [Array] textual representations of needed applicability targets
|
71
|
+
def lookup_applies_references!(_mixin, _derefd, _parsed_rel)
|
72
|
+
raise Occi::Core::Errors::ParserError, 'Must be implemented in the parser class'
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param mixin [Occi::Core::Mixin] mixin instance needing dependency dereferencing
|
76
|
+
# @param derefd [Array] list of all available category instances
|
77
|
+
# @param parsed_rel [Array] textual representations of needed dependencies
|
78
|
+
def lookup_depends_references!(_mixin, _derefd, _parsed_rel)
|
79
|
+
raise Occi::Core::Errors::ParserError, 'Must be implemented in the parser class'
|
80
|
+
end
|
81
|
+
|
82
|
+
# @param where [Enumerable] list of items to look through, items must respond to `.identifier`
|
83
|
+
# @param what [String] identifier of the desired item
|
84
|
+
# @return [Object] desired item from `where`
|
85
|
+
def first_or_die(where, what)
|
86
|
+
found = where.detect { |elm| elm.identifier == what }
|
87
|
+
unless found
|
88
|
+
raise Occi::Core::Errors::ParsingError,
|
89
|
+
"#{self} -> Category #{what.to_s.inspect} referenced but not provided"
|
90
|
+
end
|
91
|
+
found
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
module Helpers
|
4
|
+
# Introduces JSON parsing to various parser classes. This allowes
|
5
|
+
# parsers to convert JSON-formatted text into hashes.
|
6
|
+
#
|
7
|
+
# @author Boris Parak <parak@cesnet.cz>
|
8
|
+
module RawJsonParser
|
9
|
+
# :nodoc:
|
10
|
+
def raw_hash(body)
|
11
|
+
JSON.parse body, symbolize_names: true
|
12
|
+
rescue => ex
|
13
|
+
raise Occi::Core::Errors::ParsingError, "#{self} -> JSON parsing failed: #{ex.message}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
module Helpers
|
4
|
+
# Introduces rendering capabilities to every receiver
|
5
|
+
# class. Short-hand `to_<format>` methods are automatically
|
6
|
+
# generated for every available rendering `format`. The
|
7
|
+
# renderability is evaluated in runtime, when calling `render`
|
8
|
+
# or one of the `to_<format>` methods.
|
9
|
+
#
|
10
|
+
# @author Boris Parak <parak@cesnet.cz>
|
11
|
+
module Renderable
|
12
|
+
# Default renderer factory class
|
13
|
+
RENDERER_FACTORY_CLASS = Occi::Core::RendererFactory
|
14
|
+
|
15
|
+
# Renders the receiver into the specified over-the-wire `format`.
|
16
|
+
# `format` is automatically injected into `options` and these
|
17
|
+
# are then passed (unmodified) to the underlying renderer. See
|
18
|
+
# documentation of a specific renderer for details.
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# render 'text' # => String
|
22
|
+
# render 'json' # => String
|
23
|
+
# render 'headers' # => Hash
|
24
|
+
#
|
25
|
+
# @param format [String] over-the-wire format, mandatory
|
26
|
+
# @param options [Hash] options passed to the underlying renderer
|
27
|
+
# @return [Object] output of the chosen renderer
|
28
|
+
def render(format, options = {})
|
29
|
+
options[:format] = format
|
30
|
+
logger.debug "#{self.class} is being rendered to #{format} with #{options.inspect}" if respond_to?(:logger)
|
31
|
+
renderer_for(format).render(self, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Instance delegate for `RendererFactory#renderer_for`, see `RendererFactory`.
|
35
|
+
def renderer_for(format)
|
36
|
+
renderer_factory.renderer_for(format)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Instance proxy to `renderer_factory` instance, see `Renderable::renderer_factory`.
|
40
|
+
def renderer_factory
|
41
|
+
Renderable.renderer_factory
|
42
|
+
end
|
43
|
+
|
44
|
+
# Adds available rendering formats as `to_<format>` methods on
|
45
|
+
# the receiver.
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# class Test
|
49
|
+
# include Occi::Core::Helpers::Renderable
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# t = Test.new
|
53
|
+
# t.to_text # => String
|
54
|
+
#
|
55
|
+
# @param base [Class] class receiving this module
|
56
|
+
def self.included(base)
|
57
|
+
renderer_factory.formats.each do |format|
|
58
|
+
base.logger.debug "Renderable: Adding support for #{format} to #{base}" if base.respond_to?(:logger)
|
59
|
+
base.send(:define_method, "to_#{format}", proc { render(format) })
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Allows calling `.extend(Renderable)` on instances. Does not allow
|
64
|
+
# class-based extension, will raise a `RuntimeError` error.
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# o = Object.new
|
68
|
+
# o.extend Renderable
|
69
|
+
# o.to_text # => String
|
70
|
+
#
|
71
|
+
# @param base [Class, Object] class or object being extended
|
72
|
+
def self.extended(base)
|
73
|
+
base.is_a?(Class) ? raise("#{self} cannot extend #{base}") : included(base.class)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns pre-constructed instance of the active renderer
|
77
|
+
# factory providing access to registered renderers.
|
78
|
+
#
|
79
|
+
# @return [Object] instance of the renderer factory
|
80
|
+
def self.renderer_factory
|
81
|
+
renderer_factory_class.instance
|
82
|
+
end
|
83
|
+
|
84
|
+
# Provides access to the default renderer factory class.
|
85
|
+
#
|
86
|
+
# @return [Class] renderer factory class
|
87
|
+
def self.renderer_factory_class
|
88
|
+
RENDERER_FACTORY_CLASS
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
module Helpers
|
4
|
+
# Introduces YAML parsing capabilities to every receiver
|
5
|
+
# class.
|
6
|
+
#
|
7
|
+
# @author Boris Parak <parak@cesnet.cz>
|
8
|
+
module YamlSummoner
|
9
|
+
# Reads the provided YAML file and passes its content as `args` to the
|
10
|
+
# constructor of the class. YAML file is expected to provide all the
|
11
|
+
# necessary information (depending on the class in question) in the
|
12
|
+
# required form (appropriate types and structures). Dereferencing will
|
13
|
+
# will be automatically attempted on suitable classes, this requires
|
14
|
+
# `model` and `attribute_definitions` to be provided.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# Occi::Core::AttributeDefinition.from_yaml 'my_def.yml'
|
18
|
+
# # => #<Occi::Core::AttributeDefinition>
|
19
|
+
#
|
20
|
+
# @param path [String] path to a YAML File
|
21
|
+
# @param model [Occi::Core::Model] model instance for dereferencing (category look-up)
|
22
|
+
# @param attribute_definitions [Hash] hash with known attribute definitions for dereferencing
|
23
|
+
# @return [Object] instance of receiver class
|
24
|
+
def from_yaml(path, model = nil, attribute_definitions = nil)
|
25
|
+
raise 'This method cannot be invoked on instances' unless is_a? Class
|
26
|
+
allowed_classes = respond_to?(:allowed_yaml_classes, true) ? allowed_yaml_classes : []
|
27
|
+
|
28
|
+
object_args = YAML.safe_load(File.read(path), allowed_classes)
|
29
|
+
object_args.symbolize_keys!
|
30
|
+
object_args.dereference_with!(self, model, attribute_definitions) if needs_dereferencing?
|
31
|
+
new object_args
|
32
|
+
end
|
33
|
+
|
34
|
+
# Identifies classes suitable for dereferencing.
|
35
|
+
#
|
36
|
+
# @return [TrueClass] if needs dereferencing
|
37
|
+
# @return [FalseClass] if does not need dereferencing
|
38
|
+
def needs_dereferencing?
|
39
|
+
ancestors.include? Occi::Core::Category
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
# Contains various helper modules and classes shared with
|
4
|
+
# the rest of the code. For details, see documentation
|
5
|
+
# for the particular helper.
|
6
|
+
#
|
7
|
+
# @author Boris Parak <parak@cesnet.cz>
|
8
|
+
module Helpers; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require File.join(File.dirname(__FILE__), 'helpers', 'argument_validator')
|
13
|
+
Dir[File.join(File.dirname(__FILE__), 'helpers', '*.rb')].each { |file| require file.gsub('.rb', '') }
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
# Provides mechanisms for easy instantiation of various
|
4
|
+
# Entity sub-types such as Resource or Link (and their sub-types).
|
5
|
+
# Unknown sub-types will result in generic `Occi::Core::Resource`
|
6
|
+
# and `Occi::Core::Link` instances.
|
7
|
+
# Known (pre-defined) sub-types will be provided as instances of
|
8
|
+
# unique classes inheriting from the abovementioned.
|
9
|
+
#
|
10
|
+
# @attr model [Occi::Core::Model] model filled with known category definitions
|
11
|
+
#
|
12
|
+
# @author Boris Parak <parak@cesnet.cz>
|
13
|
+
class InstanceBuilder
|
14
|
+
include Yell::Loggable
|
15
|
+
include Helpers::ArgumentValidator
|
16
|
+
|
17
|
+
attr_accessor :model
|
18
|
+
|
19
|
+
# Constructs and instance of the InstanceBuilder. It can be used to quickly and easily get
|
20
|
+
# get instances of various `Occi::Core::Entity` sub-types based on their kind identifier.
|
21
|
+
#
|
22
|
+
# @param args [Hash] constructor arguments
|
23
|
+
# @option args [Occi::Core::Model] :model model filled with known category definitions
|
24
|
+
def initialize(args = {})
|
25
|
+
pre_initialize(args)
|
26
|
+
default_args! args
|
27
|
+
|
28
|
+
@model = args.fetch(:model)
|
29
|
+
|
30
|
+
post_initialize(args)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Constructs an instance based on the given category identifier. This method
|
34
|
+
# can construct instances of Entity sub-types.
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# build 'http://schemas.ogf.org/occi/core#resource'
|
38
|
+
# # => Occi::Core::Resource
|
39
|
+
#
|
40
|
+
# @param identifier [String] identifier of the category
|
41
|
+
# @param args [Hash] hash for the instance constructor
|
42
|
+
# @return [Object] constructed instance
|
43
|
+
# @return [NilClass] if such an instance could not be constructed
|
44
|
+
def build(identifier, args = {})
|
45
|
+
k_args = args_with_kind(identifier, args)
|
46
|
+
klass(identifier, parent_klass(k_args[:kind])).new k_args
|
47
|
+
end
|
48
|
+
alias get build
|
49
|
+
|
50
|
+
# Constructs an instance based on the given category identifier. This method
|
51
|
+
# can construct instances of Resource sub-types.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# build_resource 'http://schemas.ogf.org/occi/core#resource' # => Occi::Core::Resource
|
55
|
+
#
|
56
|
+
# @param identifier [String] identifier of the category
|
57
|
+
# @param args [Hash] hash for the instance constructor
|
58
|
+
# @return [Object] constructed instance
|
59
|
+
# @return [NilClass] if such an instance could not be constructed
|
60
|
+
def build_resource(identifier, args = {})
|
61
|
+
klass(identifier, Occi::Core::Resource).new args_with_kind(identifier, args)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Constructs an instance based on the given category identifier. This method
|
65
|
+
# can construct instances of Link sub-types.
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# build_link 'http://schemas.ogf.org/occi/core#link' # => Occi::Core::Link
|
69
|
+
#
|
70
|
+
# @param identifier [String] identifier of the category
|
71
|
+
# @param args [Hash] hash for the instance constructor
|
72
|
+
# @return [Object] constructed instance
|
73
|
+
# @return [NilClass] if such an instance could not be constructed
|
74
|
+
def build_link(identifier, args = {})
|
75
|
+
klass(identifier, Occi::Core::Link).new args_with_kind(identifier, args)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Looks up the appropriate candidate class for the given identifier. If no class
|
79
|
+
# is found in static tables, the last known ancestor is returned. For Core, this
|
80
|
+
# method ALWAYS returns the last known ancestor given as `last_ancestor`, for
|
81
|
+
# compatibility reasons.
|
82
|
+
#
|
83
|
+
# @param identifier [String] identifier of the category
|
84
|
+
# @param last_ancestor [Class] expected ancestor
|
85
|
+
# @return [Class] pre-defined class or given last ancestor
|
86
|
+
def klass(identifier, last_ancestor)
|
87
|
+
found_last_ancestor = self.class.klass_map[identifier]
|
88
|
+
if found_last_ancestor && !found_last_ancestor.ancestors.include?(last_ancestor)
|
89
|
+
raise Occi::Core::Errors::InstanceValidationError,
|
90
|
+
"#{found_last_ancestor.inspect} is not a sub-type of #{last_ancestor.inspect}"
|
91
|
+
end
|
92
|
+
found_last_ancestor || last_ancestor
|
93
|
+
end
|
94
|
+
|
95
|
+
# Looks up the given identifier in the model. Returns `Occi::Core::Kind` instance if
|
96
|
+
# found and raises an error otherwise. Look-up results not related to `Occi::Core::Kind`
|
97
|
+
# will also raise an error.
|
98
|
+
#
|
99
|
+
# @param identifier [String] identifier of the category
|
100
|
+
# @return [Occi::Core::Kind] full category definition from the model
|
101
|
+
def kind(identifier)
|
102
|
+
kind = model.find_by_identifier!(identifier)
|
103
|
+
unless kind.is_a? Occi::Core::Kind
|
104
|
+
raise Occi::Core::Errors::CategoryValidationError, "#{identifier.inspect} " \
|
105
|
+
'is not a kind'
|
106
|
+
end
|
107
|
+
kind
|
108
|
+
end
|
109
|
+
|
110
|
+
# Locates the closes known parent class for instances of the given kind.
|
111
|
+
# This usually means `Occi::Core::Resource`, `Occi::Core::Link`, or error.
|
112
|
+
#
|
113
|
+
# @param kind [Occi::Core::Kind] kind instance to evaluate
|
114
|
+
# @return [Class] located known parent class
|
115
|
+
def parent_klass(kind)
|
116
|
+
if kind.related? kind(Occi::Core::Constants::RESOURCE_KIND)
|
117
|
+
Occi::Core::Resource
|
118
|
+
elsif kind.related? kind(Occi::Core::Constants::LINK_KIND)
|
119
|
+
Occi::Core::Link
|
120
|
+
else
|
121
|
+
raise Occi::Core::Errors::ModelLookupError,
|
122
|
+
"Could not identify #{kind.identifier.inspect} as a Link or Resource"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class << self
|
127
|
+
# :nodoc:
|
128
|
+
def klass_map
|
129
|
+
{}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
# :nodoc:
|
136
|
+
def sufficient_args!(args)
|
137
|
+
return if args[:model]
|
138
|
+
raise Occi::Core::Errors::MandatoryArgumentError, 'model is a mandatory ' \
|
139
|
+
"argument for #{self.class}"
|
140
|
+
end
|
141
|
+
|
142
|
+
# :nodoc:
|
143
|
+
def defaults
|
144
|
+
{ model: nil }
|
145
|
+
end
|
146
|
+
|
147
|
+
# :nodoc:
|
148
|
+
def pre_initialize(args); end
|
149
|
+
|
150
|
+
# :nodoc:
|
151
|
+
def post_initialize(args); end
|
152
|
+
|
153
|
+
# :nodoc:
|
154
|
+
def args_with_kind(identifier, args)
|
155
|
+
k_args = args.clone
|
156
|
+
k_args[:kind] = kind(identifier)
|
157
|
+
k_args[:rel] = kind(k_args[:rel]) if k_args[:rel]
|
158
|
+
k_args
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|