def get_conn(): """ Return a conn object for the passed VM data """ return OneAndOneService( api_token=config.get_cloud_config_value( "api_token", get_configured_provider(), __opts__, search_global=False ) )
def getOneAndOneClient(self): """ initialize 1and1 client :return: OneAndOneService() """ # Try initializing the 1and1 client ant return it try: client = OneAndOneService(self.getConfig(self.configApiToken)) # If initializing failed return nothing except Exception as e: self.logger.warning("Could not establish connection to 1&1 Cloud Site. ERROR: %s" % e) return return client
# List all the of appliances that you can use for creating a server from oneandone.client import OneAndOneService client = OneAndOneService('675fbe491b27896b57e76867604f8255') server_appliances = client.list_appliances() # Retrieve a specific appliance from oneandone.client import OneAndOneService client = OneAndOneService('675fbe491b27896b57e76867604f8255') server_appliance = client.get_appliance(appliance_id='')
# List all servers from oneandone.client import OneAndOneService client = OneAndOneService('API-TOKEN') servers = client.list_servers() # Retrieve a single server from oneandone.client import OneAndOneService client = OneAndOneService('API-TOKEN') server = client.get_server(server_id='') # List fixed server flavors from oneandone.client import OneAndOneService client = OneAndOneService('API-TOKEN') fixed_servers = client.fixed_server_flavors() # Retrieve information about a fixed server flavor from oneandone.client import OneAndOneService client = OneAndOneService('API-TOKEN') fixed_server = client.get_fixed_server(fixed_server_id='') # List baremetal models from oneandone.client import OneAndOneService
# Create a block storage from oneandone.client import OneAndOneService, BlockStorage client = OneAndOneService('<API-TOKEN>') block_storage = BlockStorage(name='My new block storage', description='My block storage description', size=20, datacenter_id='908DC2072407C94C8054610AD5A53B8C') response = client.create_block_storage(block_storage) # List all block storages from oneandone.client import OneAndOneService, BlockStorage client = OneAndOneService('<API-TOKEN>') response = client.list_block_storages() # Retrieve a single block storage from oneandone.client import OneAndOneService client = OneAndOneService('<API-TOKEN>') response = client.get_block_storage(block_storage_id='') # Modify a block storage from oneandone.client import OneAndOneService client = OneAndOneService('<API-TOKEN>')
def setUp(self): self.client = OneAndOneService('USER-API-KEY')
import os from oneandone.client import OneAndOneService from oneandone.client import Server, Hdd token = os.getenv('ONEANDONE_TOKEN') client = OneAndOneService(token) print "creating bare metal server" server_appliances = client.list_appliances(q='baremetal') baremetal_model = client.list_baremetal_models(q='BMC_L') # Create a server server1 = Server(name='Python baremetal Server', description='Server Description', server_type='baremetal', baremetal_model_id=baremetal_model[0]['id'], appliance_id=server_appliances[0]['id'] ) hdd1 = Hdd(size=120, is_main=True) hdds = [hdd1] new_server = client.create_server(server=server1) print server1.wait_for() # Add a new IP to a server. print "add a new IP to the server" response = client.add_new_ip(server_id=new_server['id'], ip_type='IPV4') print server1.wait_for()
from oneandone.client import OneAndOneService from oneandone.client import Server, Hdd, LoadBalancer, LoadBalancerRule from oneandone.client import FirewallPolicy, FirewallPolicyRule client = OneAndOneService('<API-Token>') # Create Load Balancer lb1 = LoadBalancer(name='Example App LB', description='Example Description', health_check_test='TCP', health_check_interval=40, persistence=True, persistence_time=1200, method='ROUND_ROBIN') rule1 = LoadBalancerRule(protocol='TCP', port_balancer=80, port_server=80, source='0.0.0.0') rules = [rule1] new_load_balancer = client.create_load_balancer(load_balancer=lb1, load_balancer_rules=rules) ## Wait for Load Balancer to go live print 'Creating load balancer...' print lb1.wait_for() # Create Firewall Policy fp1 = FirewallPolicy(name='Example App FP', description='Test Description')