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,156 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
module Parsers
|
4
|
+
module Json
|
5
|
+
# Static parsing class responsible for extracting entities from JSON.
|
6
|
+
# Class supports 'application/json' via `json`. No other formats are supported.
|
7
|
+
#
|
8
|
+
# @attr model [Occi::Core::Model, Occi::Infrastructure::Model] model to use as a primary reference point
|
9
|
+
#
|
10
|
+
# @author Boris Parak <parak@cesnet.cz>
|
11
|
+
class Entity
|
12
|
+
include Yell::Loggable
|
13
|
+
include Helpers::ArgumentValidator
|
14
|
+
include Helpers::ErrorHandler
|
15
|
+
extend Helpers::RawJsonParser
|
16
|
+
|
17
|
+
# Constants
|
18
|
+
SINGLE_INSTANCE_TYPES = %i[resource link].freeze
|
19
|
+
MULTI_INSTANCE_TYPES = %i[entity-collection].freeze
|
20
|
+
|
21
|
+
TYPECASTER_HASH = {
|
22
|
+
IPAddr => ->(val) { IPAddr.new val },
|
23
|
+
URI => ->(val) { URI.parse val },
|
24
|
+
Float => ->(val) { val.to_f },
|
25
|
+
Integer => ->(val) { val.to_i }
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
attr_reader :model
|
29
|
+
|
30
|
+
# Constructs an instance of the entity parser. Only entities (their kinds) defined by the model are allowed.
|
31
|
+
#
|
32
|
+
# @param args [Hash] constructor arguments in a Hash
|
33
|
+
# @option args [Occi::Core::Model] :model model to use as a primary reference point
|
34
|
+
def initialize(args = {})
|
35
|
+
pre_initialize(args)
|
36
|
+
default_args! args
|
37
|
+
|
38
|
+
@model = args.fetch(:model)
|
39
|
+
|
40
|
+
post_initialize(args)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Builds an entity instances from the lines provided as input.
|
44
|
+
#
|
45
|
+
# @param body [String] JSON body for parsing
|
46
|
+
# @param type [Symbol] `:resource`, `:link`, or `:'entity-collection'`
|
47
|
+
# @return [Array] constructed instances
|
48
|
+
def json(body, type)
|
49
|
+
case type
|
50
|
+
when *SINGLE_INSTANCE_TYPES
|
51
|
+
json_single self.class.raw_hash(body)
|
52
|
+
when *MULTI_INSTANCE_TYPES
|
53
|
+
json_collection self.class.raw_hash(body)
|
54
|
+
else
|
55
|
+
raise Occi::Core::Errors::ParserError, "#{self.class} -> #{type.to_s.inspect} is not a valid type"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Builds an entity instance from the hash provided as input.
|
60
|
+
#
|
61
|
+
# @param hash [Hash] Hash body for parsing
|
62
|
+
# @return [Array] constructed instances
|
63
|
+
def json_single(hash)
|
64
|
+
instance = @_ib.get hash[:kind], mixins: lookup(hash[:mixins]), actions: lookup(hash[:actions])
|
65
|
+
|
66
|
+
set_attributes! instance.attributes, hash[:attributes]
|
67
|
+
set_links! instance.links, hash[:links] if instance.respond_to?(:links)
|
68
|
+
set_target! instance, hash[:target] if instance.respond_to?(:target)
|
69
|
+
|
70
|
+
Set.new [instance]
|
71
|
+
end
|
72
|
+
|
73
|
+
# Builds entity instances from the hash provided as input.
|
74
|
+
#
|
75
|
+
# @param hash [Hash] Hash body for parsing
|
76
|
+
# @return [Array] constructed instances
|
77
|
+
def json_collection(hash)
|
78
|
+
all = []
|
79
|
+
|
80
|
+
all.concat hash[:resources] if hash[:resources]
|
81
|
+
all.concat hash[:links] if hash[:links]
|
82
|
+
all.map! { |a| json_single(a) }
|
83
|
+
|
84
|
+
Set.new(all).flatten
|
85
|
+
end
|
86
|
+
|
87
|
+
# :nodoc:
|
88
|
+
def lookup(ary)
|
89
|
+
set = Set.new
|
90
|
+
return set if ary.blank?
|
91
|
+
ary.each { |i| set << handle(Occi::Core::Errors::ParsingError) { model.find_by_identifier!(i) } }
|
92
|
+
set
|
93
|
+
end
|
94
|
+
|
95
|
+
# :nodoc:
|
96
|
+
def set_attributes!(attributes, hash)
|
97
|
+
return if hash.blank?
|
98
|
+
hash.each_pair do |name, value|
|
99
|
+
attribute = attributes[name.to_s]
|
100
|
+
unless attribute
|
101
|
+
raise Occi::Core::Errors::ParsingError,
|
102
|
+
"#{self.class} -> attribute #{name.to_s.inspect} is not allowed for this entity"
|
103
|
+
end
|
104
|
+
attribute.value = typecast(value, attribute.attribute_definition.type)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def set_links!(links, ary)
|
109
|
+
return if ary.blank?
|
110
|
+
ary.each { |l| links << json_single(l).first }
|
111
|
+
end
|
112
|
+
|
113
|
+
# :nodoc:
|
114
|
+
def set_target!(link, hash)
|
115
|
+
return unless link.respond_to?(:target_kind)
|
116
|
+
return if hash.blank? || hash[:kind].blank?
|
117
|
+
|
118
|
+
link.target_kind = lookup([hash[:kind]]).first
|
119
|
+
end
|
120
|
+
|
121
|
+
# :nodoc:
|
122
|
+
def typecast(value, type)
|
123
|
+
if value.nil? || type.nil?
|
124
|
+
raise Occi::Core::Errors::ParsingError,
|
125
|
+
"#{self.class} -> Cannot typecast (un)set value to (un)set type"
|
126
|
+
end
|
127
|
+
return value unless TYPECASTER_HASH.key?(type)
|
128
|
+
|
129
|
+
TYPECASTER_HASH[type].call(value)
|
130
|
+
end
|
131
|
+
|
132
|
+
protected
|
133
|
+
|
134
|
+
# :nodoc:
|
135
|
+
def sufficient_args!(args)
|
136
|
+
return if args[:model]
|
137
|
+
raise Occi::Core::Errors::MandatoryArgumentError, "Model is a mandatory argument for #{self.class}"
|
138
|
+
end
|
139
|
+
|
140
|
+
# :nodoc:
|
141
|
+
def defaults
|
142
|
+
{ model: nil }
|
143
|
+
end
|
144
|
+
|
145
|
+
# :nodoc:
|
146
|
+
def pre_initialize(args); end
|
147
|
+
|
148
|
+
# :nodoc:
|
149
|
+
def post_initialize(_args)
|
150
|
+
@_ib = model.instance_builder
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
File without changes
|
@@ -0,0 +1,277 @@
|
|
1
|
+
{
|
2
|
+
"id": "occi-schema.json",
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
4
|
+
"title": "OCCI v1.2 JSON Rendering Schema",
|
5
|
+
"definitions": {
|
6
|
+
"kinded_uri": {
|
7
|
+
"id": "#kinded_uri",
|
8
|
+
"type": "object",
|
9
|
+
"required": ["location"],
|
10
|
+
"additionalProperties": false,
|
11
|
+
"properties": {
|
12
|
+
"location": { "type": "string" },
|
13
|
+
"kind": { "type": "string" }
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"resource": {
|
17
|
+
"id": "#resource",
|
18
|
+
"type": "object",
|
19
|
+
"required": ["kind", "id", "attributes"],
|
20
|
+
"additionalProperties": false,
|
21
|
+
"properties": {
|
22
|
+
"kind": { "type": "string" },
|
23
|
+
"mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
24
|
+
"attributes": { "$ref": "#/definitions/attributes" },
|
25
|
+
"actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
26
|
+
"id": { "type": "string" },
|
27
|
+
"links": {
|
28
|
+
"type": "array",
|
29
|
+
"minItems": 1,
|
30
|
+
"items": {
|
31
|
+
"$ref": "#/definitions/link"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"summary": { "type": "string" },
|
35
|
+
"title": { "type": "string" }
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"action_instance": {
|
39
|
+
"id": "#action_instance",
|
40
|
+
"type": "object",
|
41
|
+
"required": ["action"],
|
42
|
+
"additionalProperties": false,
|
43
|
+
"properties": {
|
44
|
+
"action": { "type": "string" },
|
45
|
+
"attributes": { "$ref": "#/definitions/attributes" }
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"link": {
|
49
|
+
"id": "#link",
|
50
|
+
"type": "object",
|
51
|
+
"required": ["kind", "id", "target", "source", "attributes"],
|
52
|
+
"additionalProperties": false,
|
53
|
+
"properties": {
|
54
|
+
"kind": { "type": "string" },
|
55
|
+
"mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
56
|
+
"attributes": { "$ref": "#/definitions/attributes" },
|
57
|
+
"actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
58
|
+
"id": { "type": "string" },
|
59
|
+
"source": { "$ref": "#/definitions/kinded_uri" },
|
60
|
+
"target": { "$ref": "#/definitions/kinded_uri" },
|
61
|
+
"title": { "type": "string" }
|
62
|
+
}
|
63
|
+
},
|
64
|
+
"kind": {
|
65
|
+
"id": "#kind",
|
66
|
+
"type": "object",
|
67
|
+
"required": ["term", "scheme", "location"],
|
68
|
+
"additionalProperties": false,
|
69
|
+
"properties": {
|
70
|
+
"term": { "type": "string" },
|
71
|
+
"scheme": { "type": "string" },
|
72
|
+
"title": { "type": "string" },
|
73
|
+
"attributes": { "$ref": "#/definitions/attribute_definitions" },
|
74
|
+
"actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
75
|
+
"parent": { "type": "string" },
|
76
|
+
"location": { "type": "string" }
|
77
|
+
}
|
78
|
+
},
|
79
|
+
"mixin": {
|
80
|
+
"id": "#mixin",
|
81
|
+
"type": "object",
|
82
|
+
"required": ["term", "scheme", "location"],
|
83
|
+
"additionalProperties": false,
|
84
|
+
"properties": {
|
85
|
+
"term": { "type": "string" },
|
86
|
+
"scheme": { "type": "string" },
|
87
|
+
"title": { "type": "string" },
|
88
|
+
"attributes": { "$ref": "#/definitions/attribute_definitions" },
|
89
|
+
"actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
90
|
+
"depends": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
91
|
+
"applies": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
|
92
|
+
"location": { "type": "string" }
|
93
|
+
}
|
94
|
+
},
|
95
|
+
"action": {
|
96
|
+
"id": "#action",
|
97
|
+
"type": "object",
|
98
|
+
"required": ["term", "scheme"],
|
99
|
+
"additionalProperties": false,
|
100
|
+
"properties": {
|
101
|
+
"term": { "type": "string" },
|
102
|
+
"scheme": { "type": "string" },
|
103
|
+
"title": { "type": "string" },
|
104
|
+
"attributes": { "$ref": "#/definitions/attribute_definitions" }
|
105
|
+
}
|
106
|
+
},
|
107
|
+
"resource_collection": {
|
108
|
+
"id": "#resource_collection",
|
109
|
+
"type": "object",
|
110
|
+
"required": ["resources"],
|
111
|
+
"additionalProperties": false,
|
112
|
+
"properties": {
|
113
|
+
"resources": {
|
114
|
+
"type": "array",
|
115
|
+
"minItems": 1,
|
116
|
+
"items": {
|
117
|
+
"$ref": "#/definitions/resource"
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
},
|
122
|
+
"link_collection": {
|
123
|
+
"id": "#link_collection",
|
124
|
+
"type": "object",
|
125
|
+
"required": ["links"],
|
126
|
+
"additionalProperties": false,
|
127
|
+
"properties": {
|
128
|
+
"links": {
|
129
|
+
"type": "array",
|
130
|
+
"minItems": 1,
|
131
|
+
"items": {
|
132
|
+
"$ref": "#/definitions/link"
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
},
|
137
|
+
"entity_collection": {
|
138
|
+
"id": "#entity_collection",
|
139
|
+
"type": "object",
|
140
|
+
"additionalProperties": false,
|
141
|
+
"properties": {
|
142
|
+
"resources": {
|
143
|
+
"type": "array",
|
144
|
+
"minItems": 1,
|
145
|
+
"items": {
|
146
|
+
"$ref": "#/definitions/resource"
|
147
|
+
}
|
148
|
+
},
|
149
|
+
"links": {
|
150
|
+
"type": "array",
|
151
|
+
"minItems": 1,
|
152
|
+
"items": {
|
153
|
+
"$ref": "#/definitions/link"
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
},
|
158
|
+
"kind_collection": {
|
159
|
+
"id": "#kind_collection",
|
160
|
+
"type": "object",
|
161
|
+
"required": ["kinds"],
|
162
|
+
"additionalProperties": false,
|
163
|
+
"properties": {
|
164
|
+
"kinds": {
|
165
|
+
"type": "array",
|
166
|
+
"minItems": 1,
|
167
|
+
"items": {
|
168
|
+
"$ref": "#/definitions/kind"
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
},
|
173
|
+
"mixin_collection": {
|
174
|
+
"id": "#mixin_collection",
|
175
|
+
"type": "object",
|
176
|
+
"required": ["mixins"],
|
177
|
+
"additionalProperties": false,
|
178
|
+
"properties": {
|
179
|
+
"mixins": {
|
180
|
+
"type": "array",
|
181
|
+
"minItems": 1,
|
182
|
+
"items": {
|
183
|
+
"$ref": "#/definitions/mixin"
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
},
|
188
|
+
"action_collection": {
|
189
|
+
"id": "#action_collection",
|
190
|
+
"type": "object",
|
191
|
+
"required": ["actions"],
|
192
|
+
"additionalProperties": false,
|
193
|
+
"properties": {
|
194
|
+
"actions": {
|
195
|
+
"type": "array",
|
196
|
+
"minItems": 1,
|
197
|
+
"items": {
|
198
|
+
"$ref": "#/definitions/action"
|
199
|
+
}
|
200
|
+
}
|
201
|
+
}
|
202
|
+
},
|
203
|
+
"attributes": {
|
204
|
+
"id": "#attributes",
|
205
|
+
"type": "object",
|
206
|
+
"additionalProperties": {
|
207
|
+
"oneOf": [
|
208
|
+
{ "type": "number" },
|
209
|
+
{ "type": "boolean" },
|
210
|
+
{ "type": "string" },
|
211
|
+
{ "type": "object" },
|
212
|
+
{ "type": "array" }
|
213
|
+
]
|
214
|
+
}
|
215
|
+
},
|
216
|
+
"attribute_definition": {
|
217
|
+
"id": "#attribute_definition",
|
218
|
+
"type": "object",
|
219
|
+
"additionalProperties": false,
|
220
|
+
"required": ["type", "mutable", "required"],
|
221
|
+
"properties": {
|
222
|
+
"mutable": { "type": "boolean" },
|
223
|
+
"required": { "type": "boolean" },
|
224
|
+
"type": { "type": "string" },
|
225
|
+
"default": {
|
226
|
+
"oneOf": [
|
227
|
+
{ "type": "number" },
|
228
|
+
{ "type": "string" },
|
229
|
+
{ "type": "boolean" },
|
230
|
+
{ "type": "object" },
|
231
|
+
{ "type": "array" }
|
232
|
+
]
|
233
|
+
},
|
234
|
+
"description": { "type": "string" },
|
235
|
+
"pattern": { "type": "string" }
|
236
|
+
}
|
237
|
+
},
|
238
|
+
"attribute_definitions": {
|
239
|
+
"id": "#attribute_definitions",
|
240
|
+
"type": "object",
|
241
|
+
"additionalProperties": false,
|
242
|
+
"patternProperties": {
|
243
|
+
".+": {
|
244
|
+
"$ref": "#/definitions/attribute_definition"
|
245
|
+
}
|
246
|
+
}
|
247
|
+
},
|
248
|
+
"model": {
|
249
|
+
"id": "#model",
|
250
|
+
"type": "object",
|
251
|
+
"additionalProperties": false,
|
252
|
+
"properties": {
|
253
|
+
"mixins": {
|
254
|
+
"type": "array",
|
255
|
+
"minItems": 1,
|
256
|
+
"items": {
|
257
|
+
"$ref": "#/definitions/mixin"
|
258
|
+
}
|
259
|
+
},
|
260
|
+
"kinds": {
|
261
|
+
"type": "array",
|
262
|
+
"minItems": 1,
|
263
|
+
"items": {
|
264
|
+
"$ref": "#/definitions/kind"
|
265
|
+
}
|
266
|
+
},
|
267
|
+
"actions": {
|
268
|
+
"type": "array",
|
269
|
+
"minItems": 1,
|
270
|
+
"items": {
|
271
|
+
"$ref": "#/definitions/action"
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
module Parsers
|
4
|
+
module Json
|
5
|
+
# Class responsible for validating JSON content before parsing. This should be called from
|
6
|
+
# every parsing class.
|
7
|
+
#
|
8
|
+
# @author Boris Parak <parak@cesnet.cz>
|
9
|
+
class Validator
|
10
|
+
# Repository constants
|
11
|
+
SCHEMA_DIR = 'validator'.freeze
|
12
|
+
SCHEMA_REPO = File.join(File.expand_path(File.dirname(__FILE__)), SCHEMA_DIR)
|
13
|
+
BASE_SCHEMAS = %i[occi-schema].freeze
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Validates given `json` text with the appropriate schema for `type`.
|
17
|
+
# This method raises `Occi::Core::Errors::ParsingError` on failure.
|
18
|
+
#
|
19
|
+
# @param json [String] JSON text to validate
|
20
|
+
# @param type [Symbol] schema selector
|
21
|
+
# @raise [Occi::Core::Errors::ParsingError] on validation failure
|
22
|
+
def validate!(json, type)
|
23
|
+
JSON::Validator.schema_reader = JSON::Schema::Reader.new(accept_uri: false, accept_file: true)
|
24
|
+
JSON::Validator.validate!(schema_for(type), json, json: true)
|
25
|
+
rescue JSON::Schema::JsonParseError, JSON::Schema::ValidationError => e
|
26
|
+
raise Occi::Core::Errors::ParsingError, "#{self} -> #{e.message}"
|
27
|
+
end
|
28
|
+
|
29
|
+
# :nodoc:
|
30
|
+
def validate_model!(json)
|
31
|
+
validate! json, :model
|
32
|
+
end
|
33
|
+
|
34
|
+
# :nodoc:
|
35
|
+
def validate_resource!(json)
|
36
|
+
validate! json, :resource
|
37
|
+
end
|
38
|
+
|
39
|
+
# :nodoc:
|
40
|
+
def validate_link!(json)
|
41
|
+
validate! json, :link
|
42
|
+
end
|
43
|
+
|
44
|
+
# :nodoc:
|
45
|
+
def validate_action_instance!(json)
|
46
|
+
validate! json, :'action-instance'
|
47
|
+
end
|
48
|
+
|
49
|
+
# :nodoc:
|
50
|
+
def validate_entity_collection!(json)
|
51
|
+
validate! json, :'entity-collection'
|
52
|
+
end
|
53
|
+
|
54
|
+
# :nodoc:
|
55
|
+
def validate_link_collection!(json)
|
56
|
+
validate! json, :'link-collection'
|
57
|
+
end
|
58
|
+
|
59
|
+
# :nodoc:
|
60
|
+
def validate_resource_collection!(json)
|
61
|
+
validate! json, :'resource-collection'
|
62
|
+
end
|
63
|
+
|
64
|
+
# :nodoc:
|
65
|
+
def validate_mixin_collection!(json)
|
66
|
+
validate! json, :'mixin-collection'
|
67
|
+
end
|
68
|
+
|
69
|
+
# :nodoc:
|
70
|
+
def validate_locations!(json)
|
71
|
+
validate! json, :locations
|
72
|
+
end
|
73
|
+
|
74
|
+
# :nodoc:
|
75
|
+
def schema_for(type)
|
76
|
+
if type.blank? || BASE_SCHEMAS.include?(type)
|
77
|
+
raise Occi::Core::Errors::ParserError, "Schema type #{type.inspect} is not allowed"
|
78
|
+
end
|
79
|
+
File.join(SCHEMA_REPO, "#{type}.json")
|
80
|
+
end
|
81
|
+
private :schema_for
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|