Skip to content

Commit 750da77

Browse files
author
caberos
committed
Merge branch 'master' of https://github.com/softlayer/softlayer-python into issue1426
2 parents 2afcd9d + 0558eab commit 750da77

File tree

13 files changed

+504
-38
lines changed

13 files changed

+504
-38
lines changed

SoftLayer/CLI/config/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from SoftLayer.CLI import formatting
1313

1414

15-
def get_api_key(client, username, secret):
15+
def get_api_key(client, username, secret): # pylint: disable=inconsistent-return-statements
1616
"""Attempts API-Key and password auth to get an API key.
1717
1818
This will also generate an API key if one doesn't exist

SoftLayer/CLI/custom_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import click
1010

1111

12+
# pylint: disable=inconsistent-return-statements
1213
class NetworkParamType(click.ParamType):
1314
"""Validates a network parameter type and converts to a tuple.
1415

SoftLayer/CLI/hardware/create.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
help="Exports options to a template file")
3232
@click.option('--wait', type=click.INT,
3333
help="Wait until the server is finished provisioning for up to X seconds before returning")
34+
@click.option('--router-public', type=click.INT,
35+
help="The ID of the public ROUTER on which you want the virtual server placed")
36+
@click.option('--router-private', type=click.INT,
37+
help="The ID of the private ROUTER on which you want the virtual server placed")
3438
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
3539
@helpers.multi_option('--extra', '-e', help="Extra option Key Names")
3640
@environment.pass_env
@@ -57,7 +61,9 @@ def cli(env, **args):
5761
'port_speed': args.get('port_speed'),
5862
'no_public': args.get('no_public') or False,
5963
'extras': args.get('extra'),
60-
'network': args.get('network')
64+
'network': args.get('network'),
65+
'public_router': args.get('router_public', None),
66+
'private_router': args.get('router_private', None)
6167
}
6268

6369
# Do not create hardware server with --test or --export

SoftLayer/CLI/report/bandwidth.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ def _get_virtual_bandwidth(env, start, end):
175175
@click.option(
176176
'--start',
177177
callback=_validate_datetime,
178-
default=(
179-
datetime.datetime.now() - datetime.timedelta(days=30)
180-
).strftime('%Y-%m-%d'),
178+
default=(datetime.datetime.now() - datetime.timedelta(days=30)
179+
).strftime('%Y-%m-%d'),
181180
help="datetime in the format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'")
182181
@click.option(
183182
'--end',
@@ -187,8 +186,14 @@ def _get_virtual_bandwidth(env, start, end):
187186
@click.option('--sortby', help='Column to sort by',
188187
default='hostname',
189188
show_default=True)
189+
@click.option('--virtual', is_flag=True,
190+
help='Show the all bandwidth summary for each virtual server',
191+
default=False)
192+
@click.option('--server', is_flag=True,
193+
help='show the all bandwidth summary for each hardware server',
194+
default=False)
190195
@environment.pass_env
191-
def cli(env, start, end, sortby):
196+
def cli(env, start, end, sortby, virtual, server):
192197
"""Bandwidth report for every pool/server.
193198
194199
This reports on the total data transfered for each virtual sever, hardware
@@ -213,23 +218,36 @@ def f_type(key, results):
213218
return (result['counter'] for result in results
214219
if result['type'] == key)
215220

221+
def _input_to_table(item):
222+
"Input metric data to table"
223+
pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
224+
pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
225+
pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
226+
pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
227+
table.add_row([
228+
item['type'],
229+
item['name'],
230+
formatting.b_to_gb(pub_in),
231+
formatting.b_to_gb(pub_out),
232+
formatting.b_to_gb(pri_in),
233+
formatting.b_to_gb(pri_out),
234+
item.get('pool') or formatting.blank(),
235+
])
236+
216237
try:
217-
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
218-
_get_virtual_bandwidth(env, start, end),
219-
_get_hardware_bandwidth(env, start, end)):
220-
pub_in = int(sum(f_type('publicIn_net_octet', item['data'])))
221-
pub_out = int(sum(f_type('publicOut_net_octet', item['data'])))
222-
pri_in = int(sum(f_type('privateIn_net_octet', item['data'])))
223-
pri_out = int(sum(f_type('privateOut_net_octet', item['data'])))
224-
table.add_row([
225-
item['type'],
226-
item['name'],
227-
formatting.b_to_gb(pub_in),
228-
formatting.b_to_gb(pub_out),
229-
formatting.b_to_gb(pri_in),
230-
formatting.b_to_gb(pri_out),
231-
item.get('pool') or formatting.blank(),
232-
])
238+
if virtual:
239+
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
240+
_get_virtual_bandwidth(env, start, end)):
241+
_input_to_table(item)
242+
elif server:
243+
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
244+
_get_hardware_bandwidth(env, start, end)):
245+
_input_to_table(item)
246+
else:
247+
for item in itertools.chain(_get_pooled_bandwidth(env, start, end),
248+
_get_hardware_bandwidth(env, start, end),
249+
_get_virtual_bandwidth(env, start, end)):
250+
_input_to_table(item)
233251
except KeyboardInterrupt:
234252
env.err("Printing collected results and then aborting.")
235253

SoftLayer/CLI/virt/create.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ def _parse_create_args(client, args):
9595
"private_vlan": args.get('vlan_private', None),
9696
"public_subnet": args.get('subnet_public', None),
9797
"private_subnet": args.get('subnet_private', None),
98+
"public_router": args.get('router_public', None),
99+
"private_router": args.get('router_private', None),
98100
}
99101

100102
# The primary disk is included in the flavor and the local_disk flag is not needed
@@ -192,6 +194,10 @@ def _parse_create_args(client, args):
192194
help="The ID of the public SUBNET on which you want the virtual server placed")
193195
@click.option('--subnet-private', type=click.INT,
194196
help="The ID of the private SUBNET on which you want the virtual server placed")
197+
@click.option('--router-public', type=click.INT,
198+
help="The ID of the public ROUTER on which you want the virtual server placed")
199+
@click.option('--router-private', type=click.INT,
200+
help="The ID of the private ROUTER on which you want the virtual server placed")
195201
@helpers.multi_option('--public-security-group', '-S',
196202
help=('Security group ID to associate with the public interface'))
197203
@helpers.multi_option('--private-security-group', '-s',

SoftLayer/managers/hardware.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ def _generate_create_dict(self,
492492
hourly=True,
493493
no_public=False,
494494
extras=None,
495-
network=None):
495+
network=None,
496+
public_router=None,
497+
private_router=None):
496498
"""Translates arguments into a dictionary for creating a server."""
497499

498500
extras = extras or []
@@ -535,6 +537,10 @@ def _generate_create_dict(self,
535537
'domain': domain,
536538
}]
537539
}
540+
if private_router:
541+
extras['hardware'][0]['primaryBackendNetworkComponent'] = {"router": {"id": int(private_router)}}
542+
if public_router:
543+
extras['hardware'][0]['primaryNetworkComponent'] = {"router": {"id": int(public_router)}}
538544
if post_uri:
539545
extras['provisionScripts'] = [post_uri]
540546

SoftLayer/managers/vs.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,11 @@ def _generate_create_dict(
533533
if datacenter:
534534
data["datacenter"] = {"name": datacenter}
535535

536-
if private_vlan or public_vlan or private_subnet or public_subnet:
537-
network_components = self._create_network_components(public_vlan, private_vlan,
538-
private_subnet, public_subnet)
539-
data.update(network_components)
536+
network_components = self._create_network_components(public_vlan, private_vlan,
537+
private_subnet, public_subnet,
538+
kwargs.get('private_router'),
539+
kwargs.get('public_router'))
540+
data.update(network_components)
540541

541542
if public_security_groups:
542543
secgroups = [{'securityGroup': {'id': int(sg)}}
@@ -581,8 +582,17 @@ def _generate_create_dict(
581582

582583
def _create_network_components(
583584
self, public_vlan=None, private_vlan=None,
584-
private_subnet=None, public_subnet=None):
585+
private_subnet=None, public_subnet=None,
586+
private_router=None, public_router=None):
585587
parameters = {}
588+
if any([private_router, public_router]) and any([private_vlan, public_vlan, private_subnet, public_subnet]):
589+
raise exceptions.SoftLayerError("You have to select network vlan or network vlan with a subnet or "
590+
"only router, not all options")
591+
592+
if private_router:
593+
parameters['primaryBackendNetworkComponent'] = {"router": {"id": int(private_router)}}
594+
if public_router:
595+
parameters['primaryNetworkComponent'] = {"router": {"id": int(public_router)}}
586596
if private_vlan:
587597
parameters['primaryBackendNetworkComponent'] = {"networkVlan": {"id": int(private_vlan)}}
588598
if public_vlan:
@@ -685,7 +695,21 @@ def verify_create_instance(self, **kwargs):
685695
kwargs.pop('tags', None)
686696
create_options = self._generate_create_dict(**kwargs)
687697
template = self.guest.generateOrderTemplate(create_options)
688-
if 'private_subnet' in kwargs or 'public_subnet' in kwargs:
698+
if kwargs.get('public_router') or kwargs.get('private_router'):
699+
if kwargs.get('private_vlan') or kwargs.get('public_vlan') or kwargs.get('private_subnet') \
700+
or kwargs.get('public_subnet'):
701+
raise exceptions.SoftLayerError("You have to select network vlan or network vlan with a subnet or "
702+
"only router, not all options")
703+
vsi = template['virtualGuests'][0]
704+
network_components = self._create_network_components(kwargs.get('public_vlan', None),
705+
kwargs.get('private_vlan', None),
706+
kwargs.get('private_subnet', None),
707+
kwargs.get('public_subnet', None),
708+
kwargs.get('private_router', None),
709+
kwargs.get('public_router', None))
710+
vsi.update(network_components)
711+
712+
if kwargs.get('private_subnet') or kwargs.get('public_subnet'):
689713
vsi = template['virtualGuests'][0]
690714
network_components = self._create_network_components(kwargs.get('public_vlan', None),
691715
kwargs.get('private_vlan', None),

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from setuptools import setup, find_packages
66

7+
# pylint: disable=inconsistent-return-statements
8+
79
DESCRIPTION = "A library for SoftLayer's API"
810

911
if os.path.exists('README.rst'):

0 commit comments

Comments
 (0)