def test_delete_record(self, no_going_back_mock):
        no_going_back_mock.return_value = True
        self.client['Dns_Domain'].getResourceRecords.return_value = [
            fixtures.Dns_Domain.getResourceRecords[0]]
        command = dns.RecordRemove(client=self.client)
        output = command.execute({'<zone>': 'example.com',
                                  '<record>': 'hostname',
                                  '--id': '1',
                                  '--really': False})
        self.assertEqual([{'record': '1'}],
                         formatting.format_output(output, 'python'))

        output = command.execute({'<zone>': 'example.com',
                                  '<record>': 'hostname',
                                  '--id': None,
                                  '--really': False})
        self.assertEqual([{'record': 1}],
                         formatting.format_output(output, 'python'))

        no_going_back_mock.return_value = False
        self.assertRaises(exceptions.CLIAbort,
                          command.execute, {'<zone>': 'example.com',
                                            '<record>': 'hostname',
                                            '--id': 1,
                                            '--really': False})
예제 #2
0
    def test_format_output_python(self):
        t = formatting.format_output('just a string', 'python')
        self.assertEqual('just a string', t)

        t = formatting.format_output(['just a string'], 'python')
        self.assertEqual(['just a string'], t)

        t = formatting.format_output({'test_key': 'test_value'}, 'python')
        self.assertEqual({'test_key': 'test_value'}, t)
예제 #3
0
    def test_format_output_python(self):
        t = formatting.format_output('just a string', 'python')
        self.assertEqual('just a string', t)

        t = formatting.format_output(['just a string'], 'python')
        self.assertEqual(['just a string'], t)

        t = formatting.format_output({'test_key': 'test_value'}, 'python')
        self.assertEqual({'test_key': 'test_value'}, t)
예제 #4
0
    def test_format_output_python(self):
        t = formatting.format_output("just a string", "python")
        self.assertEqual("just a string", t)

        t = formatting.format_output(["just a string"], "python")
        self.assertEqual(["just a string"], t)

        t = formatting.format_output({"test_key": "test_value"}, "python")
        self.assertEqual({"test_key": "test_value"}, t)
예제 #5
0
    def test_format_output_unicode(self):
        t = formatting.format_output('☃', 'raw')
        self.assertEqual('☃', t)

        item = formatting.FormattedItem('raw ☃', '☃')
        t = formatting.format_output(item)
        self.assertEqual('☃', t)

        t = formatting.format_output(item, 'raw')
        self.assertEqual('raw ☃', t)
예제 #6
0
    def test_format_output_unicode(self):
        t = formatting.format_output('☃', 'raw')
        self.assertEqual('☃', t)

        item = formatting.FormattedItem('raw ☃', '☃')
        t = formatting.format_output(item)
        self.assertEqual('☃', t)

        t = formatting.format_output(item, 'raw')
        self.assertEqual('raw ☃', t)
예제 #7
0
    def test_sequentialoutput(self):
        t = formatting.SequentialOutput()
        self.assertTrue(hasattr(t, 'append'))
        t.append('This is a test')
        t.append('')
        t.append('More tests')
        output = formatting.format_output(t)
        self.assertEqual("This is a test\nMore tests", output)

        t.separator = ','
        output = formatting.format_output(t)
        self.assertEqual("This is a test,More tests", output)
예제 #8
0
    def test_sequentialoutput(self):
        t = formatting.SequentialOutput()
        self.assertTrue(hasattr(t, "append"))
        t.append("This is a test")
        t.append("")
        t.append("More tests")
        output = formatting.format_output(t)
        self.assertEqual("This is a test\nMore tests", output)

        t.separator = ","
        output = formatting.format_output(t)
        self.assertEqual("This is a test,More tests", output)
예제 #9
0
    def test_sequentialoutput(self):
        t = formatting.SequentialOutput()
        self.assertTrue(hasattr(t, 'append'))
        t.append('This is a test')
        t.append('')
        t.append('More tests')
        output = formatting.format_output(t)
        self.assertEqual("This is a test\nMore tests", output)

        t.separator = ','
        output = formatting.format_output(t)
        self.assertEqual("This is a test,More tests", output)
예제 #10
0
    def test_sequentialoutput(self):
        # specifying the separator prevents windows from using \n\r
        t = formatting.SequentialOutput(separator="\n")
        self.assertTrue(hasattr(t, 'append'))
        t.append('This is a test')
        t.append('')
        t.append('More tests')
        output = formatting.format_output(t)
        self.assertEqual("This is a test\nMore tests", output)

        t.separator = ','
        output = formatting.format_output(t)
        self.assertEqual("This is a test,More tests", output)
예제 #11
0
    def test_sequentialoutput(self):
        # specifying the separator prevents windows from using \n\r
        t = formatting.SequentialOutput(separator="\n")
        self.assertTrue(hasattr(t, 'append'))
        t.append('This is a test')
        t.append('')
        t.append('More tests')
        output = formatting.format_output(t)
        self.assertEqual("This is a test\nMore tests", output)

        t.separator = ','
        output = formatting.format_output(t)
        self.assertEqual("This is a test,More tests", output)
예제 #12
0
    def test_format_output_jsonraw(self):
        t = formatting.Table(['nothing'])
        t.align['nothing'] = 'c'
        t.add_row(['testdata'])
        t.add_row([formatting.blank()])
        t.sortby = 'nothing'
        ret = formatting.format_output(t, 'jsonraw')
        # This uses json.dumps due to slight changes in the output between
        # py3.3 and py3.4
        expected = json.dumps([{'nothing': 'testdata'}, {'nothing': None}])
        self.assertEqual(expected, ret)

        ret = formatting.format_output('test', 'json')
        self.assertEqual('"test"', ret)
예제 #13
0
    def test_format_output_jsonraw(self):
        t = formatting.Table(['nothing'])
        t.align['nothing'] = 'c'
        t.add_row(['testdata'])
        t.add_row([formatting.blank()])
        t.sortby = 'nothing'
        ret = formatting.format_output(t, 'jsonraw')
        # This uses json.dumps due to slight changes in the output between
        # py3.3 and py3.4
        expected = json.dumps([{'nothing': 'testdata'}, {'nothing': None}])
        self.assertEqual(expected, ret)

        ret = formatting.format_output('test', 'json')
        self.assertEqual('"test"', ret)
예제 #14
0
    def test_format_output_json(self):
        t = formatting.Table(["nothing"])
        t.align["nothing"] = "c"
        t.add_row(["testdata"])
        t.add_row([formatting.blank()])
        t.sortby = "nothing"
        ret = formatting.format_output(t, "json")
        # This uses json.dumps due to slight changes in the output between
        # py3.3 and py3.4
        expected = json.dumps([{"nothing": "testdata"}, {"nothing": None}], indent=4)
        self.assertEqual(expected, ret)

        ret = formatting.format_output("test", "json")
        self.assertEqual('"test"', ret)
예제 #15
0
    def test_server_create_options_with_cpu_only(self, packages):
        args = {
            '<chassis_id>': '999',
            '--all': False,
            '--datacenter': False,
            '--cpu': True,
            '--nic': False,
            '--disk': False,
            '--os': False,
            '--memory': False,
            '--controller': False,
        }

        test_data = [
            (999, 'Chassis 999'),
        ]
        packages.return_value = test_data

        runnable = server.ServerCreateOptions(client=self.client)

        output = runnable.execute(args)

        expected = {
            'cpu': [{
                'Description': 'Dual Quad Core Pancake 200 - 1.60GHz',
                'ID': 723
            }, {
                'Description': 'Dual Quad Core Pancake 200 - 1.80GHz',
                'ID': 724
            }],
        }

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #16
0
    def test_detail_vs(self):
        command = vs.VSDetails(client=self.client)
        output = command.execute({'<identifier>': '100',
                                  '--passwords': True,
                                  '--price': True})

        self.assertEqual({'active_transaction': None,
                          'cores': 2,
                          'created': '2013-08-01 15:23:45',
                          'datacenter': 'TEST00',
                          'hostname': 'vs-test1.test.sftlyr.ws',
                          'id': 100,
                          'memory': 1024,
                          'modified': {},
                          'os': '12.04-64 Minimal for CCI',
                          'os_version': '12.04-64 Minimal for CCI',
                          'notes': 'notes',
                          'price rate': 1.54,
                          'tags': ['production'],
                          'private_cpu': {},
                          'private_ip': '10.45.19.37',
                          'private_only': {},
                          'ptr': 'test.softlayer.com.',
                          'public_ip': '172.16.240.2',
                          'state': 'RUNNING',
                          'status': 'ACTIVE',
                          'users': [{'password': '******', 'username': '******'}],
                          'vlans': [{'type': 'PUBLIC',
                                     'number': 23,
                                     'id': 1}],
                          'owner': 'chechu'},
                         formatting.format_output(output, 'python'))
예제 #17
0
 def test_format_output_table(self):
     t = formatting.Table(['nothing'])
     t.align['nothing'] = 'c'
     t.add_row(['testdata'])
     t.sortby = 'nothing'
     ret = formatting.format_output(t, 'table')
     self.assertIsInstance(ret, Table)
예제 #18
0
    def test_server_details(self):
        runnable = server.ServerDetails(client=self.client)

        args = {'<identifier>': 1234, '--passwords': True, '--price': True}
        output = runnable.execute(args)

        expected = {
            'status': 'ACTIVE',
            'datacenter': 'TEST00',
            'created': '2013-08-01 15:23:45',
            'notes': 'These are test notes.',
            'hostname': 'hardware-test1.test.sftlyr.ws',
            'public_ip': '172.16.1.100',
            'private_ip': '10.1.0.2',
            'ipmi_ip': '10.1.0.3',
            'price rate': 1.54,
            'memory': 2048,
            'cores': 2,
            'ptr': '2.0.1.10.in-addr.arpa',
            'os': 'Ubuntu',
            'id': 1000,
            'tags': ['test_tag'],
            'users': ['root abc123'],
            'vlans': [{'id': 9653, 'number': 1800, 'type': 'PRIVATE'},
                      {'id': 19082, 'number': 3672, 'type': 'PUBLIC'}],
            'owner': 'chechu'
        }

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #19
0
    def test_server_create_options_with_cpu_only(self, packages):
        args = {
            '<chassis_id>': '999',
            '--all': False,
            '--datacenter': False,
            '--cpu': True,
            '--nic': False,
            '--disk': False,
            '--os': False,
            '--memory': False,
            '--controller': False,
        }

        test_data = [
            (999, 'Chassis 999'),
        ]
        packages.return_value = test_data

        runnable = server.ServerCreateOptions(client=self.client)

        output = runnable.execute(args)

        expected = {
            'cpu': [
                {'Description': 'Dual Quad Core Pancake 200 - 1.60GHz',
                 'ID': 723},
                {'Description': 'Dual Quad Core Pancake 200 - 1.80GHz',
                 'ID': 724}
            ],
        }

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #20
0
    def test_server_cancel_reasons(self):
        runnable = server.ServerCancelReasons(client=self.client)
        output = runnable.execute({})

        expected = [
            {'Code': 'datacenter',
             'Reason': 'Migrating to a different SoftLayer datacenter'},
            {'Code': 'cost', 'Reason': 'Server / Upgrade Costs'},
            {'Code': 'moving', 'Reason': 'Moving to competitor'},
            {'Code': 'migrate_smaller',
             'Reason': 'Migrating to smaller server'},
            {'Code': 'sales', 'Reason': 'Sales process / upgrades'},
            {'Code': 'performance',
             'Reason': 'Network performance / latency'},
            {'Code': 'unneeded', 'Reason': 'No longer needed'},
            {'Code': 'support', 'Reason': 'Support response / timing'},
            {'Code': 'closing', 'Reason': 'Business closing down'},
            {'Code': 'migrate_larger', 'Reason': 'Migrating to larger server'}
        ]

        method = 'assertItemsEqual'
        if not hasattr(self, method):
            # For Python 3.3 compatibility
            method = 'assertCountEqual'

        f = getattr(self, method)
        f(expected, formatting.format_output(output, 'python'))
    def test_list_zones(self):
        command = dns.ListZones(client=self.client)

        output = command.execute({'<zone>': None})
        self.assertEqual([{'serial': 2014030728,
                           'updated': '2014-03-07T13:52:31-06:00',
                           'id': 12345, 'zone': 'example.com'}],
                         formatting.format_output(output, 'python'))
예제 #22
0
    def test_format_output_json_keyvaluetable(self):
        t = formatting.KeyValueTable(['key', 'value'])
        t.add_row(['nothing', formatting.blank()])
        t.sortby = 'nothing'
        ret = formatting.format_output(t, 'json')
        self.assertEqual('''{
    "nothing": null
}''', ret)
예제 #23
0
    def test_format_output_json_keyvaluetable(self):
        t = formatting.KeyValueTable(['key', 'value'])
        t.add_row(['nothing', formatting.blank()])
        t.sortby = 'nothing'
        ret = formatting.format_output(t, 'json')
        self.assertEqual('''{
    "nothing": null
}''', ret)
예제 #24
0
    def test_print_key(self):
        command = sshkey.PrintSshKey(client=self.client)
        output = command.execute({'<identifier>': '1234'})

        self.assertEqual(formatting.format_output(output, 'python'), {
            'id': 1234,
            'label': 'label',
            'notes': 'notes'
        })
예제 #25
0
    def test_format_output_table(self):
        t = formatting.Table(["nothing"])
        t.align["nothing"] = "c"
        t.add_row(["testdata"])
        t.sortby = "nothing"
        ret = formatting.format_output(t, "table")

        self.assertIn("nothing", str(ret))
        self.assertIn("testdata", str(ret))
예제 #26
0
    def test_format_output_raw(self):
        t = formatting.Table(['nothing'])
        t.align['nothing'] = 'c'
        t.add_row(['testdata'])
        t.sortby = 'nothing'
        ret = formatting.format_output(t, 'raw')

        self.assertNotIn('nothing', str(ret))
        self.assertIn('testdata', str(ret))
예제 #27
0
    def test_format_output_table(self):
        t = formatting.Table(['nothing'])
        t.align['nothing'] = 'c'
        t.add_row(['testdata'])
        t.sortby = 'nothing'
        ret = formatting.format_output(t, 'table')

        self.assertIn('nothing', str(ret))
        self.assertIn('testdata', str(ret))
    def test_list_all_zones(self):
        command = dns.ListZones(client=self.client)

        output = command.execute({'<zone>': 'example.com'})
        self.assertEqual({'record': 'a',
                          'type': 'CNAME',
                          'id': 1,
                          'value': 'd',
                          'ttl': 100},
                         formatting.format_output(output, 'python')[0])
예제 #29
0
    def test_show(self):
        command = config.Show(client=self.client)

        output = command.execute({})

        expected = {'Username': self.client.auth.username,
                    'Endpoint URL': self.client.endpoint_url,
                    'API Key': self.client.auth.api_key,
                    'Timeout': self.client.timeout}
        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #30
0
    def test_list_nas(self):
        command = nas.ListNAS(client=self.client)
        output = command.execute({})

        self.assertEqual([{'username': '******',
                           'datacenter': 'Dallas',
                           'server': '127.0.0.1',
                           'password': '******',
                           'id': 1,
                           'size': 10}],
                         formatting.format_output(output, 'python'))
예제 #31
0
    def test_detail_account(self):
        command = cdn.DetailAccount(client=self.client)

        output = command.execute({'<account>': '1234'})
        self.assertEqual({'notes': None,
                          'created': '2012-06-25T14:05:28-07:00',
                          'type': 'ORIGIN_PULL',
                          'status': 'ACTIVE',
                          'id': 1234,
                          'account_name': '1234a'},
                         formatting.format_output(output, 'python'))
예제 #32
0
    def test_format_output_json_keyvaluetable(self):
        t = formatting.KeyValueTable(["key", "value"])
        t.add_row(["nothing", formatting.blank()])
        t.sortby = "nothing"
        ret = formatting.format_output(t, "json")
        self.assertEqual(
            """{
    "nothing": null
}""",
            ret,
        )
예제 #33
0
    def test_list_firewalls(self):
        call = self.client['Account'].getNetworkVlans
        call.return_value = [{
            'id': 1,
            'dedicatedFirewallFlag': True,
            'highAvailabilityFirewallFlag': True,
            'networkVlanFirewall': {
                'id': 1234
            },
        }, {
            'id':
            2,
            'dedicatedFirewallFlag':
            False,
            'firewallGuestNetworkComponents': [{
                'id': 1234,
                'guestNetworkComponent': {
                    'guest': {
                        'id': 1
                    }
                },
                'status': 'ok'
            }],
            'firewallNetworkComponents': [{
                'id': 1234,
                'networkComponent': {
                    'downlinkComponent': {
                        'hardwareId': 1
                    }
                },
                'status': 'ok'
            }],
        }]
        command = firewall.FWList(client=self.client)

        output = command.execute({})

        self.assertEqual([{
            'type': 'VLAN - dedicated',
            'server/vlan id': 1,
            'features': ['HA'],
            'firewall id': 'vlan:1234'
        }, {
            'features': '-',
            'firewall id': 'cci:1234',
            'server/vlan id': 1,
            'type': 'CCI - standard'
        }, {
            'features': '-',
            'firewall id': 'server:1234',
            'server/vlan id': 1,
            'type': 'Server - standard'
        }], formatting.format_output(output, 'python'))
예제 #34
0
    def test_list_nas(self):
        command = nas.ListNAS(client=self.client)
        output = command.execute({})

        self.assertEqual([{
            'username': '******',
            'datacenter': 'Dallas',
            'server': '127.0.0.1',
            'password': '******',
            'id': 1,
            'size': 10
        }], formatting.format_output(output, 'python'))
예제 #35
0
    def test_show(self):
        command = config.Show(client=self.client)

        output = command.execute({})

        expected = {
            'Username': self.client.auth.username,
            'Endpoint URL': self.client.endpoint_url,
            'API Key': self.client.auth.api_key,
            'Timeout': self.client.timeout
        }
        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #36
0
    def test_list_origins(self):
        command = cdn.ListOrigins(client=self.client)

        output = command.execute({'<account>': '1234'})
        self.assertEqual([
            {'media_type': 'FLASH',
             'origin_url': 'http://ams01.objectstorage.softlayer.net:80',
             'cname': None,
             'id': '12345'},
            {'media_type': 'FLASH',
             'origin_url': 'http://sng01.objectstorage.softlayer.net:80',
             'cname': None,
             'id': '12345'}], formatting.format_output(output, 'python'))
예제 #37
0
    def test_list_keys(self):
        command = sshkey.ListSshKey(client=self.client)
        output = command.execute({})

        self.assertEqual(formatting.format_output(output, 'python'),
                         [{'notes': '-',
                           'fingerprint': None,
                           'id': '100',
                           'label': 'Test 1'},
                          {'notes': 'my key',
                           'fingerprint': None,
                           'id': '101',
                           'label': 'Test 2'}])
예제 #38
0
    def test_summary(self):
        command = summary.Summary(client=self.client,
                                  env=environment.Environment())

        output = command.execute({})
        expected = [{'datacenter': 'dal00',
                     'networking': 1,
                     'subnets': 0,
                     'hardware': 1,
                     'IPs': 3,
                     'vs': 1,
                     'vlans': 1}]
        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #39
0
    def test_volume_list_reduced_notes_format_output_table(self, list_mock):
        note_mock = 'test ' * 10
        expected_reduced_note = 'test ' * 4
        list_mock.return_value = [
            {'notes': note_mock}
        ]
        expected_table = formatting.Table(['notes'])
        expected_table.add_row([expected_reduced_note])
        expected_output = formatting.format_output(expected_table) + '\n'
        result = self.run_command(['--format', 'table', 'file', 'volume-list', '--columns', 'notes'])

        self.assert_no_fail(result)
        self.assertEqual(expected_output, result.output)
예제 #40
0
    def test_server_details(self):
        runnable = server.ServerDetails(client=self.client)

        args = {'<identifier>': 1234, '--passwords': True, '--price': True}
        output = runnable.execute(args)

        expected = {
            'status':
            'ACTIVE',
            'datacenter':
            'TEST00',
            'created':
            '2013-08-01 15:23:45',
            'notes':
            'These are test notes.',
            'hostname':
            'hardware-test1.test.sftlyr.ws',
            'public_ip':
            '172.16.1.100',
            'private_ip':
            '10.1.0.2',
            'ipmi_ip':
            '10.1.0.3',
            'price rate':
            1.54,
            'memory':
            2048,
            'cores':
            2,
            'ptr':
            '2.0.1.10.in-addr.arpa',
            'os':
            'Ubuntu',
            'id':
            1000,
            'tags': ['test_tag'],
            'users': ['root abc123'],
            'vlans': [{
                'id': 9653,
                'number': 1800,
                'type': 'PRIVATE'
            }, {
                'id': 19082,
                'number': 3672,
                'type': 'PUBLIC'
            }],
            'owner':
            'chechu'
        }

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #41
0
    def test_show(self):
        command = rwhois.RWhoisShow(client=self.client)

        output = command.execute({})
        expected = {'Abuse Email': 'abuseEmail',
                    'Address 1': 'address1',
                    'Address 2': 'address2',
                    'City': 'city',
                    'Company': 'companyName',
                    'Country': 'country',
                    'Name': 'firstName lastName',
                    'Postal Code': 'postalCode',
                    'State': '-'}
        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #42
0
    def test_server_create_options_for_bmc(self, bmpi, packages):
        args = {
            '<chassis_id>': '1099',
            '--all': True,
            '--datacenter': False,
            '--cpu': False,
            '--nic': False,
            '--disk': False,
            '--os': False,
            '--memory': False,
            '--controller': False,
        }

        test_data = [
            (1099, 'Bare Metal Instance'),
        ]
        packages.return_value = test_data

        bmpi.return_value = '1099'

        runnable = server.ServerCreateOptions(client=self.client)

        output = runnable.execute(args)

        expected = {
            'memory/cpu': [
                {
                    'cpu': ['2'],
                    'memory': '2'
                },
                {
                    'cpu': ['2', '4'],
                    'memory': '4'
                },
            ],
            'datacenter': ['RANDOM_LOCATION'],
            'disk': ['250_SATA_II', '500_SATA_II'],
            'dual nic': ['1000_DUAL', '100_DUAL', '10_DUAL'],
            'os (CENTOS)': ['CENTOS_6_64_LAMP', 'CENTOS_6_64_MINIMAL'],
            'os (REDHAT)': ['REDHAT_6_64_LAMP', 'REDHAT_6_64_MINIMAL'],
            'os (UBUNTU)': ['UBUNTU_12_64_LAMP', 'UBUNTU_12_64_MINIMAL'],
            'os (WIN)': [
                'WIN_2008-DC_64', 'WIN_2008-ENT_64', 'WIN_2008-STD-R2_64',
                'WIN_2008-STD_64', 'WIN_2012-DC-HYPERV_64'
            ],
            'single nic': ['100', '1000']
        }

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #43
0
    def test_list_accounts(self):
        command = cdn.ListAccounts(client=self.client)

        output = command.execute({'--sortby': None})
        self.assertEqual([{'notes': None,
                           'created': '2012-06-25T14:05:28-07:00',
                           'type': 'ORIGIN_PULL',
                           'id': 1234,
                           'account_name': '1234a'},
                          {'notes': None,
                           'created': '2012-07-24T13:34:25-07:00',
                           'type': 'POP_PULL',
                           'id': 1234,
                           'account_name': '1234a'}],
                         formatting.format_output(output, 'python'))
예제 #44
0
    def test_ip_list(self):
        command = globalip.GlobalIpList(client=self.client)

        output = command.execute({'--v4': True})
        self.assertEqual([{'assigned': 'Yes',
                           'id': '200',
                           'ip': '127.0.0.1',
                           'target': '127.0.0.1 (example.com)'},
                          {'assigned': 'Yes',
                           'id': '201',
                           'ip': '127.0.0.1',
                           'target': '127.0.0.1 (example.com)'}],
                         formatting.format_output(output, 'python'))

        output = command.execute({'--v6': True})
        self.assertEqual([{'assigned': 'Yes',
                           'id': '200',
                           'ip': '127.0.0.1',
                           'target': '127.0.0.1 (example.com)'},
                          {'assigned': 'Yes',
                           'id': '201',
                           'ip': '127.0.0.1',
                           'target': '127.0.0.1 (example.com)'}],
                         formatting.format_output(output, 'python'))
예제 #45
0
    def execute(self, args):
        username, secret, endpoint_url, timeout = self.get_user_input()

        api_key = get_api_key(self.client,
                              username,
                              secret,
                              endpoint_url=endpoint_url)

        path = '~/.softlayer'
        if args.get('--config'):
            path = args.get('--config')
        config_path = os.path.expanduser(path)

        self.env.out(
            formatting.format_output(
                config_table({
                    'username': username,
                    'api_key': api_key,
                    'endpoint_url': endpoint_url,
                    'timeout': timeout
                })))

        if not formatting.confirm('Are you sure you want to write settings '
                                  'to "%s"?' % config_path,
                                  default=True):
            raise exceptions.CLIAbort('Aborted.')

        # Persist the config file. Read the target config file in before
        # setting the values to avoid clobbering settings
        config = utils.configparser.RawConfigParser()
        config.read(config_path)
        try:
            config.add_section('softlayer')
        except utils.configparser.DuplicateSectionError:
            pass

        config.set('softlayer', 'username', username)
        config.set('softlayer', 'api_key', api_key)
        config.set('softlayer', 'endpoint_url', endpoint_url)

        config_file = os.fdopen(
            os.open(config_path, (os.O_WRONLY | os.O_CREAT), 0o600), 'w')
        try:
            config.write(config_file)
        finally:
            config_file.close()

        return "Configuration Updated Successfully"
예제 #46
0
    def test_list_keys(self):
        command = sshkey.ListSshKey(client=self.client)
        output = command.execute({})

        self.assertEqual(formatting.format_output(output, 'python'),
                         [{
                             'notes': '-',
                             'fingerprint': None,
                             'id': '100',
                             'label': 'Test 1'
                         }, {
                             'notes': 'my key',
                             'fingerprint': None,
                             'id': '101',
                             'label': 'Test 2'
                         }])
예제 #47
0
    def test_list_chassis_server(self, packages):
        test_data = [(1, 'Chassis 1'), (2, 'Chassis 2')]
        packages.return_value = test_data
        runnable = server.ListChassisServer(client=self.client)

        output = runnable.execute({})

        expected = [{
            'Chassis': 'Chassis 1',
            'Code': 1
        }, {
            'Chassis': 'Chassis 2',
            'Code': 2
        }]

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #48
0
    def test_list_chassis_server(self, packages):
        test_data = [
            (1, 'Chassis 1'),
            (2, 'Chassis 2')
        ]
        packages.return_value = test_data
        runnable = server.ListChassisServer(client=self.client)

        output = runnable.execute({})

        expected = [
            {'Chassis': 'Chassis 1', 'Code': 1},
            {'Chassis': 'Chassis 2', 'Code': 2}
        ]

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #49
0
    def test_show(self):
        command = rwhois.RWhoisShow(client=self.client)

        output = command.execute({})
        expected = {
            'Abuse Email': 'abuseEmail',
            'Address 1': 'address1',
            'Address 2': 'address2',
            'City': 'city',
            'Company': 'companyName',
            'Country': 'country',
            'Name': 'firstName lastName',
            'Postal Code': 'postalCode',
            'State': '-'
        }
        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #50
0
    def test_server_create_options(self, packages):
        args = {
            '<chassis_id>': '999',
            '--all': True,
            '--datacenter': False,
            '--cpu': False,
            '--nic': False,
            '--disk': False,
            '--os': False,
            '--memory': False,
            '--controller': False,
        }

        test_data = [
            (999, 'Chassis 999'),
        ]
        packages.return_value = test_data

        runnable = server.ServerCreateOptions(client=self.client)

        output = runnable.execute(args)

        expected = {
            'cpu': [{
                'Description': 'Dual Quad Core Pancake 200 - 1.60GHz',
                'ID': 723
            }, {
                'Description': 'Dual Quad Core Pancake 200 - 1.80GHz',
                'ID': 724
            }],
            'datacenter': ['RANDOM_LOCATION'],
            'disk': ['250_SATA_II', '500_SATA_II'],
            'disk_controllers': ['None', 'RAID0'],
            'dual nic': ['1000_DUAL', '100_DUAL', '10_DUAL'],
            'memory': [4, 6],
            'os (CENTOS)': ['CENTOS_6_64_LAMP', 'CENTOS_6_64_MINIMAL'],
            'os (REDHAT)': ['REDHAT_6_64_LAMP', 'REDHAT_6_64_MINIMAL'],
            'os (UBUNTU)': ['UBUNTU_12_64_LAMP', 'UBUNTU_12_64_MINIMAL'],
            'os (WIN)': [
                'WIN_2008-DC_64', 'WIN_2008-ENT_64', 'WIN_2008-STD-R2_64',
                'WIN_2008-STD_64', 'WIN_2012-DC-HYPERV_64'
            ],
            'single nic': ['100', '1000']
        }

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #51
0
    def test_server_create_options(self, packages):
        args = {
            '<chassis_id>': '999',
            '--all': True,
            '--datacenter': False,
            '--cpu': False,
            '--nic': False,
            '--disk': False,
            '--os': False,
            '--memory': False,
            '--controller': False,
        }

        test_data = [
            (999, 'Chassis 999'),
        ]
        packages.return_value = test_data

        runnable = server.ServerCreateOptions(client=self.client)

        output = runnable.execute(args)

        expected = {
            'cpu': [
                {'Description': 'Dual Quad Core Pancake 200 - 1.60GHz',
                 'ID': 723},
                {'Description': 'Dual Quad Core Pancake 200 - 1.80GHz',
                 'ID': 724}],
            'datacenter': ['RANDOM_LOCATION'],
            'disk': ['250_SATA_II', '500_SATA_II'],
            'disk_controllers': ['None', 'RAID0'],
            'dual nic': ['1000_DUAL', '100_DUAL', '10_DUAL'],
            'memory': [4, 6],
            'os (CENTOS)': ['CENTOS_6_64_LAMP', 'CENTOS_6_64_MINIMAL'],
            'os (REDHAT)': ['REDHAT_6_64_LAMP', 'REDHAT_6_64_MINIMAL'],
            'os (UBUNTU)': ['UBUNTU_12_64_LAMP', 'UBUNTU_12_64_MINIMAL'],
            'os (WIN)': [
                'WIN_2008-DC_64',
                'WIN_2008-ENT_64',
                'WIN_2008-STD-R2_64',
                'WIN_2008-STD_64',
                'WIN_2012-DC-HYPERV_64'],
            'single nic': ['100', '1000']}

        self.assertEqual(expected, formatting.format_output(output, 'python'))
예제 #52
0
    def test_check_create_args(self, confirm_mock):
        confirm_mock.return_value = True
        command = vs.CreateVS(client=self.client)
        output = command.execute({'--cpu': '2',
                                  '--domain': 'example.com',
                                  '--hostname': 'host',
                                  '--image': None,
                                  '--os': 'UBUNTU_LATEST',
                                  '--memory': '=1024',
                                  '--nic': '100',
                                  '--hourly': True,
                                  '--monthly': False,
                                  '--like': None,
                                  '--datacenter': None,
                                  '--dedicated': False,
                                  '--san': False,
                                  '--test': False,
                                  '--export': None,
                                  '--userfile': None,
                                  '--postinstall': None,
                                  '--key': [],
                                  '--network': [],
                                  '--disk': [],
                                  '--private': False,
                                  '--template': None,
                                  '--userdata': None,
                                  '--vlan_public': None,
                                  '--vlan_private': None,
                                  '--wait': None,
                                  '--really': False})

        self.assertEqual([{'guid': '1a2b3c-1701',
                           'id': 100,
                           'created': '2013-08-01 15:23:45'}],
                         formatting.format_output(output, 'python'))
        service = self.client['Virtual_Guest']
        service.createObject.assert_called_with({
            'domain': 'example.com',
            'localDiskFlag': True,
            'startCpus': 2,
            'operatingSystemReferenceCode': 'UBUNTU_LATEST',
            'maxMemory': 1024,
            'hourlyBillingFlag': True,
            'hostname': 'host'})
예제 #53
0
    def test_server_cancel_reasons(self):
        runnable = server.ServerCancelReasons(client=self.client)
        output = runnable.execute({})

        expected = [{
            'Code': 'datacenter',
            'Reason': 'Migrating to a different SoftLayer datacenter'
        }, {
            'Code': 'cost',
            'Reason': 'Server / Upgrade Costs'
        }, {
            'Code': 'moving',
            'Reason': 'Moving to competitor'
        }, {
            'Code': 'migrate_smaller',
            'Reason': 'Migrating to smaller server'
        }, {
            'Code': 'sales',
            'Reason': 'Sales process / upgrades'
        }, {
            'Code': 'performance',
            'Reason': 'Network performance / latency'
        }, {
            'Code': 'unneeded',
            'Reason': 'No longer needed'
        }, {
            'Code': 'support',
            'Reason': 'Support response / timing'
        }, {
            'Code': 'closing',
            'Reason': 'Business closing down'
        }, {
            'Code': 'migrate_larger',
            'Reason': 'Migrating to larger server'
        }]

        method = 'assertItemsEqual'
        if not hasattr(self, method):
            # For Python 3.3 compatibility
            method = 'assertCountEqual'

        f = getattr(self, method)
        f(expected, formatting.format_output(output, 'python'))
예제 #54
0
    def test_create_options(self):
        command = vs.CreateOptionsVS(client=self.client)

        output = command.execute({'--all': True,
                                  '--cpu': True,
                                  '--datacenter': True,
                                  '--disk': True,
                                  '--memory': True,
                                  '--nic': True,
                                  '--os': True})

        self.assertEqual({'cpus (private)': [],
                          'cpus (standard)': ['1', '2', '3', '4'],
                          'datacenter': ['ams01', 'dal05'],
                          'local disk(0)': ['25', '100'],
                          'memory': ['1024', '2048', '3072', '4096'],
                          'nic': ['10', '100', '1000'],
                          'os (CENTOS)': 'CENTOS_6_64',
                          'os (DEBIAN)': 'DEBIAN_7_64',
                          'os (UBUNTU)': 'UBUNTU_12_64'},
                         formatting.format_output(output, 'python'))