Skip to content

Commit

Permalink
Merge pull request #65 from StackPointCloud/fix-update-v4
Browse files Browse the repository at this point in the history
Support for API v4 & bug fixing
  • Loading branch information
Jasmin Gacic authored Oct 10, 2017
2 parents ec04063 + bdb81ce commit 7c5807e
Show file tree
Hide file tree
Showing 15 changed files with 843 additions and 65 deletions.
227 changes: 216 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@
* [NIC](#nic)
* [Firewall Rules](#firewall)
* [IP Block](#ip-block)
* [LAN](#lan)
* [LAN](#lan)
* [User](#user)
* [Group](#group)
* [Share](#share)
* [Resource](#resource)
* [Support](#support)

## Concepts

The ProfitBricks CLI wraps the [ProfitBricks REST API](https://devops.profitbricks.com/api/rest/) allowing you to interact with it from a command-line interface.
The ProfitBricks CLI wraps the [ProfitBricks Cloud API](https://devops.profitbricks.com/api/cloud/) allowing you to interact with it from a command-line interface.

## Getting Started

Before you begin you will need to have [signed-up](https://www.profitbricks.com/signup/) for a ProfitBricks account. The credentials you establish during sign-up will be used to authenticate against the [ProfitBricks API](https://devops.profitbricks.com/api/rest/).
Before you begin you will need to have [signed-up](https://www.profitbricks.com/signup/) for a ProfitBricks account. The credentials you establish during sign-up will be used to authenticate against the [ProfitBricks Cloud API](https://devops.profitbricks.com/api/cloud/).

## Installation

Expand All @@ -55,7 +59,7 @@ Please utilize one of the following URL's to retrieve an install script that is

[GitHub - ProfitBricks Windows Install](https://github.com/profitbricks/profitbricks-cli/tree/master/install/windows/install.bat)

If you prefer, you may install `nodejs` and `npm` manually. Then run the following to to install the ProfitBricks CLI module globally:
If you prefer, you may install `nodejs` and `npm` manually. Then run the following to install the ProfitBricks CLI module globally:

```
npm install -g profitbricks-cli
Expand All @@ -70,9 +74,9 @@ Run `profitbricks` or `profitbricks -h` or `profitbricks --help`:
```
Usage: profitbricks [Options]
Options:
-h, --help output usage information
-V, --version output the version number
setup Configures credentials for ProfitBricks CLI
datacenter, [env] Data center operations
Expand All @@ -88,6 +92,10 @@ Run `profitbricks` or `profitbricks -h` or `profitbricks --help`:
lan, [env] LAN operations
request, [env] Request operations
location, [env] Location operations
group, [env] Group operations
user, [env] User operations
share, [env] Share operations
resource, [env] Resource operations
-i, --id [env] Id
-n, --name [env] Name
-l, --location [env] Location
Expand All @@ -106,6 +114,7 @@ Run `profitbricks` or `profitbricks -h` or `profitbricks --help`:
--volumesize [env] Volume size
--volumename [env] Volume name
--imageid [env] Image id
--imagealias [env] Image alias
-b --bus [env] Bus type (VIRTIO or IDE)
-t --type [env] The disk type.
--imagepassword [env] One-time password is set on the Image for the appropriate account. Password has to contain 8-50 characters. Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789]
Expand All @@ -126,9 +135,10 @@ Run `profitbricks` or `profitbricks -h` or `profitbricks --help`:
--cpufamily [env] Sets the CPU type. "AMD_OPTERON" or "INTEL_XEON". Defaults to "AMD_OPTERON".
--lan [env] The LAN ID the NIC will sit on. If the LAN ID does not exist it will be created.
--public [env] Boolean indicating if the LAN faces the public Internet or not.
--ipfailover [env] IP failover group, e.g. "ip1,nicid1;ip2,nicid2;ip3,nicid3..."
--requestid [env] Request UUID
--nicid [env] Network Interface UUID
--nat NIC Network Address Translation.
--nat NIC Network Address Translation
--protocol [env] The protocol for the rule: TCP, UDP, ICMP, ANY.
--sourceMac [env] Only traffic originating from the respective MAC address is allowed. Valid format: aa:bb:cc:dd:ee:ff. Value null allows all source MAC address.
--sourceIp [env] Only traffic originating from the respective IPv4 address is allowed. Value null allows all source IPs.
Expand All @@ -140,15 +150,33 @@ Run `profitbricks` or `profitbricks -h` or `profitbricks --help`:
--portRangeEnd [env] Defines the end range of the allowed port (from 1 to 65534) if protocol TCP or UDP is chosen. Leave portRangeStart and portRangeEnd value null to allow all ports.
--icmpType [env] Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen. Value null allows all types.
--icmpCode [env] Defines the allowed code (from 0 to 254) if protocol ICMP is chosen. Value null allows all codes.
--groupid [env] Group UUID
--resourceid [env] Resource UUID
--resourcetype [env] Resource type. "datacenter", "snapshot", "ipblock" or "image".
--editprivilege [env] The group has permission to edit privileges on the resource.
--shareprivilege [env] The group has permission to share the resource.
--createdatacenter [env] Group will be allowed to create virtual data centers.
--createsnapshot [env] Group will be allowed to create snapshots.
--reserveip [env] Group will be allowed to reserve IP addresses.
--accessactlog [env] Group will be allowed to access the activity log.
--firstname [env] A first name for the user.
--lastname [env] A last name for the user.
--email [env] An email for the user.
--password [env] A password for the user.
--admin [env] Indicates if the user has administrative rights.
--forcesecauth [env] Indicates if secure (two-factor) authentication should be forced for the user.
--json Print results as JSON string
--addip [env] Add IP
--removeip [env] Remove IP
--adduser [env] UUID of the user to add to a group
--removeuser [env] UUID of the user to remove from a group
-f, --force Forces execution
-h, --help output usage information
```

## Configuration

Before using the ProfitBrick's CLI to perform any operations, we'll need to set our credentials:
Before using the CLI to perform any operations, we'll need to set our credentials:

```
$ profitbricks setup
Expand All @@ -164,13 +192,20 @@ You will be notified with the following message if you have provided incorrect c

After successful authentication you will no longer need to provide credentials unless you want to change them. They are stored as a BASE64 encoded string in a '.profitbricks-auth' file in your home directory.

You may provide your credentials in the environment variables as well. The CLI will always check for the credentials in the environment variables before attempting to read `.profitbricks-auth` file.

```
export PROFITBRICKS_USERNAME="YourProfitBricksUsername"
export PROFITBRICKS_PASSWORD="YourProfitBricksPassword"
```

# How To's:

These examples assume that you don't have any resources provisioned under your account. The first thing we will want to do is create a data center to hold all of our resources.

## Create Data Center

We need to supply some parameters to get our first data center created. In this case, we will set the location to 'us/las' so that this data center is created under the [DevOps Data Center](https://devops.profitbricks.com/tutorials/devops-data-center-information/). Other valid locations can be determined by reviewing the [REST API Documentation](https://devops.profitbricks.com/api/rest/#locations). That documentation is an excellent resource since that is what the ProfitBricks CLI is calling to complete these operations.
We need to supply some parameters to get our first data center created. In this case, we will set the location to 'us/las'. Other valid locations can be determined by reviewing the [Cloud API Documentation](https://devops.profitbricks.com/api/cloud/v4/#locations). That documentation is an excellent resource since that is what the ProfitBricks CLI is calling to complete these operations.

```
$ profitbricks datacenter create --name "Demo" --description "CLI Demo Data Center" --location "us/las"
Expand Down Expand Up @@ -251,6 +286,18 @@ Id Name Size Licence Bus State
d7dc58a1-9505-48f5-9db4-22cff0659cf8 null 12 LINUX VIRTIO BUSY
```

We can also use image aliases instead of non-constant image IDs to create new volumes. Use `image aliases` command to find out available image aliases for a particular location.

```
node profitbricks volume create --datacenterid 3fc832b1-558f-48a4-bca2-af5043975393 --name "Test Alias" --imagealias ubuntu:latest --size 20 --bus VIRTIO --type SSD --sshkey [ssh_key_string]
Volume
------------------------------------------------------------------------------
Id Name Size Licence Bus State
------------------------------------ ---------- ---- ------- ------ -----
e7a6e51e-824f-4733-8ae2-30da817a9cbe Test Alias 20GB null VIRTIO BUSY
```

## Attach Volume

The volume we've created is not yet connected or attached to a server. To accomplish that we'll use the `dcid` and `serverid` values returned from the previous commands:
Expand Down Expand Up @@ -558,6 +605,12 @@ $ profitbricks image update -i [imageid] --name [name] ---description [descripti
$ profitbricks image delete -i [imageid]
```

### List Image Aliases

```
$ profitbricks image aliases -l [locationid]
```

## NIC

### List NICs
Expand Down Expand Up @@ -587,7 +640,7 @@ $ profitbricks nic update -i [nicid] --datacenterid [dcid] --serverid [serverid]
$ profitbricks nic update --datacenterid [dc] --serverid [server] -i [nicid] --addip 1.1.1.1
$ profitbricks nic update --datacenterid [dc] --serverid [server] -i [nicid] --removeip 1.1.1.1
```


### Delete NIC

Expand Down Expand Up @@ -621,7 +674,7 @@ $ profitbricks nic detach --datacenterid [dcid] --loadbalancerid [lbid] -i [nici
$profitbricks firewall list --datacenterid [dcid] --serverid [serverid] --nicid [nicid]
```

### Get Specific Firewall Rule
### Get Specific Firewall Rule

```
$profitbricks firewall get --datacenterid [dcid] --serverid [serverid] --nicid [nicid] --id [firewallid]
Expand Down Expand Up @@ -682,13 +735,17 @@ profitbricks lan list --datacenterid [dcid]
### Create LAN

```
profitbricks lan create --datacenterid [dcid] -p [path_to_json]
profitbricks lan create --datacenterid [dcid] --name [name] --public [boolean]
```

### Update LAN

```
profitbricks lan update --datacenterid [dcid] --name [name] --public [boolean] -i [lanid]
profitbricks lan update --datacenterid [dcid] -p [path_to_json]
profitbricks lan update --datacenterid [dcid] --name [name] --public [boolean] -i [lanid] --ipfailover [ip1,nicid1;ip2,nicid2;...]
```

### Get LAN
Expand All @@ -697,7 +754,155 @@ profitbricks lan update --datacenterid [dcid] --name [name] --public [boolean] -
profitbricks lan show --datacenterid [dcid] --id [lanid]
```

## User

### List Users

```
$ profitbricks user list
```

### Create User

```
$ profitbricks user create -p [path_to_json]
$ profitbricks user create --firstname [firstname] --lastname [lastname] --email [email] --password [password] --admin [boolean] --forcesecauth [boolean]
```

### Get Specific User

```
$ profitbricks user get -i [userid]
$ profitbricks user show -i [userid]
```

### Update User

```
$ profitbricks user update -i [userid] --firstname [firstname] --lastname [lastname] --email [email] --admin [boolean] --forcesecauth [boolean]
```

### Delete User

```
$ profitbricks user delete -i [userid]
```

## Group

### List Groups

```
$ profitbricks group list
```

### Create Group

```
$ profitbricks group create -p [path_to_json]
$ profitbricks group create --name [name] --createdatacenter [boolean] --createsnapshot [boolean] --reserveip [boolean] --accessactlog [boolean]
```

### Get Specific Group

```
$ profitbricks group get -i [groupid]
$ profitbricks group show -i [groupid]
```

### Update Group

```
$ profitbricks group update -i [groupid] --name [name] --createdatacenter [boolean] --createsnapshot [boolean] --reserveip [boolean] --accessactlog [boolean]
```

### Delete Group

```
$ profitbricks group delete -i [groupid]
```

### List Group Users

```
$ profitbricks group users -i [groupid]
```

### Add Group User

```
$ profitbricks group user --adduser [userid] -i [groupid]
```

### Remove Group User

```
profitbricks group user --removeuser [userid] -i [groupid]
```

## Share

### List Shares

```
$ profitbricks share list --groupid [groupid]
```

### Add Share

```
$ profitbricks share add --groupid [groupid] --resourceid [resourceid] --editprivilege [boolean] --shareprivilege [boolean]
$ profitbricks share create --groupid [groupid] --resourceid [resourceid] --editprivilege [boolean] --shareprivilege [boolean]
```

### Get Specific Share

```
$ profitbricks share get --groupid [groupid] -i [shareid]
$ profitbricks share show --groupid [groupid] -i [shareid]
```

### Update Share

```
$ profitbricks share update --groupid [groupid] -i [shareid] --editprivilege [boolean] --shareprivilege [boolean]
```

### Remove Share

```
$ profitbricks share delete --groupid [groupid] -i [shareid]
$ profitbricks share remove --groupid [groupid] -i [shareid]
```

## Resource

### List All Resources

```
$ profitbricks resource list
```

### List Specific Type Resources

```
$ profitbricks resource list --resourcetype [datacenter|snapshot|image|ipblock]
```

### Get Specific Type Resource

```
$ profitbricks resource get --resourcetype [datacenter|snapshot|image|ipblock] -i [resourceid]
$ profitbricks resource show --resourcetype [datacenter|snapshot|image|ipblock] -i [resourceid]
```


## Support
Expand Down
2 changes: 1 addition & 1 deletion autocomplete
Original file line number Diff line number Diff line change
@@ -1 +1 @@
complete -W "-h --help -V --version setup datacenter server volume snapshot loadbalancer nic ipblock drives image lan get show create delete update attach detach start stop reboot -i --id -n --name -l --location -d --description -p --path --datacenterid -r --ram -c --cores -a --availabilityzone --licencetype --bootVolume --bootCdrom --volumeid --volumesize --volumename --imageid -b --bus -s --size --cpuHotPlug --cpuHotUnplug --ramHotPlug --ramHotUnplug --nicHotPlug --nicHotUnplug --discVirtioHotPlug --discVirtioHotUnplug --discScsiHotPlug --discScsiHotUnplug --ip --dhcp --serverid --lan --public --json -f --force" profitbricks
complete -W "-h --help -V --version setup datacenter server volume snapshot loadbalancer nic firewall ipblock drives image lan request location group user share resource -i --id -n --name -l --location -d --description -p --path --datacenterid --loadbalancerid -r --ram -c --cores -a --availabilityzone --licencetype --sshkey --bootVolume --bootCdrom --volumeid --volumesize --volumename --imageid --imagealias -b --bus -t --type --imagepassword -s --size --cpuHotPlug --cpuHotUnplug --ramHotPlug --ramHotUnplug --nicHotPlug --nicHotUnplug --discVirtioHotPlug --discVirtioHotUnplug --discScsiHotPlug --discScsiHotUnplug --ip --dhcp --serverid --cpufamily --lan --public --ipfailover --requestid --nicid --nat --protocol --sourceMac --sourceIp --sourceIp --targetIp --targetIp --portRangeStart --portRangeEnd --portRangeEnd --icmpType --icmpCode --groupid --resourceid --resourcetype --editprivilege --shareprivilege --createdatacenter --createsnapshot --reserveip --accessactlog --firstname --lastname --email --password --admin --forcesecauth --json --addip --removeip --adduser --removeuser -f --force" profitbricks
Loading

0 comments on commit 7c5807e

Please sign in to comment.