Skip to content
Merged
4 changes: 2 additions & 2 deletions SoftLayer/CLI/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
\b
Examples :
%s
""" % ('*'+'\n*'.join(META_CHOICES),
'slcli metadata '+'\nslcli metadata '.join(META_CHOICES))
""" % ('*' + '\n*'.join(META_CHOICES),
'slcli metadata ' + '\nslcli metadata '.join(META_CHOICES))


@click.command(help=HELP,
Expand Down
3 changes: 1 addition & 2 deletions SoftLayer/CLI/virt/capacity/create_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
def cli(env, **args):
"""Allows for creating a virtual guest in a reserved capacity."""
create_args = _parse_create_args(env.client, args)
if args.get('ipv6'):
create_args['ipv6'] = True

create_args['primary_disk'] = args.get('primary_disk')
manager = CapacityManager(env.client)
capacity_id = args.get('capacity_id')
Expand Down
288 changes: 100 additions & 188 deletions SoftLayer/CLI/virt/create.py

Large diffs are not rendered by default.

24 changes: 7 additions & 17 deletions SoftLayer/CLI/virt/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,30 @@
completed. However for Network, no reboot is required.""")
@click.argument('identifier')
@click.option('--cpu', type=click.INT, help="Number of CPU cores")
@click.option('--private',
is_flag=True,
@click.option('--private', is_flag=True,
help="CPU core will be on a dedicated host server.")
@click.option('--memory', type=virt.MEM_TYPE, help="Memory in megabytes")
@click.option('--network', type=click.INT, help="Network port speed in Mbps")
@click.option('--flavor', type=click.STRING, help="Flavor keyName\n"
"Do not use --memory, --cpu or --private, if you are using flavors")
@click.option('--flavor', type=click.STRING,
help="Flavor keyName\nDo not use --memory, --cpu or --private, if you are using flavors")
@environment.pass_env
def cli(env, identifier, cpu, private, memory, network, flavor):
"""Upgrade a virtual server."""

vsi = SoftLayer.VSManager(env.client)

if not any([cpu, memory, network, flavor]):
raise exceptions.ArgumentError(
"Must provide [--cpu], [--memory], [--network], or [--flavor] to upgrade")
raise exceptions.ArgumentError("Must provide [--cpu], [--memory], [--network], or [--flavor] to upgrade")

if private and not cpu:
raise exceptions.ArgumentError(
"Must specify [--cpu] when using [--private]")
raise exceptions.ArgumentError("Must specify [--cpu] when using [--private]")

vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
if not (env.skip_confirmations or formatting.confirm(
"This action will incur charges on your account. "
"Continue?")):
if not (env.skip_confirmations or formatting.confirm("This action will incur charges on your account. Continue?")):
raise exceptions.CLIAbort('Aborted')

if memory:
memory = int(memory / 1024)

if not vsi.upgrade(vs_id,
cpus=cpu,
memory=memory,
nic_speed=network,
public=not private,
preset=flavor):
if not vsi.upgrade(vs_id, cpus=cpu, memory=memory, nic_speed=network, public=not private, preset=flavor):
raise exceptions.CLIAbort('VS Upgrade Failed')
28 changes: 26 additions & 2 deletions SoftLayer/fixtures/SoftLayer_Product_Order.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@
'setupFee': '1',
'item': {'id': 1, 'description': 'this is a thing'},
}]}
placeOrder = verifyOrder
placeOrder = {
'orderId': 1234,
'orderDate': '2013-08-01 15:23:45',
'orderDetails': {
'prices': [{
'id': 1,
'laborFee': '2',
'oneTimeFee': '2',
'oneTimeFeeTax': '.1',
'quantity': 1,
'recurringFee': '2',
'recurringFeeTax': '.1',
'hourlyRecurringFee': '2',
'setupFee': '1',
'item': {'id': 1, 'description': 'this is a thing'},
}],
'virtualGuests': [{
'id': 1234567,
'globalIdentifier': '1a2b3c-1701',
'fullyQualifiedDomainName': 'test.guest.com'
}]
}
}

# Reserved Capacity Stuff

Expand Down Expand Up @@ -75,7 +97,9 @@
'id': 1,
'description': 'B1.1x2 (1 Year ''Term)',
'keyName': 'B1_1X2_1_YEAR_TERM',
}
},
'hourlyRecurringFee': 1.0,
'recurringFee': 2.0
}
]
}
Expand Down
11 changes: 10 additions & 1 deletion SoftLayer/fixtures/SoftLayer_Virtual_Guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,16 @@
setUserMetadata = ['meta']
reloadOperatingSystem = 'OK'
setTags = True
createArchiveTransaction = {}
createArchiveTransaction = {
'createDate': '2018-12-10T17:29:18-06:00',
'elapsedSeconds': 0,
'guestId': 12345678,
'hardwareId': None,
'id': 12345,
'modifyDate': '2018-12-10T17:29:18-06:00',
'statusChangeDate': '2018-12-10T17:29:18-06:00'
}

executeRescueLayer = True

getUpgradeItemPrices = [
Expand Down
77 changes: 61 additions & 16 deletions SoftLayer/managers/vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

LOGGER = logging.getLogger(__name__)


# pylint: disable=no-self-use
# pylint: disable=no-self-use,too-many-lines


class VSManager(utils.IdentifierMixin, object):
Expand Down Expand Up @@ -664,12 +663,10 @@ def change_port_speed(self, instance_id, public, speed):
A port speed of 0 will disable the interface.
"""
if public:
return self.client.call('Virtual_Guest',
'setPublicNetworkInterfaceSpeed',
return self.client.call('Virtual_Guest', 'setPublicNetworkInterfaceSpeed',
speed, id=instance_id)
else:
return self.client.call('Virtual_Guest',
'setPrivateNetworkInterfaceSpeed',
return self.client.call('Virtual_Guest', 'setPrivateNetworkInterfaceSpeed',
speed, id=instance_id)

def _get_ids_from_hostname(self, hostname):
Expand Down Expand Up @@ -784,10 +781,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
continue

# We never want swap devices
type_name = utils.lookup(block_device,
'diskImage',
'type',
'keyName')
type_name = utils.lookup(block_device, 'diskImage', 'type', 'keyName')
if type_name == 'SWAP':
continue

Expand All @@ -804,8 +798,7 @@ def capture(self, instance_id, name, additional_disks=False, notes=None):
return self.guest.createArchiveTransaction(
name, disks_to_capture, notes, id=instance_id)

def upgrade(self, instance_id, cpus=None, memory=None,
nic_speed=None, public=True, preset=None):
def upgrade(self, instance_id, cpus=None, memory=None, nic_speed=None, public=True, preset=None):
"""Upgrades a VS instance.

Example::
Expand All @@ -832,17 +825,16 @@ def upgrade(self, instance_id, cpus=None, memory=None,
data = {'nic_speed': nic_speed}

if cpus is not None and preset is not None:
raise exceptions.SoftLayerError("Do not use cpu, private and memory if you are using flavors")
raise ValueError("Do not use cpu, private and memory if you are using flavors")
data['cpus'] = cpus

if memory is not None and preset is not None:
raise exceptions.SoftLayerError("Do not use memory, private or cpu if you are using flavors")
raise ValueError("Do not use memory, private or cpu if you are using flavors")
data['memory'] = memory

maintenance_window = datetime.datetime.now(utils.UTC())
order = {
'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest_'
'Upgrade',
'complexType': 'SoftLayer_Container_Product_Order_Virtual_Guest_Upgrade',
'properties': [{
'name': 'MAINTENANCE_WINDOW',
'value': maintenance_window.strftime("%Y-%m-%d %H:%M:%S%z")
Expand Down Expand Up @@ -874,6 +866,59 @@ def upgrade(self, instance_id, cpus=None, memory=None,
return True
return False

def order_guest(self, guest_object, test=False):
"""Uses Product_Order::placeOrder to create a virtual guest.

Useful when creating a virtual guest with options not supported by Virtual_Guest::createObject
specifically ipv6 support.

:param dictionary guest_object: See SoftLayer.CLI.virt.create._parse_create_args

Example::
new_vsi = {
'domain': u'test01.labs.sftlyr.ws',
'hostname': u'minion05',
'datacenter': u'hkg02',
'flavor': 'BL1_1X2X100'
'dedicated': False,
'private': False,
'os_code' : u'UBUNTU_LATEST',
'hourly': True,
'ssh_keys': [1234],
'disks': ('100','25'),
'local_disk': True,
'tags': 'test, pleaseCancel',
'public_security_groups': [12, 15],
'ipv6': True
}

vsi = mgr.order_guest(new_vsi)
# vsi will have the newly created vsi receipt.
# vsi['orderDetails']['virtualGuests'] will be an array of created Guests
print vsi
"""
tags = guest_object.pop('tags', None)
template = self.verify_create_instance(**guest_object)

if guest_object.get('ipv6'):
ipv6_price = self.ordering_manager.get_price_id_list('PUBLIC_CLOUD_SERVER', ['1_IPV6_ADDRESS'])
template['prices'].append({'id': ipv6_price[0]})

# Notice this is `userdata` from the cli, but we send it in as `userData`
if guest_object.get('userdata'):
# SL_Virtual_Guest::generateOrderTemplate() doesn't respect userData, so we need to add it ourself
template['virtualGuests'][0]['userData'] = [{"value": guest_object.get('userdata')}]

if test:
result = self.client.call('Product_Order', 'verifyOrder', template)
else:
result = self.client.call('Product_Order', 'placeOrder', template)
if tags is not None:
virtual_guests = utils.lookup(result, 'orderDetails', 'virtualGuests')
for guest in virtual_guests:
self.set_tags(tags, guest_id=guest['id'])
return result

def _get_package_items(self):
"""Following Method gets all the item ids related to VS.

Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def query_filter_date(start, end):
return {
'operation': 'betweenDate',
'options': [
{'name': 'startDate', 'value': [startdate+' 0:0:0']},
{'name': 'endDate', 'value': [enddate+' 0:0:0']}
{'name': 'startDate', 'value': [startdate + ' 0:0:0']},
{'name': 'endDate', 'value': [enddate + ' 0:0:0']}
]
}

Expand Down
2 changes: 1 addition & 1 deletion tests/CLI/modules/subnet_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def test_detail(self):
json.loads(result.output))

def test_list(self):
result = self.run_command(['subnet', 'list'])
result = self.run_command(['subnet', 'list'])
self.assert_no_fail(result)
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
SoftLayer.tests.CLI.modules.vs_capacity_tests
SoftLayer.tests.CLI.modules.vs.vs_capacity_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:license: MIT, see LICENSE for more details.
Expand Down
Loading