我的目的:我只想通过我编写的java程序,从具有特定CPU/RAM/硬盘容量的模板创建一个CentOS虚拟机。
我做的事情:Foreman 1.7.1 +(无集群修复问题/1945)+为vmware添加计算资源
我可以使用以下配置通过 Web UI 创建主机: 名称: 测试基于CentOsImageBased 无主机组 部署于:cmptrsrc_VMWare (VMWare) 环境:生产 没有傀儡 CA 没有傀儡师
域
:本地域
建筑:x86_64 操作系统: CentOS 6.5 预配方法:基于映像 (CentOs6_5img)
根据 API v2,我按如下方式设置了主机配置:
host.setName("CGCentOs");
host.setEnvironmentId("1");
host.setDomainId("1");
host.setArchitectureId("1");
host.setOperatingsystemId("1");
host.setComputeResourceId("1");
我使用 http://www.jsonschema2pojo.org/生成 java pojos(我稍微更改生成的文件,就像我删除@JsonInclude(JsonInclude.Include.NON_NULL))和@JsonPropertyOrder部分,我也使用org.codehaus.jackson),我的代码基于这个项目 https://github.com/muconsulting/foreman-java-sdk
我曾经毫无错误地获得/发布很多请求,所以我认为这部分没有任何问题
当我尝试使用上述配置创建我的主机时,尾随生产.log会给出: 不允许domain_id作为主机的嵌套参数
所以我试图摆脱使用domain_id,主机组可以指定domain_id,所以我创建了一个具有特定环境的主机组:
Host host = new Host();
host.setName("CGCentOs");
host.setHostgroupId(1);
host.setDomainId(1);
host.setArchitectureId(1);
host.setOperatingsystemId(1);
host.setComputeResourceId(1);
它给出:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "domain_id"=>1, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "domain_id"=>1, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1}}
Expire fragment views/tabs_and_title_records-3 (0.1ms)
Authorized user admin(Admin User)
domain_id is not allowed as nested parameter for hosts. Allowed parameters are hostgroup_id, location_id, organization_id, environment_id (RuntimeError)
所以我也在主机组中指定domain_id,它变成了
2.具有特定环境和domain_id的主机组
Host host = new Host();
host.setName("CGCentOs");
host.setHostgroupId(1);
host.setArchitectureId(1);
host.setOperatingsystemId(1);
host.setComputeResourceId(1);
它给出:
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1}}
Authorized user admin(Admin User)
architecture_id is not allowed as nested parameter for hosts. Allowed parameters are hostgroup_id, location_id, organization_id, environment_id (RuntimeError)
我向主机组添加architecture_id
主机主机 = 新主机();host.setName("CGCentOs");host.setHostgroupId(1);
host.setOperatingsystemId(1);host.setComputeResourceId(1);
它给出:
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1}}
Authorized user admin(Admin User)
operatingsystem_id is not allowed as nested parameter for hosts. Allowed parameters are hostgroup_id, location_id, organization_id, environment_id (RuntimeError)
我将operatingsystem_id添加到主机组。
主机主机 = 新主机();host.setName("CGCentOs");host.setHostgroupId(1);
host.setComputeResourceId(1);
它给出:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "hostgroup_id"=>1, "compute_resource_id"=>1}}
Expire fragment views/tabs_and_title_records-3 (0.6ms)
Authorized user admin(Admin User)
compute_resource_id is not allowed as nested parameter for hosts. Allowed parameters are hostgroup_id, location_id, organization_id, environment_id (RuntimeError)
我无法将compute_resource ID 添加到主机组...我只是删除了这条线...
主机主机 = 新主机();host.setName("CGCentOs");host.setHostgroupId(1);
它给出:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "hostgroup_id"=>1}}
Authorized user admin(Admin User)
Unprocessable entity Host::Managed (id: new):
MAC address is not a valid MAC address
MAC address can't be blank
Partition Table cant be blank unless a custom partition has been defined
我期待这一点,因为,coumpute 资源定义了它的虚拟性......因此,计算配置文件和计算资源似乎很紧密
我试试这个:
Host host = new Host();
host.setName("CGCentOs");
host.setHostgroupId(1);
host.setComputeProfileId(3);
它给出:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1, "compute_profile_id"=>3, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "hostgroup_id"=>1, "compute_profile_id"=>3}}
Authorized user admin(Admin User)
compute_profile_id is not allowed as nested parameter for hosts. Allowed parameters are hostgroup_id, location_id, organization_id, environment_id (RuntimeError)
我创建了一个新的计算配置文件,它出现在编辑 hos 组窗格中...所以重试:
Host host = new Host();
host.setName("CGCentOs");
host.setHostgroupId(1);
再次MAC地址问题:
Processing by Api::V2::HostsController#create as JSON
Parameters: {"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "hostgroup_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "hostgroup_id"=>1}}
Expire fragment views/tabs_and_title_records-3 (0.1ms)
Authorized user admin(Admin User)
Unprocessable entity Host::Managed (id: new):
MAC address is not a valid MAC address
MAC address can't be blank
Partition Table cant be blank unless a custom partition has been defined
除了拉开发分支之外,还有其他解决方法吗?提前谢谢你
您的 JSON 目前如下所示:
{"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "domain_id"=>1, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "domain_id"=>1, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1}}
但必须是:
{"host"=>{"name"=>"CGCentOs", "capabilities"=>nil, "parameters"=>nil, "interfaces"=>nil, "puppetclasses"=>nil, "domain_id"=>1, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1, "all_puppetclasses"=>nil, "config_groups"=>nil, "apiv"=>"v2", :host=>{"name"=>"CGCentOs", "domain_id"=>1, "architecture_id"=>1, "operatingsystem_id"=>1, "hostgroup_id"=>1, "compute_resource_id"=>1}}}
原因是,工头中包含一个名为"host"的新键值对 1.7.x.It 原因是 API 从工头 1.6.x 更改为 1.7.x
干杯克里斯