Example #1
0
def create_port(network_id, ip_address, subnet_id, security_group_ids=None):
    '''
    https://www.conoha.jp/docs/neutron-add_port.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }

    # 必須項目
    data = {
        'port': {
            'network_id': network_id,
            'fixed_ips': [{
                'ip_address': ip_address,
                'subnet_id': subnet_id
            }]
        }
    }

    # Optional 項目
    if security_group_ids is not None:
        data['port']['security_groups'] = security_group_ids

    return http.post(f'{endpoint}/ports', data, headers)
Example #2
0
def delete_server(server_id):
    '''
    https://www.conoha.jp/docs/compute-delete_vm.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.delete(f'{endpoint}/servers/{server_id}', headers)
Example #3
0
def list_subnets():
    '''
    https://www.conoha.jp/docs/neutron-get_subnets_list.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/subnets', headers)
Example #4
0
def delete_port(port_id):
    '''
    https://www.conoha.jp/docs/neutron-remove_port.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.delete(f'{endpoint}/ports/{port_id}', headers)
Example #5
0
def list_ports(server_id):
    '''
    https://www.conoha.jp/docs/compute-get_attached_ports_list.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/servers/{server_id}/os-interface', headers)
Example #6
0
def describe_security_group_rule(rule_id):
    '''
    https://www.conoha.jp/docs/neutron-get_rules_detail_specified.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/security-group-rules/{rule_id}', headers)
Example #7
0
def list_security_group_rules():
    '''
    https://www.conoha.jp/docs/neutron-get_rules_on_secgroup.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/security-group-rules', headers)
Example #8
0
def describe_network(network_id):
    '''
    https://www.conoha.jp/docs/neutron-get_networks_detail_specified.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/networks/{network_id}', headers)
Example #9
0
def describe_server(server_id):
    '''
    https://www.conoha.jp/docs/compute-get_vms_detail_specified.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/servers/{server_id}', headers)
Example #10
0
def list_servers_detail():
    '''
    詳細表示: https://www.conoha.jp/docs/compute-get_vms_detail.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/servers/detail', headers)
Example #11
0
def list_images():
    '''
    https://www.conoha.jp/docs/compute-get_images_list.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.get(f'{endpoint}/images', headers)
Example #12
0
def delete_security_group_rule(rule_id):
    '''
    https://www.conoha.jp/docs/neutron-delete_rule_on_secgroup.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.delete(f'{endpoint}/security-group-rules/{rule_id}', headers)
Example #13
0
def create_network():
    '''
    https://www.conoha.jp/docs/neutron-add_network.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.post(f'{endpoint}/networks', None, headers)
Example #14
0
def create_subnet(network_id, cidr):
    '''
    https://www.conoha.jp/docs/neutron-add_subnet.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    data = {'subnet': {'network_id': network_id, 'cidr': cidr}}
    return http.post(f'{endpoint}/subnets', data, headers)
Example #15
0
def start_server(server_id):
    '''
    https://www.conoha.jp/docs/compute-power_on_vm.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    data = {'os-start': None}
    return http.post(f'{endpoint}/servers/{server_id}/action', data, headers)
Example #16
0
def update_port(port_id, security_group_ids):
    '''
    https://www.conoha.jp/docs/neutron-update_port.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    data = {'port': {'security_groups': security_group_ids}}
    return http.put(f'{endpoint}/ports/{port_id}', data, headers)
Example #17
0
def detach_port(server_id, port_id):
    '''
    https://www.conoha.jp/docs/compute-dettach_port.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    return http.delete(
        f'{endpoint}/servers/{server_id}/os-interface/{port_id}', headers)
Example #18
0
def attach_port(server_id, port_id):
    '''
    https://www.conoha.jp/docs/compute-attach_port.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    data = {'interfaceAttachment': {'port_id': port_id}}
    return http.post(f'{endpoint}/servers/{server_id}/os-interface', data,
                     headers)
Example #19
0
def stop_server(server_id, force):
    '''
    通常停止: https://www.conoha.jp/docs/compute-stop_cleanly_vm.php
    強制停止: https://www.conoha.jp/docs/compute-stop_forcibly_vm.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }
    data = {'os-stop': None}
    if force:
        data['os-stop'] = {'force_shutdown': True}
    return http.post(f'{endpoint}/servers/{server_id}/action', data, headers)
Example #20
0
def create_security_group(name, description=None):
    '''
    https://www.conoha.jp/docs/neutron-create_secgroup.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }

    # 必須項目
    data = {'security_group': {'name': name}}

    # Optional 項目
    if description is not None:
        data['security_group']['description'] = description

    return http.post(f'{endpoint}/security-groups', data, headers)
Example #21
0
def create_server(image_ref,
                  flavor_ref,
                  admin_pass=None,
                  key_name=None,
                  security_groups=None,
                  instance_name_tag=None,
                  volume_id=None,
                  vnc_keymap=None,
                  user_data=None):
    '''
    https://www.conoha.jp/docs/compute-create_vm.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }

    # 必須項目
    data = {'server': {'imageRef': image_ref, 'flavorRef': flavor_ref}}

    # Optional 項目
    if admin_pass is not None:
        data['server']['adminPass'] = admin_pass
    if key_name is not None:
        data['server']['key_name'] = key_name
    if security_groups is not None:
        data['server']['security_groups'] = []
        for security_group in security_groups:
            data['server']['security_groups'].append({'name': security_group})
    if instance_name_tag is not None:
        data['server']['metadata'] = {'instance_name_tag': instance_name_tag}
    if volume_id is not None:
        data['server']['block_device_mapping'] = {'volume_id': volume_id}
    if vnc_keymap is not None:
        data['server']['vncKeymap'] = vnc_keymap
    if user_data is not None:
        # 生の文字列を BASE64 エンコードに変換する
        data['server']['user_data'] = base64.b64encode(
            user_data.encode(encoding='utf-8')).decode(encoding='utf-8')
    return http.post(f'{endpoint}/servers', data, headers)
Example #22
0
def create_security_group_rule(direction,
                               ether_type,
                               security_group_id,
                               port_range_min=None,
                               port_range_max=None,
                               protocol=None,
                               remote_group_id=None,
                               remote_ip_prefix=None):
    '''
    https://www.conoha.jp/docs/neutron-create_rule_on_secgroup.php
    '''
    headers = {
        'Accept': 'application/json',
        'X-Auth-Token': config.get_token()['id']
    }

    # 必須項目
    data = {
        'security_group_rule': {
            'direction': direction,
            'ethertype': ether_type,
            'security_group_id': security_group_id
        }
    }

    # Optional 項目
    if port_range_min is not None:
        data['security_group_rule']['port_range_min'] = port_range_min
    if port_range_max is not None:
        data['security_group_rule']['port_range_max'] = port_range_max
    if protocol is not None and protocol != 'null':
        data['security_group_rule']['protocol'] = protocol
    if remote_group_id is not None:
        data['security_group_rule']['remote_group_id'] = remote_group_id
    if remote_ip_prefix is not None:
        data['security_group_rule']['remote_ip_prefix'] = remote_ip_prefix

    return http.post(f'{endpoint}/security-group-rules', data, headers)