Bump MRI upstreams
[aaa.git] / aaa-cli / src / main / java / org / opendaylight / aaa / cli / dmstore / AddDomain.java
1 /*
2  * Copyright (c) 2016, 2017 Inocybe Technologies. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.aaa.cli.dmstore;
10
11 import org.apache.karaf.shell.api.action.Command;
12 import org.apache.karaf.shell.api.action.Option;
13 import org.apache.karaf.shell.api.action.lifecycle.Service;
14 import org.opendaylight.aaa.api.model.Domain;
15 import org.opendaylight.aaa.cli.AaaCliAbstractCommand;
16
17 /**
18  * Adds a domain.
19  *
20  * @author mserngawy
21  */
22 @Service
23 @Command(name = "add-domain", scope = "aaa", description = "Add domain.")
24 public class AddDomain extends AaaCliAbstractCommand {
25     @Option(name = "-name",
26             aliases = { "--domainName" },
27             description = "The domain name",
28             required = true,
29             multiValued = false)
30     private String domainName;
31
32     @Option(name = "-desc",
33             aliases = { "--domainDescription" },
34             description = "The domain Description",
35             required = true,
36             multiValued = false)
37     private String domainDesc;
38
39     @Override
40     public Object execute() throws Exception {
41         if (super.execute() == null) {
42             return LOGIN_FAILED_MESS;
43         }
44         Domain domain = new Domain();
45         domain.setDescription(domainDesc);
46         domain.setEnabled(true);
47         domain.setName(domainName);
48         domain = identityStore.writeDomain(domain);
49         if (domain != null) {
50             return "Domain " + domainName + " has been created, Domain Id is " + domain.getDomainid();
51         }
52         return null;
53     }
54 }