summaryrefslogtreecommitdiffstats
path: root/openstack-console/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openstack-console/src/main')
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneUserShow.java70
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaCommand.java26
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaEnvironment.java98
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaServerList.java60
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java100
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java84
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java150
-rw-r--r--openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java36
8 files changed, 312 insertions, 312 deletions
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneUserShow.java b/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneUserShow.java
index 95b93fc..c7a8a6e 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneUserShow.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/keystone/KeystoneUserShow.java
@@ -27,43 +27,43 @@ import com.woorea.openstack.keystone.Keystone;
import com.woorea.openstack.keystone.model.User;
public class KeystoneUserShow extends KeystoneCommand {
-
- public KeystoneUserShow() {
- super("user-show");
- }
+
+ public KeystoneUserShow() {
+ super("user-show");
+ }
- @Override
- public void execute(Keystone keystone, CommandLine cmd) {
-
- String[] args = cmd.getArgs();
- if(args.length == 1) {
- User user = keystone.users().show(args[0]).execute();
- Table t = new Table(new TableModel<User>(Arrays.asList(user)) {
+ @Override
+ public void execute(Keystone keystone, CommandLine cmd) {
+
+ String[] args = cmd.getArgs();
+ if(args.length == 1) {
+ User user = keystone.users().show(args[0]).execute();
+ Table t = new Table(new TableModel<User>(Arrays.asList(user)) {
- @Override
- public Column[] getHeaders() {
- return new Column[]{
- new Column("id", 32, Column.ALIGN_LEFT),
- new Column("name", 10, Column.ALIGN_LEFT),
- new Column("email", 22, Column.ALIGN_LEFT),
- new Column("tenant", 32, Column.ALIGN_LEFT),
- new Column("enabled", 7, Column.ALIGN_LEFT)
- };
- }
+ @Override
+ public Column[] getHeaders() {
+ return new Column[]{
+ new Column("id", 32, Column.ALIGN_LEFT),
+ new Column("name", 10, Column.ALIGN_LEFT),
+ new Column("email", 22, Column.ALIGN_LEFT),
+ new Column("tenant", 32, Column.ALIGN_LEFT),
+ new Column("enabled", 7, Column.ALIGN_LEFT)
+ };
+ }
- @Override
- public String[] getRow(User user) {
- return new String[]{
- user.getId(),
- user.getName(),
- user.getEmail(),
- user.getTenantId(),
- user.getEnabled().toString()
- };
- }
- });
- System.out.println(t.render());
- }
- }
+ @Override
+ public String[] getRow(User user) {
+ return new String[]{
+ user.getId(),
+ user.getName(),
+ user.getEmail(),
+ user.getTenantId(),
+ user.getEnabled().toString()
+ };
+ }
+ });
+ System.out.println(t.render());
+ }
+ }
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaCommand.java b/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaCommand.java
index 11366fd..a45c51d 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaCommand.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaCommand.java
@@ -24,18 +24,18 @@ import com.woorea.openstack.nova.Nova;
public abstract class NovaCommand extends Command {
-
- public NovaCommand(String name) {
- super(name);
- }
-
- @Override
- public void execute(Console console, CommandLine args) {
- NovaEnvironment environment = (NovaEnvironment) console.getEnvironment();
- execute(environment.CLIENT, args);
-
- }
-
- protected abstract void execute(Nova nova, CommandLine args);
+
+ public NovaCommand(String name) {
+ super(name);
+ }
+
+ @Override
+ public void execute(Console console, CommandLine args) {
+ NovaEnvironment environment = (NovaEnvironment) console.getEnvironment();
+ execute(environment.CLIENT, args);
+
+ }
+
+ protected abstract void execute(Nova nova, CommandLine args);
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaEnvironment.java b/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaEnvironment.java
index 2bf4a43..0f8f07c 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaEnvironment.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaEnvironment.java
@@ -28,54 +28,54 @@ import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
import com.woorea.openstack.nova.Nova;
public class NovaEnvironment extends Environment {
-
- public final Nova CLIENT;
-
- public static final Command NOVA = new Command("nova") {
-
- @Override
- public void execute(Console console, CommandLine args) {
-
- if(args.getArgs().length == 1) {
- Keystone keystone = new Keystone((String) console.getProperty("keystone.endpoint"));
-
- Access access = keystone.tokens().authenticate(
- new UsernamePassword(
- console.getProperty("keystone.username"),
- console.getProperty("keystone.password")
- )
- )
- .withTenantName(console.getProperty("keystone.tenant_name"))
- .execute();
-
- System.out.println(console.getProperty("nova.endpoint"));
-
- Nova client = new Nova(console.getProperty("nova.endpoint")+args.getArgs()[0]);
- client.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));
-
- NovaEnvironment environment = new NovaEnvironment(console.getEnvironment(), client);
-
- environment.register(new NovaServerList());
-
- console.setEnvironment(environment);
-
- }
-
- }
-
- };
-
- public NovaEnvironment(Environment parent, Nova client) {
- super(parent);
- CLIENT = client;
- }
+
+ public final Nova CLIENT;
+
+ public static final Command NOVA = new Command("nova") {
+
+ @Override
+ public void execute(Console console, CommandLine args) {
+
+ if(args.getArgs().length == 1) {
+ Keystone keystone = new Keystone((String) console.getProperty("keystone.endpoint"));
+
+ Access access = keystone.tokens().authenticate(
+ new UsernamePassword(
+ console.getProperty("keystone.username"),
+ console.getProperty("keystone.password")
+ )
+ )
+ .withTenantName(console.getProperty("keystone.tenant_name"))
+ .execute();
+
+ System.out.println(console.getProperty("nova.endpoint"));
+
+ Nova client = new Nova(console.getProperty("nova.endpoint")+args.getArgs()[0]);
+ client.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));
+
+ NovaEnvironment environment = new NovaEnvironment(console.getEnvironment(), client);
+
+ environment.register(new NovaServerList());
+
+ console.setEnvironment(environment);
+
+ }
+
+ }
+
+ };
+
+ public NovaEnvironment(Environment parent, Nova client) {
+ super(parent);
+ CLIENT = client;
+ }
- /* (non-Javadoc)
- * @see org.woorea.wsh.Environment#getPrompt()
- */
- @Override
- public String getPrompt() {
- return "nova> ";
- }
-
+ /* (non-Javadoc)
+ * @see org.woorea.wsh.Environment#getPrompt()
+ */
+ @Override
+ public String getPrompt() {
+ return "nova> ";
+ }
+
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaServerList.java b/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaServerList.java
index 4e210c8..8f8f20c 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaServerList.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/nova/NovaServerList.java
@@ -26,35 +26,35 @@ import com.woorea.openstack.nova.model.Server;
import com.woorea.openstack.nova.model.Servers;
public class NovaServerList extends NovaCommand {
-
- public NovaServerList() {
- super("list");
- }
-
- @Override
- public void execute(Nova nova, CommandLine cmd) {
-
- final Servers servers = nova.servers().list(true).execute();
-
- Table t = new Table(new TableModel<Server>(servers.getList()) {
-
- @Override
- public Column[] getHeaders() {
- return new Column[]{
- new Column("id", 32, Column.ALIGN_LEFT),
- new Column("name", 10, Column.ALIGN_LEFT)
- };
- }
-
- @Override
- public String[] getRow(Server server) {
- return new String[]{
- server.getId(),
- server.getName()
- };
- }
- });
- System.out.println(t.render());
- }
+
+ public NovaServerList() {
+ super("list");
+ }
+
+ @Override
+ public void execute(Nova nova, CommandLine cmd) {
+
+ final Servers servers = nova.servers().list(true).execute();
+
+ Table t = new Table(new TableModel<Server>(servers.getList()) {
+
+ @Override
+ public Column[] getHeaders() {
+ return new Column[]{
+ new Column("id", 32, Column.ALIGN_LEFT),
+ new Column("name", 10, Column.ALIGN_LEFT)
+ };
+ }
+
+ @Override
+ public String[] getRow(Server server) {
+ return new String[]{
+ server.getId(),
+ server.getName()
+ };
+ }
+ });
+ System.out.println(t.render());
+ }
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java
index 588b252..755ac17 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/utils/Column.java
@@ -18,64 +18,64 @@ package com.woorea.openstack.console.utils;
public class Column {
- public static final int ALIGN_LEFT = -1;
- public static final int ALIGN_RIGHT = 1;
+ public static final int ALIGN_LEFT = -1;
+ public static final int ALIGN_RIGHT = 1;
- private String name;
-
- private int size;
-
- private int align;
+ private String name;
+
+ private int size;
+
+ private int align;
- public Column(String name, int size, int align) {
- super();
- this.name = name;
- this.size = size;
- this.align = align;
- }
+ public Column(String name, int size, int align) {
+ super();
+ this.name = name;
+ this.size = size;
+ this.align = align;
+ }
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
- /**
- * @return the size
- */
- public int getSize() {
- return size;
- }
+ /**
+ * @return the size
+ */
+ public int getSize() {
+ return size;
+ }
- /**
- * @param size the size to set
- */
- public void setSize(int size) {
- this.size = size;
- }
+ /**
+ * @param size the size to set
+ */
+ public void setSize(int size) {
+ this.size = size;
+ }
- /**
- * @return the align
- */
- public int getAlign() {
- return align;
- }
+ /**
+ * @return the align
+ */
+ public int getAlign() {
+ return align;
+ }
- /**
- * @param align the align to set
- */
- public void setAlign(int align) {
- this.align = align;
- }
+ /**
+ * @param align the align to set
+ */
+ public void setAlign(int align) {
+ this.align = align;
+ }
-
+
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java
index e38f66c..8166217 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/utils/ConsoleUtils.java
@@ -17,47 +17,47 @@
package com.woorea.openstack.console.utils;
public class ConsoleUtils {
-
- public static final String RED = "\u001B[31m";
-
- public static final String GREEN = "\u001B[32m";
-
- public static final String YELLOW = "\u001B[33m";
-
- public static final String END = "\u001B[0m";
-
- private StringBuilder sb = new StringBuilder();
-
- public ConsoleUtils append(String text) {
- sb.append(text);
- return this;
- }
-
- public ConsoleUtils red(String text) {
- sb.append(ConsoleUtils.RED).append(text).append(END);
- return this;
- }
-
- public ConsoleUtils green(String text) {
- sb.append(ConsoleUtils.GREEN).append(text).append(END);
- return this;
- }
-
- public ConsoleUtils yellow(String text) {
- sb.append(ConsoleUtils.YELLOW).append(text).append(END);
- return this;
- }
-
- public static void log(String text) {
- System.out.println(new ConsoleUtils().yellow("| ").append(text));
- }
+
+ public static final String RED = "\u001B[31m";
+
+ public static final String GREEN = "\u001B[32m";
+
+ public static final String YELLOW = "\u001B[33m";
+
+ public static final String END = "\u001B[0m";
+
+ private StringBuilder sb = new StringBuilder();
+
+ public ConsoleUtils append(String text) {
+ sb.append(text);
+ return this;
+ }
+
+ public ConsoleUtils red(String text) {
+ sb.append(ConsoleUtils.RED).append(text).append(END);
+ return this;
+ }
+
+ public ConsoleUtils green(String text) {
+ sb.append(ConsoleUtils.GREEN).append(text).append(END);
+ return this;
+ }
+
+ public ConsoleUtils yellow(String text) {
+ sb.append(ConsoleUtils.YELLOW).append(text).append(END);
+ return this;
+ }
+
+ public static void log(String text) {
+ System.out.println(new ConsoleUtils().yellow("| ").append(text));
+ }
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return sb.toString();
- }
-
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return sb.toString();
+ }
+
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java
index 84b168d..d25d16d 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/utils/Table.java
@@ -18,80 +18,80 @@ package com.woorea.openstack.console.utils;
public class Table {
-
- private StringBuilder sb = new StringBuilder();
-
- private TableModel<?> model;
-
- public Table(TableModel<?> model) {
- this.model = model;
- }
-
- public StringBuilder render() {
- header();
- for(String[] row : model.getRows()) {
- int i = 0;
- for(String column : row) {
- Column columnModel = model.getHeaders()[i];
- sb.append("| ");
- if(column != null) {
- if(Column.ALIGN_RIGHT == columnModel.getAlign()) {
- for(int j = 0; j < columnModel.getSize() - column.length(); j++) {
- sb.append(" ");
- }
- }
- sb.append(column.length() <= columnModel.getSize() ? column : column.substring(0, columnModel.getSize()));
- if(Column.ALIGN_LEFT == columnModel.getAlign()) {
- for(int j = 0; j < columnModel.getSize() - column.length(); j++) {
- sb.append(" ");
- }
- }
- } else {
- for(int k = 0; k < columnModel.getSize(); k++) {
- sb.append(" ");
- }
- }
- sb.append(" ");
- i++;
- }
- sb.append("|\n");
- }
- for(Column c : model.getHeaders()) {
- sb.append("+");
- for(int i = 0; i < c.getSize() + 2; i++) {
- sb.append("-");
- }
- }
- sb.append("+\n");
- return sb;
- }
-
- public void header() {
- for(Column c : model.getHeaders()) {
- sb.append("+");
- for(int i = 0; i < c.getSize() + 2; i++) {
- sb.append("-");
- }
- }
- sb.append("+\n");
-
- for(Column c : model.getHeaders()) {
- sb.append("| ");
- sb.append(c.getName());
- for(int i = 0; i < c.getSize() - c.getName().length(); i++) {
- sb.append(" ");
- }
- sb.append(" ");
- }
- sb.append("|\n");
-
- for(Column c : model.getHeaders()) {
- sb.append("+");
- for(int i = 0; i < c.getSize() + 2; i++) {
- sb.append("-");
- }
- }
- sb.append("+\n");
- }
+
+ private StringBuilder sb = new StringBuilder();
+
+ private TableModel<?> model;
+
+ public Table(TableModel<?> model) {
+ this.model = model;
+ }
+
+ public StringBuilder render() {
+ header();
+ for(String[] row : model.getRows()) {
+ int i = 0;
+ for(String column : row) {
+ Column columnModel = model.getHeaders()[i];
+ sb.append("| ");
+ if(column != null) {
+ if(Column.ALIGN_RIGHT == columnModel.getAlign()) {
+ for(int j = 0; j < columnModel.getSize() - column.length(); j++) {
+ sb.append(" ");
+ }
+ }
+ sb.append(column.length() <= columnModel.getSize() ? column : column.substring(0, columnModel.getSize()));
+ if(Column.ALIGN_LEFT == columnModel.getAlign()) {
+ for(int j = 0; j < columnModel.getSize() - column.length(); j++) {
+ sb.append(" ");
+ }
+ }
+ } else {
+ for(int k = 0; k < columnModel.getSize(); k++) {
+ sb.append(" ");
+ }
+ }
+ sb.append(" ");
+ i++;
+ }
+ sb.append("|\n");
+ }
+ for(Column c : model.getHeaders()) {
+ sb.append("+");
+ for(int i = 0; i < c.getSize() + 2; i++) {
+ sb.append("-");
+ }
+ }
+ sb.append("+\n");
+ return sb;
+ }
+
+ public void header() {
+ for(Column c : model.getHeaders()) {
+ sb.append("+");
+ for(int i = 0; i < c.getSize() + 2; i++) {
+ sb.append("-");
+ }
+ }
+ sb.append("+\n");
+
+ for(Column c : model.getHeaders()) {
+ sb.append("| ");
+ sb.append(c.getName());
+ for(int i = 0; i < c.getSize() - c.getName().length(); i++) {
+ sb.append(" ");
+ }
+ sb.append(" ");
+ }
+ sb.append("|\n");
+
+ for(Column c : model.getHeaders()) {
+ sb.append("+");
+ for(int i = 0; i < c.getSize() + 2; i++) {
+ sb.append("-");
+ }
+ }
+ sb.append("+\n");
+ }
}
diff --git a/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java b/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java
index 527f26d..3715c85 100644
--- a/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java
+++ b/openstack-console/src/main/java/com/woorea/openstack/console/utils/TableModel.java
@@ -19,23 +19,23 @@ package com.woorea.openstack.console.utils;
import java.util.List;
public abstract class TableModel<T> {
-
- protected List<T> data;
-
- public TableModel(List<T> data) {
- this.data = data;
- }
-
- public abstract Column[] getHeaders();
+
+ protected List<T> data;
+
+ public TableModel(List<T> data) {
+ this.data = data;
+ }
+
+ public abstract Column[] getHeaders();
- public final String[][] getRows() {
- String[][] rows = new String[data.size()][];
- for(int i = 0; i < data.size(); i++) {
- rows[i] = getRow(data.get(i));
- }
- return rows;
- }
-
- public abstract String[] getRow(T data);
-
+ public final String[][] getRows() {
+ String[][] rows = new String[data.size()][];
+ for(int i = 0; i < data.size(); i++) {
+ rows[i] = getRow(data.get(i));
+ }
+ return rows;
+ }
+
+ public abstract String[] getRow(T data);
+
}