Skip to content

Commit 3e770a2

Browse files
Merge branch '1026' of github.com:allmightyspiff/softlayer-python into 1026
2 parents a53a75a + 893ff90 commit 3e770a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2185
-1376
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
# Change Log
22

33

4-
## [5.5.1] - 2018-08-31
4+
## [5.5.3] - 2018-08-31
5+
- Changes: https://github.com/softlayer/softlayer-python/compare/v5.5.2...v5.5.3
6+
7+
+ Added `slcli user delete`
8+
+ #1023 Added `slcli order quote` to let users create a quote from the slcli.
9+
+ #1032 Fixed vs upgrades when using flavors.
10+
+ #1034 Added pagination to ticket list commands
11+
+ #1037 Fixed DNS manager to be more flexible and support more zone types.
12+
+ #1044 Pinned Click library version at >=5 < 7
13+
14+
## [5.5.2] - 2018-08-31
515
- Changes: https://github.com/softlayer/softlayer-python/compare/v5.5.1...v5.5.2
616

717
+ #1018 Fixed hardware credentials.

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SoftLayer API Python Client
1717

1818

1919
This library provides a simple Python client to interact with `SoftLayer's
20-
XML-RPC API <http://developer.softlayer.com/reference/softlayerapi>`_.
20+
XML-RPC API <https://softlayer.github.io/reference/softlayerapi>`_.
2121

2222
A command-line interface is also included and can be used to manage various
2323
SoftLayer products and services.
@@ -120,7 +120,7 @@ If you are using the library directly in python, you can do something like this.
120120

121121
System Requirements
122122
-------------------
123-
* Python 2.7, 3.3, 3.4, 3.5 or 3.6.
123+
* Python 2.7, 3.3, 3.4, 3.5, 3.6, or 3.7.
124124
* A valid SoftLayer API username and key.
125125
* A connection to SoftLayer's private network is required to use
126126
our private network API endpoints.
@@ -129,7 +129,7 @@ Python Packages
129129
---------------
130130
* six >= 1.7.0
131131
* prettytable >= 0.7.0
132-
* click >= 5
132+
* click >= 5, < 7
133133
* requests >= 2.18.4
134134
* prompt_toolkit >= 0.53
135135
* pygments >= 2.0.0

SoftLayer/CLI/columns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def mask(self):
5757
def get_formatter(columns):
5858
"""This function returns a callback to use with click options.
5959
60-
The retuend function parses a comma-separated value and returns a new
60+
The returend function parses a comma-separated value and returns a new
6161
ColumnFormatter.
6262
6363
:param columns: a list of Column instances

SoftLayer/CLI/dns/record_add.py

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,86 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import exceptions
89
from SoftLayer.CLI import helpers
910
# pylint: disable=redefined-builtin
1011

1112

1213
@click.command()
13-
@click.argument('zone')
1414
@click.argument('record')
15-
@click.argument('type')
15+
@click.argument('record_type')
1616
@click.argument('data')
17+
@click.option('--zone',
18+
help="Zone name or identifier that the resource record will be associated with.\n"
19+
"Required for all record types except PTR")
1720
@click.option('--ttl',
18-
type=click.INT,
19-
default=7200,
21+
default=900,
2022
show_default=True,
2123
help='TTL value in seconds, such as 86400')
24+
@click.option('--priority',
25+
default=10,
26+
show_default=True,
27+
help='The priority of the target host. (MX or SRV type only)')
28+
@click.option('--protocol',
29+
type=click.Choice(['tcp', 'udp', 'tls']),
30+
default='tcp',
31+
show_default=True,
32+
help='The protocol of the service, usually either TCP or UDP. (SRV type only)')
33+
@click.option('--port',
34+
type=click.INT,
35+
help='The TCP/UDP/TLS port on which the service is to be found. (SRV type only)')
36+
@click.option('--service',
37+
help='The symbolic name of the desired service. (SRV type only)')
38+
@click.option('--weight',
39+
default=5,
40+
show_default=True,
41+
help='Relative weight for records with same priority. (SRV type only)')
2242
@environment.pass_env
23-
def cli(env, zone, record, type, data, ttl):
24-
"""Add resource record."""
43+
def cli(env, record, record_type, data, zone, ttl, priority, protocol, port, service, weight):
44+
"""Add resource record.
45+
46+
Each resource record contains a RECORD and DATA property, defining a resource's name and it's target data.
47+
Domains contain multiple types of resource records so it can take one of the following values: A, AAAA, CNAME,
48+
MX, SPF, SRV, and PTR.
49+
50+
About reverse records (PTR), the RECORD value must to be the public Ip Address of device you would like to manage
51+
reverse DNS.
52+
53+
slcli dns record-add 10.10.8.21 PTR myhost.com --ttl=900
54+
55+
Examples:
56+
57+
slcli dns record-add myhost.com A 192.168.1.10 --zone=foobar.com --ttl=900
58+
59+
slcli dns record-add myhost.com AAAA 2001:DB8::1 --zone=foobar.com
60+
61+
slcli dns record-add 192.168.1.2 MX 192.168.1.10 --zone=foobar.com --priority=11 --ttl=1800
62+
63+
slcli dns record-add myhost.com TXT "txt-verification=rXOxyZounZs87oacJSKvbUSIQ" --zone=2223334
64+
65+
slcli dns record-add myhost.com SPF "v=spf1 include:_spf.google.com ~all" --zone=2223334
66+
67+
slcli dns record-add myhost.com SRV 192.168.1.10 --zone=2223334 --service=foobar --port=80 --protocol=TCP
68+
69+
"""
2570

2671
manager = SoftLayer.DNSManager(env.client)
27-
zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')
28-
manager.create_record(zone_id, record, type, data, ttl=ttl)
72+
record_type = record_type.upper()
73+
74+
if zone and record_type != 'PTR':
75+
zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')
76+
77+
if record_type == 'MX':
78+
manager.create_record_mx(zone_id, record, data, ttl=ttl, priority=priority)
79+
elif record_type == 'SRV':
80+
manager.create_record_srv(zone_id, record, data, protocol, port, service,
81+
ttl=ttl, priority=priority, weight=weight)
82+
else:
83+
manager.create_record(zone_id, record, record_type, data, ttl=ttl)
84+
85+
elif record_type == 'PTR':
86+
manager.create_record_ptr(record, data, ttl=ttl)
87+
else:
88+
raise exceptions.CLIAbort("%s isn't a valid record type or zone is missing" % record_type)
89+
90+
click.secho("%s record added successfully" % record_type, fg='green')

SoftLayer/CLI/order/package_list.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from SoftLayer.CLI import formatting
88
from SoftLayer.managers import ordering
99

10-
COLUMNS = ['name',
10+
COLUMNS = ['id',
11+
'name',
1112
'keyName',
1213
'type']
1314

@@ -51,6 +52,7 @@ def cli(env, keyword, package_type):
5152

5253
for package in packages:
5354
table.add_row([
55+
package['id'],
5456
package['name'],
5557
package['keyName'],
5658
package['type']['keyName']

SoftLayer/CLI/order/place.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
4343
can then be converted to be made programmatically by calling
4444
SoftLayer.OrderingManager.place_order() with the same keynames.
4545
46-
Packages for ordering can be retrived from `slcli order package-list`
46+
Packages for ordering can be retrieved from `slcli order package-list`
4747
Presets for ordering can be retrieved from `slcli order preset-list` (not all packages
4848
have presets)
4949

SoftLayer/CLI/order/place_quote.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""Place quote"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import json
5+
6+
import click
7+
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
from SoftLayer.managers import ordering
11+
12+
13+
@click.command()
14+
@click.argument('package_keyname')
15+
@click.argument('location')
16+
@click.option('--preset',
17+
help="The order preset (if required by the package)")
18+
@click.option('--name',
19+
help="A custom name to be assigned to the quote (optional)")
20+
@click.option('--send-email',
21+
is_flag=True,
22+
help="The quote will be sent to the email address associated.")
23+
@click.option('--complex-type', help=("The complex type of the order. This typically begins"
24+
" with 'SoftLayer_Container_Product_Order_'."))
25+
@click.option('--extras',
26+
help="JSON string denoting extra data that needs to be sent with the order")
27+
@click.argument('order_items', nargs=-1)
28+
@environment.pass_env
29+
def cli(env, package_keyname, location, preset, name, send_email, complex_type,
30+
extras, order_items):
31+
"""Place a quote.
32+
33+
This CLI command is used for placing a quote of the specified package in
34+
the given location (denoted by a datacenter's long name). Orders made via the CLI
35+
can then be converted to be made programmatically by calling
36+
SoftLayer.OrderingManager.place_quote() with the same keynames.
37+
38+
Packages for ordering can be retrieved from `slcli order package-list`
39+
Presets for ordering can be retrieved from `slcli order preset-list` (not all packages
40+
have presets)
41+
42+
Items can be retrieved from `slcli order item-list`. In order to find required
43+
items for the order, use `slcli order category-list`, and then provide the
44+
--category option for each category code in `slcli order item-list`.
45+
46+
\b
47+
Example:
48+
# Place quote a VSI with 4 CPU, 16 GB RAM, 100 GB SAN disk,
49+
# Ubuntu 16.04, and 1 Gbps public & private uplink in dal13
50+
slcli order place-quote --name "foobar" --send-email CLOUD_SERVER DALLAS13 \\
51+
GUEST_CORES_4 \\
52+
RAM_16_GB \\
53+
REBOOT_REMOTE_CONSOLE \\
54+
1_GBPS_PUBLIC_PRIVATE_NETWORK_UPLINKS \\
55+
BANDWIDTH_0_GB_2 \\
56+
1_IP_ADDRESS \\
57+
GUEST_DISK_100_GB_SAN \\
58+
OS_UBUNTU_16_04_LTS_XENIAL_XERUS_MINIMAL_64_BIT_FOR_VSI \\
59+
MONITORING_HOST_PING \\
60+
NOTIFICATION_EMAIL_AND_TICKET \\
61+
AUTOMATED_NOTIFICATION \\
62+
UNLIMITED_SSL_VPN_USERS_1_PPTP_VPN_USER_PER_ACCOUNT \\
63+
NESSUS_VULNERABILITY_ASSESSMENT_REPORTING \\
64+
--extras '{"virtualGuests": [{"hostname": "test", "domain": "softlayer.com"}]}' \\
65+
--complex-type SoftLayer_Container_Product_Order_Virtual_Guest
66+
67+
"""
68+
manager = ordering.OrderingManager(env.client)
69+
70+
if extras:
71+
extras = json.loads(extras)
72+
73+
args = (package_keyname, location, order_items)
74+
kwargs = {'preset_keyname': preset,
75+
'extras': extras,
76+
'quantity': 1,
77+
'quote_name': name,
78+
'send_email': send_email,
79+
'complex_type': complex_type}
80+
81+
order = manager.place_quote(*args, **kwargs)
82+
83+
table = formatting.KeyValueTable(['name', 'value'])
84+
table.align['name'] = 'r'
85+
table.align['value'] = 'l'
86+
table.add_row(['id', order['quote']['id']])
87+
table.add_row(['name', order['quote']['name']])
88+
table.add_row(['created', order['orderDate']])
89+
table.add_row(['expires', order['quote']['expirationDate']])
90+
table.add_row(['status', order['quote']['status']])
91+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
('order:place', 'SoftLayer.CLI.order.place:cli'),
212212
('order:preset-list', 'SoftLayer.CLI.order.preset_list:cli'),
213213
('order:package-locations', 'SoftLayer.CLI.order.package_locations:cli'),
214+
('order:place-quote', 'SoftLayer.CLI.order.place_quote:cli'),
214215

215216
('rwhois', 'SoftLayer.CLI.rwhois'),
216217
('rwhois:edit', 'SoftLayer.CLI.rwhois.edit:cli'),
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
"""Manages Reserved Capacity."""
22
# :license: MIT, see LICENSE for more details.
3+
34
import importlib
4-
import click
5-
import types
6-
import SoftLayer
75
import os
8-
from SoftLayer.CLI import environment
9-
from SoftLayer.CLI import formatting
106

11-
from pprint import pprint as pp
12-
class capacityCommands(click.MultiCommand):
7+
import click
8+
9+
CONTEXT = {'help_option_names': ['-h', '--help'],
10+
'max_content_width': 999}
11+
12+
13+
class CapacityCommands(click.MultiCommand):
1314
"""Loads module for capacity related commands."""
1415

15-
def __init__(self, *path, **attrs):
16+
def __init__(self, **attrs):
1617
click.MultiCommand.__init__(self, **attrs)
1718
self.path = os.path.dirname(__file__)
1819

1920
def list_commands(self, ctx):
2021
"""List all sub-commands."""
21-
22-
rv = []
22+
commands = []
2323
for filename in os.listdir(self.path):
2424
if filename == '__init__.py':
2525
continue
2626
if filename.endswith('.py'):
27-
rv.append(filename[:-3])
28-
rv.sort()
29-
return rv
27+
commands.append(filename[:-3])
28+
commands.sort()
29+
return commands
3030

31-
def get_command(self, ctx, name):
31+
def get_command(self, ctx, cmd_name):
3232
"""Get command for click."""
33-
path = "%s.%s" % (__name__, name)
33+
path = "%s.%s" % (__name__, cmd_name)
3434
module = importlib.import_module(path)
3535
return getattr(module, 'cli')
3636

37-
@click.group(cls=capacityCommands,
38-
help="Manages virtual server reserved capacity")
39-
@environment.pass_env
40-
def cli(env):
41-
"""Manages Capacity"""
37+
38+
# Required to get the sub-sub-sub command to work.
39+
@click.group(cls=CapacityCommands, context_settings=CONTEXT)
40+
def cli():
41+
"""Base command for all capacity related concerns"""
4242
pass

0 commit comments

Comments
 (0)