diff options
author | 2017-01-31 13:57:24 +0100 | |
---|---|---|
committer | 2017-01-31 14:55:11 +0100 | |
commit | 2e984294ac28c6f2ede290c38164c5d536ccaf4a (patch) | |
tree | 5eba5a929b7a961c98749fa69e03cfea58e1a724 /openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneRoleCreate.java | |
parent | 86c0f28c8ed469486b64d6422dc53e3a7bcc8adb (diff) |
Initial OpenECOMP MSO OpenStack SDK lib commit
Change-Id: Ieaacb2b2c0dcc469669880e73f0cda9fa59a6c5a
Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneRoleCreate.java')
-rw-r--r-- | openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneRoleCreate.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneRoleCreate.java b/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneRoleCreate.java new file mode 100644 index 0000000..2acdd76 --- /dev/null +++ b/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneRoleCreate.java @@ -0,0 +1,69 @@ +package com.woorea.openstack.console.keystone; + +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Options; + +import com.woorea.openstack.console.utils.Column; +import com.woorea.openstack.console.utils.Table; +import com.woorea.openstack.console.utils.TableModel; +import com.woorea.openstack.keystone.Keystone; +import com.woorea.openstack.keystone.model.Role; + +public class KeystoneRoleCreate extends KeystoneCommand { + + public KeystoneRoleCreate() { + super( "role-create"); + } + + @Override + public void execute(Keystone keystone, CommandLine cmd) { + + Role role = new Role(); + role.setName(cmd.getOptionValue("name")); + role.setDescription(cmd.getOptionValue("description")); + if(cmd.getOptionValue("enabled") != null) { + role.setEnabled("True"); + } + + role = keystone.roles().create(role).execute(); + + Table t = new Table(new TableModel<Role>(Arrays.asList(role)) { + + @Override + public Column[] getHeaders() { + return new Column[]{ + new Column("id", 32, Column.ALIGN_LEFT), + new Column("name", 10, Column.ALIGN_LEFT), + new Column("description", 32, Column.ALIGN_LEFT), + new Column("enabled", 7, Column.ALIGN_LEFT) + }; + } + + @Override + public String[] getRow(Role tenant) { + return new String[]{ + tenant.getId(), + tenant.getName(), + tenant.getDescription(), + tenant.getEnabled().toString() + }; + } + }); + System.out.println(t.render()); + } + + /* (non-Javadoc) + * @see com.billingstack.commands.Command#getOptions() + */ + @Override + public Options getOptions() { + Options opts = super.getOptions(); + opts.addOption(null, "name", true, "tenant name"); + opts.addOption(null, "description", true, "tenant description"); + opts.addOption(null, "enabled", false, "enabled"); + return opts; + } + +} |