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 domains and subnets as puppet resources that interact with the Foreman API #1047

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rjemanuele
Copy link

@rjemanuele rjemanuele commented May 3, 2022

This will add support for creating domains and subnets within Foreman using Foreman's API from Puppet.

This also adds the ability to lookup IDs for some values with a "search=" string.

foreman_domain { "test.example.com":
      ensure          => present,
      base_url        => $foreman::foreman_url,
      consumer_key    => $foreman::oauth_consumer_key,
      consumer_secret => $foreman::oauth_consumer_secret,
      effective_user  => $foreman::oauth_effective_user,
      ssl_ca          => $foreman::server_ssl_chain,
      dns_id          => "search=$lower_fqdn",
    }
foreman_subnet { "192.168.1.0":
      ensure          => present,
      base_url        => $foreman::foreman_url,
      consumer_key    => $foreman::oauth_consumer_key,
      consumer_secret => $foreman::oauth_consumer_secret,
      effective_user  => $foreman::oauth_effective_user,
      ssl_ca          => $foreman::server_ssl_chain,
      network_type    => 'IPv4',
      network         => "192.168.1.0",
      cidr            => 24,
      mask            => "255.255.255.0",
      domain_ids      => [ "search=test.example.com" ],
      dhcp_id         => "search=$lower_fqdn",
      tftp_id         => "search=$lower_fqdn",
      httpboot_id     => "search=$lower_fqdn",
      dns_id          => "search=$lower_fqdn",
      bmc_id          => "search=$lower_fqdn",
}

@rjemanuele rjemanuele marked this pull request as ready for review May 23, 2022 04:56
@rjemanuele rjemanuele changed the title Add domains to the puppet API Add domains and subnets as puppet resources that interact with the Foreman API May 23, 2022
@ekohl
Copy link
Member

ekohl commented Aug 3, 2022

Looks like CI didn't ran. Could you rebase?

@ekohl
Copy link
Member

ekohl commented Nov 1, 2022

@rjemanuele I'd still be interested in getting this in. Could you rebase this?

@rjemanuele
Copy link
Author

Rebased :)

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments, but otherwise I think this looks good.

Comment on lines +136 to +138
if !value.nil? and value.start_with?("search=") then
lookup_uri = "api/v2/" + id_name + "?" + value
lookup = request(:get, lookup_uri)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this creates some redundancy. We already have request which accepts a params hash so if anything this should pass search as a hash. That properly escapes it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekohl is there an example of using request I could have a look at to test with and make sure this works with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

desc 'foreman_domain creates a domain in foreman.'

instance_eval(&PuppetX::Foreman::Common::REST_API_COMMON_PARAMS)
instance_eval(&PuppetX::Foreman::Common::FOREMAN_DOMAIN_PARAMS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're not reusing these (and it looks like you're not), it's better to inline them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me out here with what you're looking for? I'm more of a C, C++, Python programmer, very new to Ruby.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request is to move the methods being generated by PuppetX::Foreman::Common::FOREMAN_DOMAIN_PARAMS directly into this file on the foreman_domain type instead of the extra layer of meta-programming since there isn't another type which will reuse these methods.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stated another way, the methods in lib/puppet_x/foreman/common.rb should be moved into foreman_*/rest_v3.rb.

desc 'foreman_subnet creates a subnet in foreman.'

instance_eval(&PuppetX::Foreman::Common::REST_API_COMMON_PARAMS)
instance_eval(&PuppetX::Foreman::Common::FOREMAN_SUBNET_PARAMS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be inlined, like domain.

@jhoblitt
Copy link
Contributor

@rjemanuele Are you planning to take this over the finish line? I'm interested in these types as well.

@rjemanuele
Copy link
Author

@jhoblitt Sure, I'll get this cleaned up and ready in the next week.

@jhoblitt
Copy link
Contributor

@rjemanuele Great. Let me know if plans change and I'll try to pickup the ball.

@jhoblitt
Copy link
Contributor

@rjemanuele Are you still stuck?

@jhoblitt
Copy link
Contributor

@rjemanuele ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants