Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openstack client refactored api #6

Merged
merged 4 commits into from
May 11, 2015

Conversation

vmoravec
Copy link

@vmoravec vmoravec commented May 6, 2015

Improvements:

  • the openstackclient commands are DRY now
  • command definition is more transparent
  • add optional and mandatory (default) params
  • add properties params
  • add named params with property type

Example for openstack user command implementation:

      class User < Command
        self.command = "user"
        # commands like #delete, #show, #list are used from the parent
        def create name, options={}
          super do |params|
            params.add :optional, password: "--password"
            params.add :optional, email:    "--email"
            params.add :optional, project:  "--project"
            params.add :optional, enable:   "--enable",  param_type: :switch
            params.add :optional, disable:  "--disable", param_type: :switch
          end
        end

      end

Example for openstack.image command:

      class Image < Command
        self.command = "image"

        def create name, options={}
          super do |params|
            # mandatory params
            params.add container_format: "--container-format"
            params.add disk_format:      "--disk-format"

            # optional params
            params.add :optional, copy_from: "--copy-from"
            params.add :optional, location: "--location"
            params.add :optional, public: "--public", param_type: :switch
            params.add :optional, private: "--private", param_type: :switch

            # properties: will be transformed into --property hypervisor_type=kvm
            params.add :property, hypervisor_type: "hypervisor_type"
            params.add :property, vm_mode: "vm_mode"

            # fallback to all properties defined at once
            params.add :properties, param_type: :properties
          end
        end

      end

Additionally I added a method which tests existence of an asset without raising an exception (all the methods raise error e.g. deleting a non-existent user):

control_node.openstack.user.exist?("admin") # returns true or false

vmoravec pushed a commit that referenced this pull request May 11, 2015
Add openstack client refactored api
@vmoravec vmoravec merged commit d7ca9fb into SUSE-Cloud:master May 11, 2015
@vmoravec vmoravec deleted the refactor-openstack-client branch June 16, 2015 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant